diff mbox series

[net-next] net: bridge: Allow base 16 inputs in sysfs

Message ID 20211124101122.3321496-1-idosch@idosch.org (mailing list archive)
State Accepted
Commit 5a45ab3f248b3489af8b8440eb56b2ebaae59a6c
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: bridge: Allow base 16 inputs in sysfs | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 1 maintainers not CCed: bridge@lists.linux-foundation.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Ido Schimmel Nov. 24, 2021, 10:11 a.m. UTC
From: Ido Schimmel <idosch@nvidia.com>

Cited commit converted simple_strtoul() to kstrtoul() as suggested by
the former's documentation. However, it also forced all the inputs to be
decimal resulting in user space breakage.

Fix by setting the base to '0' so that the base is automatically
detected.

Before:

 # ip link add name br0 type bridge vlan_filtering 1
 # echo "0x88a8" > /sys/class/net/br0/bridge/vlan_protocol
 bash: echo: write error: Invalid argument

After:

 # ip link add name br0 type bridge vlan_filtering 1
 # echo "0x88a8" > /sys/class/net/br0/bridge/vlan_protocol
 # echo $?
 0

Fixes: 520fbdf7fb19 ("net/bridge: replace simple_strtoul to kstrtol")
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 net/bridge/br_sysfs_br.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nikolay Aleksandrov Nov. 24, 2021, 10:17 a.m. UTC | #1
On 24/11/2021 12:11, Ido Schimmel wrote:
> From: Ido Schimmel <idosch@nvidia.com>
> 
> Cited commit converted simple_strtoul() to kstrtoul() as suggested by
> the former's documentation. However, it also forced all the inputs to be
> decimal resulting in user space breakage.
> 
> Fix by setting the base to '0' so that the base is automatically
> detected.
> 
> Before:
> 
>  # ip link add name br0 type bridge vlan_filtering 1
>  # echo "0x88a8" > /sys/class/net/br0/bridge/vlan_protocol
>  bash: echo: write error: Invalid argument
> 
> After:
> 
>  # ip link add name br0 type bridge vlan_filtering 1
>  # echo "0x88a8" > /sys/class/net/br0/bridge/vlan_protocol
>  # echo $?
>  0
> 
> Fixes: 520fbdf7fb19 ("net/bridge: replace simple_strtoul to kstrtol")
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> ---

Thank you for taking care of this.
Acked-by: Nikolay Aleksandrov <nikolay@nvidia.com>

>  net/bridge/br_sysfs_br.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
> index 11c490694296..159590d5c2af 100644
> --- a/net/bridge/br_sysfs_br.c
> +++ b/net/bridge/br_sysfs_br.c
> @@ -41,7 +41,7 @@ static ssize_t store_bridge_parm(struct device *d,
>  	if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
>  		return -EPERM;
>  
> -	err = kstrtoul(buf, 10, &val);
> +	err = kstrtoul(buf, 0, &val);
>  	if (err != 0)
>  		return err;
>  
>
David Laight Nov. 24, 2021, 12:55 p.m. UTC | #2
From: Ido Schimmel
> Sent: 24 November 2021 10:11
>
> Cited commit converted simple_strtoul() to kstrtoul() as suggested by
> the former's documentation. However, it also forced all the inputs to be
> decimal resulting in user space breakage.
> 
> Fix by setting the base to '0' so that the base is automatically
> detected.

Do both functions ignore leading whitespace?

I recently had to fix some code that did:
	if (write(sys_class_led_fd, on ? "255" : "  0", 3) != 3)
		return error.
I'm pretty sure I'd tested it before and it worked ok.
But I had to use "000" with a later kernel.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Ido Schimmel Nov. 24, 2021, 1:16 p.m. UTC | #3
On Wed, Nov 24, 2021 at 12:55:33PM +0000, David Laight wrote:
> From: Ido Schimmel
> > Sent: 24 November 2021 10:11
> >
> > Cited commit converted simple_strtoul() to kstrtoul() as suggested by
> > the former's documentation. However, it also forced all the inputs to be
> > decimal resulting in user space breakage.
> > 
> > Fix by setting the base to '0' so that the base is automatically
> > detected.
> 
> Do both functions ignore leading whitespace?

With this patch (kstrtoul):

# ip link add name br0 type bridge vlan_filtering 1
# echo "    0x88a8" > /sys/class/net/br0/bridge/vlan_protocol
bash: echo: write error: Invalid argument

With simple_strtoul:

# ip link add name br0 type bridge vlan_filtering 1
# echo "    0x88a8" > /sys/class/net/br0/bridge/vlan_protocol
bash: echo: write error: Invalid argument
patchwork-bot+netdevbpf@kernel.org Nov. 25, 2021, 1:30 a.m. UTC | #4
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 24 Nov 2021 12:11:22 +0200 you wrote:
> From: Ido Schimmel <idosch@nvidia.com>
> 
> Cited commit converted simple_strtoul() to kstrtoul() as suggested by
> the former's documentation. However, it also forced all the inputs to be
> decimal resulting in user space breakage.
> 
> Fix by setting the base to '0' so that the base is automatically
> detected.
> 
> [...]

Here is the summary with links:
  - [net-next] net: bridge: Allow base 16 inputs in sysfs
    https://git.kernel.org/netdev/net-next/c/5a45ab3f248b

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
index 11c490694296..159590d5c2af 100644
--- a/net/bridge/br_sysfs_br.c
+++ b/net/bridge/br_sysfs_br.c
@@ -41,7 +41,7 @@  static ssize_t store_bridge_parm(struct device *d,
 	if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
 		return -EPERM;
 
-	err = kstrtoul(buf, 10, &val);
+	err = kstrtoul(buf, 0, &val);
 	if (err != 0)
 		return err;