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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d5591ca1-7413-4575-90e4-a22ac81cd2b8@intel.com>
Date: Thu, 5 Dec 2024 09:45:46 +0100
From: Mateusz Polchlopek <mateusz.polchlopek@...el.com>
To: Oleksij Rempel <o.rempel@...gutronix.de>, "David S. Miller"
	<davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski
	<kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>, Andrew Lunn
	<andrew+netdev@...n.ch>, Heiner Kallweit <hkallweit1@...il.com>, "Jonathan
 Corbet" <corbet@....net>
CC: <kernel@...gutronix.de>, <linux-kernel@...r.kernel.org>,
	<netdev@...r.kernel.org>, Simon Horman <horms@...nel.org>, Russell King
	<linux@...linux.org.uk>, Maxime Chevallier <maxime.chevallier@...tlin.com>,
	<linux-doc@...r.kernel.org>
Subject: Re: [PATCH net-next v1 5/7] ethtool: add helper to prevent invalid
 statistics exposure to userspace



On 12/3/2024 8:56 AM, Oleksij Rempel wrote:
> Introduce a new helper function, `ethtool_stat_add`, to update 64-bit
> statistics with proper handling of the reserved value
> `ETHTOOL_STAT_NOT_SET`. This ensures that statistics remain valid and
> are always reported to userspace, even if the driver accidentally sets
> `ETHTOOL_STAT_NOT_SET` during an update.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@...gutronix.de>
> ---
>   include/linux/ethtool.h | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
> index b0ed740ca749..657bd69ddaf7 100644
> --- a/include/linux/ethtool.h
> +++ b/include/linux/ethtool.h
> @@ -371,6 +371,22 @@ static inline void ethtool_stats_init(u64 *stats, unsigned int n)
>   		stats[n] = ETHTOOL_STAT_NOT_SET;
>   }
>   
> +/**
> + * ethtool_stat_add - Add a value to a u64 statistic with wraparound handling
> + * @stat: Pointer to the statistic to update
> + * @value: Value to add to the statistic
> + *
> + * Adds the specified value to a u64 statistic. If the result of the addition
> + * equals the reserved value (`ETHTOOL_STAT_NOT_SET`), it increments the result
> + * by 1 to avoid the reserved value.
> + */
> +static inline void ethtool_stat_add(u64 *stat, u64 value)
> +{
> +	*stat += value;
> +	if (*stat == ETHTOOL_STAT_NOT_SET)
> +		(*stat)++;
> +}
> +
>   /* Basic IEEE 802.3 MAC statistics (30.3.1.1.*), not otherwise exposed
>    * via a more targeted API.
>    */

The code of function looks good

Reviewed-by: Mateusz Polchlopek <mateusz.polchlopek@...el.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ