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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8b2903c9-e56b-ea22-41b2-d6f96bec1d96@rasmusvillemoes.dk>
Date:   Thu, 14 Mar 2019 10:57:14 +0100
From:   Rasmus Villemoes <linux@...musvillemoes.dk>
To:     Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
Cc:     Pavel Machek <pavel@....cz>,
        Jacek Anaszewski <jacek.anaszewski@...il.com>,
        LKML <linux-kernel@...r.kernel.org>, linux-leds@...r.kernel.org
Subject: Re: [PATCH 1/4] leds: netdev trigger: use memcpy in device_name_store

On 14/03/2019 10.29, Uwe Kleine-König wrote:
> Hello,
> 
> On Wed, Mar 13, 2019 at 09:26:12PM +0100, Rasmus Villemoes wrote:
>> --- a/drivers/leds/trigger/ledtrig-netdev.c
>> +++ b/drivers/leds/trigger/ledtrig-netdev.c
>> @@ -122,7 +122,8 @@ static ssize_t device_name_store(struct device *dev,
>>  		trigger_data->net_dev = NULL;
>>  	}
>>  
>> -	strncpy(trigger_data->device_name, buf, size);
>> +	memcpy(trigger_data->device_name, buf, size);
>> +	trigger_data->device_name[size] = '\0';
> 
> This is open-coding
> 
> 	strlcpy(trigger_data->device_name, buf, size);

No. size here is the number of bytes userspace wrote, which never (well,
almost never, they could do something odd) contain a nul byte. Passing
that as size to strlcpy would guarantee that we chopped off the last
character from the user input. And while I do think the generic sysfs
layer guarantees that the PAGE_SIZE buffer is zeroed before reading from
userspace, I don't really want to rely on buf being a nul-terminated
string (which it must be if using strlcpy - remember that that does a
full strlen() to compute its return value). If anything, one could do
strlcpy(, buf, size+1), but IMO copying the actual characters the user
wrote, then explicitly making that into a nul-terminated string is much
more straight-forward.

Rasmus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ