cifs: integer overflow in parse_dacl()
Subsystems (3)
PATCH 1/1 cifs: integer overflow in parse_dacl()
On 32 bit systems num_aces * sizeof(struct cifs_ace *) could overflow leading to a smaller ppace buffer than we expected.
fs/cifs/cifsacl.c +2 -0
@@ -909,6 +909,8 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,umode_t group_mask =S_IRWXG ;umode_t other_mask =S_IRWXU |S_IRWXG |S_IRWXO ; +if (num_aces >ULONG_MAX /sizeof (struct cifs_ace *)) +return ; ppace =kmalloc (num_aces *sizeof (struct cifs_ace *),GFP_KERNEL );if (!ppace) {
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 10 lines · On Wed, 11 Jan 2012 10:46:27 +0300 Dan Carpenter <[email protected]>…
On 32 bit systems
num_aces*sizeof(struct cifs_ace *)could overflow leading to a smaller ppace buffer than we expected.Signed-off-by Dan Carpenter <[email protected]>fs/cifs/cifsacl.c +0
-0
fs/cifs/cifsacl.c static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, · line 916
Quoted 8 lines
fs/cifs/cifsacl.c +2
-0@@ -909,6 +909,8 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,umode_t group_mask =S_IRWXG ;umode_t other_mask =S_IRWXU |S_IRWXG |S_IRWXO ; +if (num_aces >ULONG_MAX /sizeof (struct cifs_ace *)) +return ; ppace =kmalloc (num_aces *sizeof (struct cifs_ace *),GFP_KERNEL );if (!ppace) {
Looks plausible. This function could use some work. I'm not sure why num_aces is signed here too...
The first arg to kmalloc is a size_t. Does that boil down to an unsigned long on all arches?
Signature · 1 line
Jeff Layton <[email protected]>
A message that is not in the archive (sent off-list or not yet received): 20120111072029.672dfdca-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org
Quoted 26 lines · Jeff Layton
Quoted 10 lines · On Wed, 11 Jan 2012 10:46:27 +0300 Dan Carpenter <[email protected]>…
On 32 bit systems
num_aces*sizeof(struct cifs_ace *)could overflow leading to a smaller ppace buffer than we expected.Signed-off-by Dan Carpenter <[email protected]>fs/cifs/cifsacl.c +0
-0fs/cifs/cifsacl.c static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, · line 916
Quoted 8 lines
fs/cifs/cifsacl.c +2
-0@@ -909,6 +909,8 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,umode_t group_mask =S_IRWXG ;umode_t other_mask =S_IRWXU |S_IRWXG |S_IRWXO ; +if (num_aces >ULONG_MAX /sizeof (struct cifs_ace *)) +return ; ppace =kmalloc (num_aces *sizeof (struct cifs_ace *),GFP_KERNEL );if (!ppace) {Looks plausible. This function could use some work. I'm not sure why
num_acesis signed here too...
Quoted 2 lines
The first arg to kmalloc is a
size_t. Does that boil down to an unsigned long on all arches?
People have been submitting a lot of patches recently based on that assumption. It matches the check in kcalloc() as well. According to include/asm-generic/posix_types.h:
/*
* Most 32 bit architectures use "unsigned int" size_t,
* and all 64 bit architectures use "unsigned long" size_t. */
It would be better to user a lower limit, but I don't know the code well enough to say if which one is good that won't break things... A high number can trigger a kmalloc() failure and that puts annoying spam in the dmesg.
regards,
dan carpenter
Jeff Layton
Acked-byQuoted 39 lines · On Wed, 11 Jan 2012 15:41:32 +0300 Dan Carpenter <[email protected]>…
Quoted 26 lines · Jeff Layton
Quoted 10 lines · On Wed, 11 Jan 2012 10:46:27 +0300 Dan Carpenter <[email protected]>…
On 32 bit systems
num_aces*sizeof(struct cifs_ace *)could overflow leading to a smaller ppace buffer than we expected.Signed-off-by Dan Carpenter <[email protected]>fs/cifs/cifsacl.c +0
-0fs/cifs/cifsacl.c static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, · line 916
Quoted 8 lines
fs/cifs/cifsacl.c +2
-0@@ -909,6 +909,8 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,umode_t group_mask =S_IRWXG ;umode_t other_mask =S_IRWXU |S_IRWXG |S_IRWXO ; +if (num_aces >ULONG_MAX /sizeof (struct cifs_ace *)) +return ; ppace =kmalloc (num_aces *sizeof (struct cifs_ace *),GFP_KERNEL );if (!ppace) {Looks plausible. This function could use some work. I'm not sure why
num_acesis signed here too...Quoted 2 lines
The first arg to kmalloc is a
size_t. Does that boil down to an unsigned long on all arches?People have been submitting a lot of patches recently based on that assumption. It matches the check in
kcalloc()as well. According toinclude/asm-generic/posix_types.h:/*
* Most 32 bit architectures use "unsigned int"size_t,
* and all 64 bit architectures use "unsigned long"size_t. */
Quoted 7 lines
It would be better to user a lower limit, but I don't know the code well enough to say if which one is good that won't break things... A high number can trigger a
kmalloc()failure and that puts annoying spam in the dmesg.regards,
dan carpenter
Ok, thanks. In that case...
Quoted 10 lines · Dan Carpenter
On 32 bit systems
num_aces*sizeof(struct cifs_ace *)could overflow leading to a smaller ppace buffer than we expected.Signed-off-by Dan Carpenter <[email protected]>fs/cifs/cifsacl.c +0
-0
fs/cifs/cifsacl.c static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, · line 912
Quoted 4 lines
fs/cifs/cifsacl.c +1
-0@@ -909,6 +909,8 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, umode_t group_mask = S_IRWXG; umode_t other_mask = S_IRWXU | S_IRWXG | S_IRWXO; + if (num_aces > ULONG_MAX / sizeof(struct cifs_ace *))
Should an error/warning (like cifs client can't handle these many aces or possible erroneous number of aces sent by server etc.) be logged before returning?
Quoted 8 lines
fs/cifs/cifsacl.c +1
-1+ return; ppace = kmalloc(num_aces * sizeof(struct cifs_ace *), GFP_KERNEL); if (!ppace) { --To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CADT32eLVwQT9V67BX8TkjVHDnQoYS7OqA_-xbnjY57ZXO3EfsA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 14 lines · Shirish Pargaonkar
Quoted 13 lines · Dan Carpenter
On 32 bit systems
num_aces*sizeof(struct cifs_ace *)could overflow leading to a smaller ppace buffer than we expected.Signed-off-by Dan Carpenter <[email protected]>fs/cifs/cifsacl.c +0
-0@@ -909,6 +909,8 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, umode_t group_mask = S_IRWXG; umode_t other_mask = S_IRWXU | S_IRWXG | S_IRWXO;
Quoted 10 lines
fs/cifs/cifsacl.c static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, · line 912
Quoted 1 line
fs/cifs/cifsacl.c +1
-0+ if (num_aces > ULONG_MAX / sizeof(struct cifs_ace *))Should an error/warning (like cifs client can't handle these many aces or possible erroneous number of aces sent by server etc.) be logged before returning?
Quoted 4 lines
fs/cifs/cifsacl.c +1
-0+ return; ppace = kmalloc(num_aces * sizeof(struct cifs_ace *), GFP_KERNEL); if (!ppace) {
Perhaps. Also note that you would overflow maximum smb size if num
aces is huge
so would you have even gotten this far?
Signature · 7 lines
Thanks, Steve -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CAH2r5muDQUL=0HcoFHH3QvP7C2pyy0=S9ESFBcm=qOYg3ESdxQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 22 lines · On Wed, 11 Jan 2012 11:24:03 -0600 Steve French <[email protected]> wrote:
Quoted 20 lines · Shirish Pargaonkar
Quoted 10 lines · Dan Carpenter
On 32 bit systems
num_aces*sizeof(struct cifs_ace *)could overflow leading to a smaller ppace buffer than we expected.Signed-off-by Dan Carpenter <[email protected]>fs/cifs/cifsacl.c +0
-0fs/cifs/cifsacl.c static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, · line 912
Quoted 4 lines
fs/cifs/cifsacl.c +1
-0@@ -909,6 +909,8 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, umode_t group_mask = S_IRWXG; umode_t other_mask = S_IRWXU | S_IRWXG | S_IRWXO; + if (num_aces > ULONG_MAX / sizeof(struct cifs_ace *))Should an error/warning (like cifs client can't handle these many aces or possible erroneous number of aces sent by server etc.) be logged before returning?
Quoted 9 lines
Quoted 4 lines
fs/cifs/cifsacl.c static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, · line 916
Quoted 4 lines
fs/cifs/cifsacl.c +1
-0+ return; ppace = kmalloc(num_aces * sizeof(struct cifs_ace *), GFP_KERNEL); if (!ppace) {Perhaps. Also note that you would overflow maximum smb size if num
aces is huge
so would you have even gotten this far?
Only if the smb frame is properly formed. It's possible that it's corrupt in such a way that the num_aces field is much larger than it should be, but the rest of the frame looks OK.
Signature · 1 line
Jeff Layton <[email protected]>
A message that is not in the archive (sent off-list or not yet received): 20120111132053.467e8cae-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org
We could calculate max_aces based on a minimum sized ace and maximum smb frame size (which would be 64K presumably for Windows for non-Writes, but larger for Samba), but not sure if it is worth the trouble unless you find a path where we would parse beyond end of frame,
Quoted 41 lines · Jeff Layton
Quoted 22 lines · On Wed, 11 Jan 2012 11:24:03 -0600 Steve French <[email protected]> wrote:
Quoted 20 lines · Shirish Pargaonkar
Quoted 10 lines · Dan Carpenter
On 32 bit systems
num_aces*sizeof(struct cifs_ace *)could overflow leading to a smaller ppace buffer than we expected.Signed-off-by Dan Carpenter <[email protected]>fs/cifs/cifsacl.c +0
-0fs/cifs/cifsacl.c static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, · line 912
Quoted 4 lines
fs/cifs/cifsacl.c +1
-0@@ -909,6 +909,8 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, umode_t group_mask = S_IRWXG; umode_t other_mask = S_IRWXU | S_IRWXG | S_IRWXO; + if (num_aces > ULONG_MAX / sizeof(struct cifs_ace *))Should an error/warning (like cifs client can't handle these many aces or possible erroneous number of aces sent by server etc.) be logged before returning?
Quoted 9 lines
Quoted 4 lines
fs/cifs/cifsacl.c static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, · line 916
Quoted 4 lines
fs/cifs/cifsacl.c +1
-0+ return; ppace = kmalloc(num_aces * sizeof(struct cifs_ace *), GFP_KERNEL); if (!ppace) {Perhaps. Also note that you would overflow maximum smb size if num aces is huge
so would you have even gotten this far?Only if the smb frame is properly formed. It's possible that it's corrupt in such a way that the
num_acesfield is much larger than it should be, but the rest of the frame looks OK.--
Jeff Layton <[email protected]>
Signature · 7 lines
Thanks, Steve -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CAH2r5msciOkxvxTrQrN9mKKCiJvM_anmxU7sag_TGk92LoKEwQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 5 lines · Steve French
We could calculate
max_acesbased on a minimum sized ace and maximum smb frame size (which would be 64K presumably for Windows for non-Writes, but larger for Samba), but not sure if it is worth the trouble unless you find a path where we would parse beyond end of frame,
This was a static checker test and I haven't tried to exploit it. You guys are more familiar with the code obviously and you've lost me with the talk about max_aces. I don't see that anywhere in the code...
$ grep max_aces fs/cifs/ -iR | wc -l 0
regards,
dan carpenter
Steve French
AppliedMerged into cifs-2.6.git
Quoted 22 lines · Dan Carpenter
On 32 bit systems
num_aces*sizeof(struct cifs_ace *)could overflow leading to a smaller ppace buffer than we expected.Signed-off-by Dan Carpenter <[email protected]>fs/cifs/cifsacl.c +2
-1@@ -909,6 +909,8 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, umode_t group_mask = S_IRWXG; umode_t other_mask = S_IRWXU | S_IRWXG | S_IRWXO; + if (num_aces > ULONG_MAX / sizeof(struct cifs_ace *)) + return; ppace = kmalloc(num_aces * sizeof(struct cifs_ace *), GFP_KERNEL); if (!ppace) { --To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 7 lines
Thanks, Steve -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html