On Wed, Jan 11, 2012 at 07:20:29AM -0500, Jeff Layton wrote: > On Wed, 11 Jan 2012 10:46:27 +0300 > Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote: > > > 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 <dan.carpenter@xxxxxxxxxx> > > > > diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c > > index 72ddf23..c1b2544 100644 > > --- a/fs/cifs/cifsacl.c > > +++ b/fs/cifs/cifsacl.c > > @@ -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? 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
Attachment:
signature.asc
Description: Digital signature