Re: [PATCH] drm/nouveau/nvif: Avoid build error due to potential integer overflows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]<

 



On 5/18/24 18:19, Joe Perches wrote:
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)


Sure, I can do that as well. I'll wait a couple of days though before
sending v3 in case there are more change requests.

Guenter




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux