blob: 9b0c18b75f65e0af66884b35a18c4a9d6628a5cd [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001From 9cb63711e63042f22da914ba039c4537b22e8fb0 Mon Sep 17 00:00:00 2001
2From: Greg Hudson <ghudson@mit.edu>
3Date: Fri, 25 Sep 2015 12:51:47 -0400
4Subject: [PATCH 3/4] Fix build_principal memory bug [CVE-2015-2697]
5
6In build_principal_va(), use k5memdup0() instead of strdup() to make a
7copy of the realm, to ensure that we allocate the correct number of
8bytes and do not read past the end of the input string. This bug
9affects krb5_build_principal(), krb5_build_principal_va(), and
10krb5_build_principal_alloc_va(). krb5_build_principal_ext() is not
11affected.
12
13CVE-2015-2697:
14
15In MIT krb5 1.7 and later, an authenticated attacker may be able to
16cause a KDC to crash using a TGS request with a large realm field
17beginning with a null byte. If the KDC attempts to find a referral to
18answer the request, it constructs a principal name for lookup using
19krb5_build_principal() with the requested realm. Due to a bug in this
20function, the null byte causes only one byte be allocated for the
21realm field of the constructed principal, far less than its length.
22Subsequent operations on the lookup principal may cause a read beyond
23the end of the mapped memory region, causing the KDC process to crash.
24
25CVSSv2: AV:N/AC:L/Au:S/C:N/I:N/A:C/E:POC/RL:OF/RC:C
26
27ticket: 8252 (new)
28target_version: 1.14
29tags: pullup
30
31Backport upstream commit:
32https://github.com/krb5/krb5/commit/f0c094a1b745d91ef2f9a4eae2149aac026a5789
33
34Upstream-Status: Backport
35---
36 src/lib/krb5/krb/bld_princ.c | 6 ++----
37 1 file changed, 2 insertions(+), 4 deletions(-)
38
39diff --git a/src/lib/krb5/krb/bld_princ.c b/src/lib/krb5/krb/bld_princ.c
40index ab6fed8..8604268 100644
41--- a/src/lib/krb5/krb/bld_princ.c
42+++ b/src/lib/krb5/krb/bld_princ.c
43@@ -40,10 +40,8 @@ build_principal_va(krb5_context context, krb5_principal princ,
44 data = malloc(size * sizeof(krb5_data));
45 if (!data) { retval = ENOMEM; }
46
47- if (!retval) {
48- r = strdup(realm);
49- if (!r) { retval = ENOMEM; }
50- }
51+ if (!retval)
52+ r = k5memdup0(realm, rlen, &retval);
53
54 while (!retval && (component = va_arg(ap, char *))) {
55 if (count == size) {
56--
571.9.1
58