All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Guenter Roeck <linux@roeck-us.net>,
	Kees Cook <keescook@chromium.org>,
	 Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: airlied@gmail.com, dakr@redhat.com, daniel@ffwll.ch,
	 dri-devel@lists.freedesktop.org, jani.nikula@intel.com,
	javierm@redhat.com, kherbst@redhat.com,
	linux-kernel@vger.kernel.org, lyude@redhat.com,
	 mripard@kernel.org, nouveau@lists.freedesktop.org,
	tzimmermann@suse.de,  linux-hardening@vger.kernel.org
Subject: Re: [PATCH] drm/nouveau/nvif: Avoid build error due to potential integer overflows
Date: Sat, 18 May 2024 18:19:18 -0700	[thread overview]
Message-ID: <03cc262da2a3db817aa5663fbce6c914708b74f8.camel@perches.com> (raw)
In-Reply-To: <a912c2d1-9008-410a-92cc-912e17c63695@roeck-us.net>

On Sat, 2024-05-18 at 11:23 -0700, Guenter Roeck wrote:
> On 5/18/24 10:32, Kees Cook wrote:
> 
[]
> > I think the INT_MAX test is actually better in this case because
> > nvif_object_ioctl()'s size argument is u32:
> > 
> > ret = nvif_object_ioctl(object, args, sizeof(*args) + size, NULL);
> >                                        ^^^^^^^^^^^^^^^^^^^^
> > 
> > So that could wrap around, even though the allocation may not.
> > 
> > Better yet, since "sizeof(*args) + size" is repeated 3 times in the
> > function, I'd recommend:
> > 
> > 	...
> > 	u32 args_size;
> > 
> > 	if (check_add_overflow(sizeof(*args), size, &args_size))
> > 		return -ENOMEM;
> > 	if (args_size > sizeof(stack)) {
> > 		if (!(args = kmalloc(args_size, GFP_KERNEL)))

trivia:

More typical kernel style would use separate alloc and test

		args = kmalloc(args_size, GFP_KERNEL);
		if (!args)

> > 			return -ENOMEM;
> >          } else {
> >                  args = (void *)stack;
> >          }
> > 	...
> >          ret = nvif_object_ioctl(object, args, args_size, NULL);
> > 
> > This will catch the u32 overflow to nvif_object_ioctl(), catch an
> > allocation underflow on 32-bits systems, and make the code more
> > readable. :)
> > 
> 
> Makes sense. I'll change that and send v2.
> 
> Thanks,
> Guenter
> 
> 


  reply	other threads:[~2024-05-19  1:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-18 14:37 [PATCH] drm/nouveau/nvif: Avoid build error due to potential integer overflows Guenter Roeck
2024-05-18 16:54 ` Christophe JAILLET
2024-05-18 17:32   ` Kees Cook
2024-05-18 18:23     ` Guenter Roeck
2024-05-19  1:19       ` Joe Perches [this message]
2024-05-19 14:09         ` Guenter Roeck

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=03cc262da2a3db817aa5663fbce6c914708b74f8.camel@perches.com \
    --to=joe@perches.com \
    --cc=airlied@gmail.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=dakr@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    --cc=javierm@redhat.com \
    --cc=keescook@chromium.org \
    --cc=kherbst@redhat.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lyude@redhat.com \
    --cc=mripard@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=tzimmermann@suse.de \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.