lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <34a6d812-b4ed-4465-b0ec-e641d185b9b1@wanadoo.fr>
Date: Sat, 18 May 2024 18:54:36 +0200
From: Christophe JAILLET <christophe.jaillet@...adoo.fr>
To: Guenter Roeck <linux@...ck-us.net>
Cc: airlied@...il.com, dakr@...hat.com, daniel@...ll.ch,
 dri-devel@...ts.freedesktop.org, jani.nikula@...el.com, javierm@...hat.com,
 kherbst@...hat.com, linux-kernel@...r.kernel.org, lyude@...hat.com,
 mripard@...nel.org, nouveau@...ts.freedesktop.org, tzimmermann@...e.de,
 linux-hardening@...r.kernel.org
Subject: Re: [PATCH] drm/nouveau/nvif: Avoid build error due to potential
 integer overflows

(adding linux-hardening@...r.kernel.org)


Le 18/05/2024 à 16:37, Guenter Roeck a écrit :
> Trying to build parisc:allmodconfig with gcc 12.x or later results
> in the following build error.
> 
> drivers/gpu/drm/nouveau/nvif/object.c: In function 'nvif_object_mthd':
> drivers/gpu/drm/nouveau/nvif/object.c:161:9: error:
> 	'memcpy' accessing 4294967264 or more bytes at offsets 0 and 32 overlaps 6442450881 bytes at offset -2147483617 [-Werror=restrict]
>    161 |         memcpy(data, args->mthd.data, size);
>        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/gpu/drm/nouveau/nvif/object.c: In function 'nvif_object_ctor':
> drivers/gpu/drm/nouveau/nvif/object.c:298:17: error:
> 	'memcpy' accessing 4294967240 or more bytes at offsets 0 and 56 overlaps 6442450833 bytes at offset -2147483593 [-Werror=restrict]
>    298 |                 memcpy(data, args->new.data, size);
> 
> gcc assumes that 'sizeof(*args) + size' can overflow, which would result
> in the problem.
> 
> The problem is not new, only it is now no longer a warning but an error since W=1
> has been enabled for the drm subsystem and since Werror is enabled for test builds.
> 
> Rearrange arithmetic and add extra size checks to avoid the overflow.
> 
> Fixes: a61ddb4393ad ("drm: enable (most) W=1 warnings by default across the subsystem")
> Cc: Javier Martinez Canillas <javierm-H+wXaHxf7aLQT0dZR+AlfA@...lic.gmane.org>
> Cc: Jani Nikula <jani.nikula-ral2JQCrhuEAvxtiuMwx3w@...lic.gmane.org>
> Cc: Thomas Zimmermann <tzimmermann-l3A5Bk7waGM@...lic.gmane.org>
> Cc: Danilo Krummrich <dakr-H+wXaHxf7aLQT0dZR+AlfA@...lic.gmane.org>
> Cc: Maxime Ripard <mripard-DgEjT+Ai2ygdnm+yROfE0A@...lic.gmane.org>
> Signed-off-by: Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@...lic.gmane.org>
> ---
> checkpatch complains about the line length in the description and the (pre-existing)
> assignlemts in if conditions, but I did not want to split lines in the description
> or rearrange the code further.
> 
> I don't know why I only see the problem with parisc builds (at least so far).
> 
>   drivers/gpu/drm/nouveau/nvif/object.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvif/object.c b/drivers/gpu/drm/nouveau/nvif/object.c
> index 4d1aaee8fe15..baf623a48874 100644
> --- a/drivers/gpu/drm/nouveau/nvif/object.c
> +++ b/drivers/gpu/drm/nouveau/nvif/object.c
> @@ -145,8 +145,9 @@ nvif_object_mthd(struct nvif_object *object, u32 mthd, void *data, u32 size)
>   	u8 stack[128];
>   	int ret;
>   
> -	if (sizeof(*args) + size > sizeof(stack)) {
> -		if (!(args = kmalloc(sizeof(*args) + size, GFP_KERNEL)))
> +	if (size > sizeof(stack) - sizeof(*args)) {
> +		if (size > INT_MAX ||
> +		    !(args = kmalloc(sizeof(*args) + size, GFP_KERNEL)))

Hi,

Would it be cleaner or better to use size_add(sizeof(*args), size)?

>   			return -ENOMEM;
>   	} else {
>   		args = (void *)stack;
> @@ -276,7 +277,8 @@ nvif_object_ctor(struct nvif_object *parent, const char *name, u32 handle,
>   	object->map.size = 0;
>   
>   	if (parent) {
> -		if (!(args = kmalloc(sizeof(*args) + size, GFP_KERNEL))) {
> +		if (size > INT_MAX ||
> +		    !(args = kmalloc(sizeof(*args) + size, GFP_KERNEL))) {

Same.

CJ

>   			nvif_object_dtor(object);
>   			return -ENOMEM;
>   		}


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ