Fix bug #7669.
authorJeremy Allison <jra@samba.org>
Thu, 9 Sep 2010 13:48:23 +0000 (15:48 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 15 Sep 2010 20:47:24 +0000 (22:47 +0200)
Fix bug #7669 (buffer overflow in sid_parse() in Samba3 and dom_sid_parse in
Samba4).

CVE-2010-3069:

===========
Description
===========

All current released versions of Samba are vulnerable to
a buffer overrun vulnerability. The sid_parse() function
(and related dom_sid_parse() function in the source4 code)
do not correctly check their input lengths when reading a
binary representation of a Windows SID (Security ID). This
allows a malicious client to send a sid that can overflow
the stack variable that is being used to store the SID in the
Samba smbd server.

A connection to a file share is needed to exploit this
vulnerability, either authenticated or unauthenticated
(guest connection).
(cherry picked from commit df20a300758bc12286820e31fcf573bdfc2147bc)

libcli/security/dom_sid.c
libcli/security/dom_sid.h
source3/lib/util_sid.c
source3/libads/ldap.c
source3/libsmb/cliquota.c
source3/smbd/nttrans.c

index 0c8890079af7e8d99305fe4e83391e20f8a6af1b..350a14f311b063c5e1cc057a5159eae5e6a8b2a1 100644 (file)
@@ -117,6 +117,10 @@ bool dom_sid_parse(const char *sidstr, struct dom_sid *ret)
                if (sidstr[i] == '-') num_sub_auths++;
        }
 
+       if (num_sub_auths > MAXSUBAUTHS) {
+               return false;
+       }
+
        ret->sid_rev_num = rev;
        ret->id_auth[0] = 0;
        ret->id_auth[1] = 0;
index e89253554e81251faf60616cd56dea2427f3b9fd..748e009117d11a99911c55bb0096673b96978f45 100644 (file)
@@ -40,5 +40,9 @@ bool dom_sid_in_domain(const struct dom_sid *domain_sid,
                       const struct dom_sid *sid);
 char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
 
+#ifndef MAXSUBAUTHS
+#define MAXSUBAUTHS 15 /* max sub authorities in a SID */
+#endif
+
 #endif /*_DOM_SID_H_*/
 
index 163c6c210a5d47d9da8802d6a2db4fc130fa118e..130e257bdd3858d45021023bf1df1c186274c7cb 100644 (file)
@@ -408,6 +408,9 @@ bool sid_parse(const char *inbuf, size_t len, DOM_SID *sid)
 
        sid->sid_rev_num = CVAL(inbuf, 0);
        sid->num_auths = CVAL(inbuf, 1);
+       if (sid->num_auths > MAXSUBAUTHS) {
+               return false;
+       }
        memcpy(sid->id_auth, inbuf+2, 6);
        if (len < 8 + sid->num_auths*4)
                return False;
index 1fb541d4e6721314162bdbbce65e49ba0bb8496a..08b831195c442ac918c87edea14f58ad91ddee11 100644 (file)
@@ -2128,7 +2128,9 @@ static void dump_sid(ADS_STRUCT *ads, const char *field, struct berval **values)
        for (i=0; values[i]; i++) {
                DOM_SID sid;
                fstring tmp;
-               sid_parse(values[i]->bv_val, values[i]->bv_len, &sid);
+               if (!sid_parse(values[i]->bv_val, values[i]->bv_len, &sid)) {
+                       continue;
+               }
                printf("%s: %s\n", field, sid_to_fstring(tmp, &sid));
        }
 }
index e40dac368d9ae6b5e686dcecdf202b4970ede921..2af5b22da5695c1e46f6bacba3aa5c473cce9256 100644 (file)
@@ -117,7 +117,9 @@ static bool parse_user_quota_record(const char *rdata, unsigned int rdata_count,
        }
 #endif /* LARGE_SMB_OFF_T */
 
-       sid_parse(rdata+40,sid_len,&qt.sid);
+       if (!sid_parse(rdata+40,sid_len,&qt.sid)) {
+               return false;
+       }
 
        qt.qtype = SMB_USER_QUOTA_TYPE;
 
index 2af9a79a50d3a3b9d44968fb5b628b763978426d..fcb2f8d2bd57ce8e587b415803967ad15896cbad 100644 (file)
@@ -2079,7 +2079,11 @@ static void call_nt_transact_ioctl(connection_struct *conn,
                /* unknown 4 bytes: this is not the length of the sid :-(  */
                /*unknown = IVAL(pdata,0);*/
 
-               sid_parse(pdata+4,sid_len,&sid);
+               if (!sid_parse(pdata+4,sid_len,&sid)) {
+                       reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+                       return;
+               }
+
                DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
 
                if (!sid_to_uid(&sid, &uid)) {
@@ -2335,7 +2339,10 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
                                break;
                        }
 
-                       sid_parse(pdata+8,sid_len,&sid);
+                       if (!sid_parse(pdata+8,sid_len,&sid)) {
+                               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+                               return;
+                       }
 
                        if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
                                ZERO_STRUCT(qt);
@@ -2516,7 +2523,11 @@ static void call_nt_transact_set_user_quota(connection_struct *conn,
        }
 #endif /* LARGE_SMB_OFF_T */
 
-       sid_parse(pdata+40,sid_len,&sid);
+       if (!sid_parse(pdata+40,sid_len,&sid)) {
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return;
+       }
+
        DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
 
        /* 44 unknown bytes left... */