diff mbox series

[v5,net-next,4/4] rtnetlink: return EINVAL when request cannot succeed

Message ID 20220415165330.10497-5-florent.fourcot@wifirst.fr (mailing list archive)
State Accepted
Commit b6177d3240a4f58fe547891010ad77a45bc1c9ab
Delegated to: Netdev Maintainers
Headers show
Series rtnetlink: improve ALT_IFNAME config and fix dangerous GROUP usage | 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 Series has a cover letter
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: 2 this patch: 2
netdev/cc_maintainers fail 4 maintainers not CCed: davem@davemloft.net kuba@kernel.org petrm@nvidia.com pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 9 this patch: 9
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: 2 this patch: 2
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

Florent Fourcot April 15, 2022, 4:53 p.m. UTC
A request without interface name/interface index/interface group cannot
work. We should return EINVAL

Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
Signed-off-by: Brian Baboch <brian.baboch@wifirst.fr>
---
 net/core/rtnetlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stephen Hemminger April 15, 2022, 7:26 p.m. UTC | #1
On Fri, 15 Apr 2022 18:53:30 +0200
Florent Fourcot <florent.fourcot@wifirst.fr> wrote:

> A request without interface name/interface index/interface group cannot
> work. We should return EINVAL
> 
> Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
> Signed-off-by: Brian Baboch <brian.baboch@wifirst.fr>
> ---
>  net/core/rtnetlink.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index 73f2cbc440c9..b943336908a7 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -3457,7 +3457,7 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
>  			return rtnl_group_changelink(skb, net,
>  						nla_get_u32(tb[IFLA_GROUP]),
>  						ifm, extack, tb);
> -		return -ENODEV;
> +		return -EINVAL;

Sometimes changing errno can be viewed as ABI change and break applications.
Florent Fourcot April 19, 2022, 7:29 a.m. UTC | #2
>> -		return -ENODEV;
>> +		return -EINVAL;
> 
> Sometimes changing errno can be viewed as ABI change and break applications.

I agree, but I think this one is OK. __rtnl_newlink function has more 
than 20 return, I don't see how an application can have behavior based 
on this specific path.

And actually, patch 1/4 is protecting almost all previous callers, this 
return is now only here for calls without ifindex/ifname/ifgroup, and 
NLM_F_CREATE not set.

If you think that this change can be merged, I can add extack error at 
this place. EINVAL is indeed very hard to parse.
Vinicius Costa Gomes April 22, 2022, 1:27 a.m. UTC | #3
Stephen Hemminger <stephen@networkplumber.org> writes:

> On Fri, 15 Apr 2022 18:53:30 +0200
> Florent Fourcot <florent.fourcot@wifirst.fr> wrote:
>
>> A request without interface name/interface index/interface group cannot
>> work. We should return EINVAL
>> 
>> Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
>> Signed-off-by: Brian Baboch <brian.baboch@wifirst.fr>
>> ---
>>  net/core/rtnetlink.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
>> index 73f2cbc440c9..b943336908a7 100644
>> --- a/net/core/rtnetlink.c
>> +++ b/net/core/rtnetlink.c
>> @@ -3457,7 +3457,7 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
>>  			return rtnl_group_changelink(skb, net,
>>  						nla_get_u32(tb[IFLA_GROUP]),
>>  						ifm, extack, tb);
>> -		return -ENODEV;
>> +		return -EINVAL;
>
> Sometimes changing errno can be viewed as ABI change and break applications.

It seems that this is already breaking applications. iproute2 ip-link
depends on the returned error:

https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/ip/iplink.c#n221


Cheers,
diff mbox series

Patch

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 73f2cbc440c9..b943336908a7 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3457,7 +3457,7 @@  static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 			return rtnl_group_changelink(skb, net,
 						nla_get_u32(tb[IFLA_GROUP]),
 						ifm, extack, tb);
-		return -ENODEV;
+		return -EINVAL;
 	}
 
 	if (tb[IFLA_MAP] || tb[IFLA_PROTINFO])