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]
Date:   Mon, 18 Mar 2019 12:25:20 +0100
From:   Pavel Machek <pavel@....cz>
To:     Rasmus Villemoes <linux@...musvillemoes.dk>
Cc:     Uwe Kleine-König 
        <u.kleine-koenig@...gutronix.de>,
        Jacek Anaszewski <jacek.anaszewski@...il.com>,
        LKML <linux-kernel@...r.kernel.org>, linux-leds@...r.kernel.org
Subject: Re: [PATCH v2 3/6] leds: netdev trigger: move newline handling back
 to device_name_store

On Thu 2019-03-14 15:06:16, Rasmus Villemoes wrote:
> Currently, setting device_name to a 15-character name requires
> avoiding a trailing newline (e.g. by using 'echo -n' or 'printf'),
> which is inconsistent and potentially surprising. Instead of
> potentially including a newline in the copy and then overwriting it,
> move the newline detection logic to the sysfs handler itself, and
> handle it by passing a smaller buffer size to
> netdev_trig_set_device().
> 
> This also makes netdev_trig_set_device() a better fit for a future
> user, which will not need the newline truncation logic.
> 
> We still have to tell userspace we consumed all the bytes it gave us,
> so we have to stash the original value of size.
> 
> Signed-off-by: Rasmus Villemoes <linux@...musvillemoes.dk>

Acked-by: Pavel Machek <pavel@....cz>

> ---
>  drivers/leds/trigger/ledtrig-netdev.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
> index 21605033e322..c35439291424 100644
> --- a/drivers/leds/trigger/ledtrig-netdev.c
> +++ b/drivers/leds/trigger/ledtrig-netdev.c
> @@ -114,8 +114,6 @@ static void netdev_trig_set_device(struct led_netdev_data *trigger_data,
>  
>  	memcpy(trigger_data->device_name, buf, size);
>  	trigger_data->device_name[size] = 0;
> -	if (size > 0 && trigger_data->device_name[size - 1] == '\n')
> -		trigger_data->device_name[size - 1] = 0;
>  
>  	if (trigger_data->device_name[0] != 0)
>  		trigger_data->net_dev =
> @@ -134,7 +132,11 @@ static ssize_t device_name_store(struct device *dev,
>  				 size_t size)
>  {
>  	struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
> +	size_t orig_size = size;
>  
> +	/* Ignore trailing newline */
> +	if (size > 0 && buf[size - 1] == '\n')
> +		size--;
>  	if (size >= IFNAMSIZ)
>  		return -EINVAL;
>  
> @@ -147,7 +149,7 @@ static ssize_t device_name_store(struct device *dev,
>  	set_baseline_state(trigger_data);
>  	spin_unlock_bh(&trigger_data->lock);
>  
> -	return size;
> +	return orig_size;
>  }
>  
>  static DEVICE_ATTR_RW(device_name);

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Download attachment "signature.asc" of type "application/pgp-signature" (182 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ