[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6c078835254b43ec82bf45db3b241510@AcuMS.aculab.com>
Date: Thu, 2 Sep 2021 14:03:17 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Joe Perches' <joe@...ches.com>,
Kari Argillander <kari.argillander@...il.com>,
Konstantin Komarov <almaz.alexandrovich@...agon-software.com>,
"ntfs3@...ts.linux.dev" <ntfs3@...ts.linux.dev>
CC: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH 1/5] fs/ntfs3: Use kmalloc_array over kmalloc with
multiply
From: Joe Perches
> Sent: 01 September 2021 03:41
>
> On Tue, 2021-08-31 at 21:15 +0300, Kari Argillander wrote:
> > If we do not use kmalloc_array we get checkpatch warning. It is also
> > little safer if something goes wrong with coding.
> []
> > diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c
> []
> > @@ -707,7 +707,7 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx,
> > u16 *ptr;
> > int new_slots = ALIGN(2 * nslots, 8);
> >
> >
> > - ptr = kmalloc(sizeof(u16) * new_slots, GFP_NOFS);
> > + ptr = kmalloc_array(new_slots, sizeof(u16), GFP_NOFS);
> > if (ptr)
> > memcpy(ptr, offs, sizeof(u16) * max_idx);
>
> This multiplication could also overflow.
Not if kmalloc_array() has suceeded.
OTOH the ALIGN(2 * nslots, 8) can also go wrong.
(But probably not if the previous kmalloc() for 1/2 the size worked.)
But there really ought to be some kind of bound check earlier.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists