[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a7c002f7-c6f2-a9ed-0100-acfbafea65c5@linux.com>
Date: Tue, 1 Oct 2019 18:13:21 +0300
From: Denis Efremov <efremov@...ux.com>
To: David Laight <David.Laight@...LAB.COM>,
'Dan Carpenter' <dan.carpenter@...cle.com>
Cc: "devel@...verdev.osuosl.org" <devel@...verdev.osuosl.org>,
Jes Sorensen <jes.sorensen@...il.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"stable@...r.kernel.org" <stable@...r.kernel.org>,
Hans de Goede <hdegoede@...hat.com>,
Bastien Nocera <hadess@...ess.net>,
Dmitry Vyukov <dvyukov@...gle.com>,
Larry Finger <Larry.Finger@...inger.net>
Subject: Re: [PATCH] staging: rtl8723bs: hal: Fix memcpy calls
On 10/1/19 5:36 PM, David Laight wrote:
>> From: Dan Carpenter
>> Sent: 01 October 2019 14:57
>> Subject: Re: [PATCH] staging: rtl8723bs: hal: Fix memcpy calls
> ...
>> That's true for glibc memcpy() but not for the kernel memcpy(). In the
>> kernel there are lots of places which do a zero size memcpy().
>
> And probably from NULL (or even garbage) pointers.
>
> After all a pointer to the end of an array (a + ARRAY_SIZE(a)) is valid
> but must not be dereferenced - so memcpy() can't dereference it's
> source address when the length is zero.
>
>> The glibc attitude is "the standard allows us to put knives here" so
>> let's put knives everywhere in the path. And the GCC attitude is let's
>> silently remove NULL checks instead of just printing a warning that the
>> NULL check isn't required... It could really make someone despondent.
>
> gcc is the one that add knives...
>
Just found an official documentation to this issue:
https://gcc.gnu.org/gcc-4.9/porting_to.html
"Null pointer checks may be optimized away more aggressively
...
The pointers passed to memmove (and similar functions in <string.h>) must be non-null
even when nbytes==0, so GCC can use that information to remove the check after the
memmove call. Calling copy(p, NULL, 0) can therefore deference a null pointer and crash."
But again, I would say that the bug in this code is because the if condition was copy-pasted
and it should be inverted.
Thanks,
Denis
Powered by blists - more mailing lists