LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Joe Perches' <joe@perches.com>,
	Kari Argillander <kari.argillander@gmail.com>,
	Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	"ntfs3@lists.linux.dev" <ntfs3@lists.linux.dev>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 1/5] fs/ntfs3: Use kmalloc_array over kmalloc with multiply
Date: Thu, 2 Sep 2021 14:03:17 +0000	[thread overview]
Message-ID: <6c078835254b43ec82bf45db3b241510@AcuMS.aculab.com> (raw)
In-Reply-To: <5197939870d1867dd2131a8fdff8842b777c6016.camel@perches.com>

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)


  parent reply	other threads:[~2021-09-02 14:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31 18:15 [PATCH 0/5] fs/ntfs3: Fix various styling issues Kari Argillander
2021-08-31 18:15 ` [PATCH 1/5] fs/ntfs3: Use kmalloc_array over kmalloc with multiply Kari Argillander
2021-09-01  2:40   ` Joe Perches
2021-09-01 13:24     ` Kari Argillander
2021-09-02 14:03     ` David Laight [this message]
2021-08-31 18:15 ` [PATCH 2/5] fs/ntfs3: Use consistent spacing around '+' Kari Argillander
2021-09-02  4:22   ` Joe Perches
2021-09-02  8:10     ` Kari Argillander
2021-09-07 16:23       ` Konstantin Komarov
2021-09-07 16:25         ` Kari Argillander
2021-08-31 18:15 ` [PATCH 3/5] fs/ntfs3: Place Comparisons constant right side of the test Kari Argillander
2021-08-31 18:15 ` [PATCH 4/5] fs/ntfs3: Remove braces from single statment block Kari Argillander

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6c078835254b43ec82bf45db3b241510@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=joe@perches.com \
    --cc=kari.argillander@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --subject='RE: [PATCH 1/5] fs/ntfs3: Use kmalloc_array over kmalloc with multiply' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).