diff mbox series

net/bridge: replace simple_strtoul to kstrtol

Message ID 20211119020642.108397-1-bernard@vivo.com (mailing list archive)
State Accepted
Commit 520fbdf7fb19b7744e370d36d9244a446299ceb7
Delegated to: Netdev Maintainers
Headers show
Series net/bridge: replace simple_strtoul to kstrtol | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
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 success CCed 6 of 6 maintainers
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Bernard Zhao Nov. 19, 2021, 2:06 a.m. UTC
simple_strtoull is obsolete, use kstrtol instead.

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
 net/bridge/br_sysfs_br.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Nov. 19, 2021, 2:20 p.m. UTC | #1
Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Thu, 18 Nov 2021 18:06:42 -0800 you wrote:
> simple_strtoull is obsolete, use kstrtol instead.
> 
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>  net/bridge/br_sysfs_br.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)

Here is the summary with links:
  - net/bridge: replace simple_strtoul to kstrtol
    https://git.kernel.org/netdev/net-next/c/520fbdf7fb19

You are awesome, thank you!
David Laight Nov. 20, 2021, 9:57 p.m. UTC | #2
From: Bernard Zhao
> Sent: 19 November 2021 02:07
> 
> simple_strtoull is obsolete, use kstrtol instead.

I think the death announcement of simple_strtoull() has already
been deemed premature.
kstrtol() isn't a replacment in many cases.

> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>  net/bridge/br_sysfs_br.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
> index d9a89ddd0331..11c490694296 100644
> --- a/net/bridge/br_sysfs_br.c
> +++ b/net/bridge/br_sysfs_br.c
> @@ -36,15 +36,14 @@ static ssize_t store_bridge_parm(struct device *d,
>  	struct net_bridge *br = to_bridge(d);
>  	struct netlink_ext_ack extack = {0};
>  	unsigned long val;
> -	char *endp;
>  	int err;
> 
>  	if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
>  		return -EPERM;
> 
> -	val = simple_strtoul(buf, &endp, 0);
> -	if (endp == buf)
> -		return -EINVAL;
> +	err = kstrtoul(buf, 10, &val);
> +	if (err != 0)
> +		return err;

That changes the valid input strings.
So is a UAPI change.
Now it might be that no one passes in strings that now fail,
but you can't tell.

Rightfully or not it used to ignore any trailing characters.
So "10flobbs" would be treated as "10".

Did you also check what happens to 0x1234 and 012 ?

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Ido Schimmel Nov. 22, 2021, 10:04 a.m. UTC | #3
On Thu, Nov 18, 2021 at 06:06:42PM -0800, Bernard Zhao wrote:
> simple_strtoull is obsolete, use kstrtol instead.
> 
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>  net/bridge/br_sysfs_br.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
> index d9a89ddd0331..11c490694296 100644
> --- a/net/bridge/br_sysfs_br.c
> +++ b/net/bridge/br_sysfs_br.c
> @@ -36,15 +36,14 @@ static ssize_t store_bridge_parm(struct device *d,
>  	struct net_bridge *br = to_bridge(d);
>  	struct netlink_ext_ack extack = {0};
>  	unsigned long val;
> -	char *endp;
>  	int err;
>  
>  	if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
>  		return -EPERM;
>  
> -	val = simple_strtoul(buf, &endp, 0);
> -	if (endp == buf)
> -		return -EINVAL;
> +	err = kstrtoul(buf, 10, &val);

Base 16 is valid.

Before this patch:

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

After this patch:

# 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

> +	if (err != 0)
> +		return err;
>  
>  	if (!rtnl_trylock())
>  		return restart_syscall();
> -- 
> 2.33.1
>
Nikolay Aleksandrov Nov. 22, 2021, 10:17 a.m. UTC | #4
On 22/11/2021 12:04, Ido Schimmel wrote:
> On Thu, Nov 18, 2021 at 06:06:42PM -0800, Bernard Zhao wrote:
>> simple_strtoull is obsolete, use kstrtol instead.
>>
>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>> ---
>>  net/bridge/br_sysfs_br.c | 7 +++----
>>  1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
>> index d9a89ddd0331..11c490694296 100644
>> --- a/net/bridge/br_sysfs_br.c
>> +++ b/net/bridge/br_sysfs_br.c
>> @@ -36,15 +36,14 @@ static ssize_t store_bridge_parm(struct device *d,
>>  	struct net_bridge *br = to_bridge(d);
>>  	struct netlink_ext_ack extack = {0};
>>  	unsigned long val;
>> -	char *endp;
>>  	int err;
>>  
>>  	if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
>>  		return -EPERM;
>>  
>> -	val = simple_strtoul(buf, &endp, 0);
>> -	if (endp == buf)
>> -		return -EINVAL;
>> +	err = kstrtoul(buf, 10, &val);
> 
> Base 16 is valid.
> 
> Before this patch:
> 
> # ip link add name br0 type bridge vlan_filtering 1
> # echo "0x88a8" > /sys/class/net/br0/bridge/vlan_protocol
> # echo $?
> 0
> 
> After this patch:
> 
> # 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
> 

Good catch, Bernard please send a revert. Thanks.
Jakub Kicinski Nov. 24, 2021, 4:13 a.m. UTC | #5
On Mon, 22 Nov 2021 12:17:39 +0200 Nikolay Aleksandrov wrote:
> > # 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
> 
> Good catch, Bernard please send a revert. Thanks.

Doesn't look like he did, would you mind taking over?
Nikolay Aleksandrov Nov. 24, 2021, 10:18 a.m. UTC | #6
On 24/11/2021 06:13, Jakub Kicinski wrote:
> On Mon, 22 Nov 2021 12:17:39 +0200 Nikolay Aleksandrov wrote:
>>> # 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
>>
>> Good catch, Bernard please send a revert. Thanks.
> 
> Doesn't look like he did, would you mind taking over?
> 

Ido sent a patch to take care of it:
https://patchwork.kernel.org/project/netdevbpf/patch/20211124101122.3321496-1-idosch@idosch.org/

Cheers,
 Nik
diff mbox series

Patch

diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
index d9a89ddd0331..11c490694296 100644
--- a/net/bridge/br_sysfs_br.c
+++ b/net/bridge/br_sysfs_br.c
@@ -36,15 +36,14 @@  static ssize_t store_bridge_parm(struct device *d,
 	struct net_bridge *br = to_bridge(d);
 	struct netlink_ext_ack extack = {0};
 	unsigned long val;
-	char *endp;
 	int err;
 
 	if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
 		return -EPERM;
 
-	val = simple_strtoul(buf, &endp, 0);
-	if (endp == buf)
-		return -EINVAL;
+	err = kstrtoul(buf, 10, &val);
+	if (err != 0)
+		return err;
 
 	if (!rtnl_trylock())
 		return restart_syscall();