netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] rtnetlink: Fail dump if target netnsid is invalid
@ 2018-09-28 19:28 David Ahern
  2018-10-02  6:22 ` David Miller
  2018-10-02 10:04 ` Jiri Benc
  0 siblings, 2 replies; 4+ messages in thread
From: David Ahern @ 2018-09-28 19:28 UTC (permalink / raw)
  To: netdev; +Cc: jbenc, davem, David Ahern

From: David Ahern <dsahern@gmail.com>

Link dumps can return results from a target namespace. If the namespace id
is invalid, then the dump request should fail if get_target_net fails
rather than continuing with a dump of the current namespace.

Fixes: 79e1ad148c844 ("rtnetlink: use netnsid to query interface")
Signed-off-by: David Ahern <dsahern@gmail.com>
---
 net/core/rtnetlink.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 63ce2283a456..7f37fe9c65a5 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1898,10 +1898,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
 		if (tb[IFLA_IF_NETNSID]) {
 			netnsid = nla_get_s32(tb[IFLA_IF_NETNSID]);
 			tgt_net = get_target_net(skb->sk, netnsid);
-			if (IS_ERR(tgt_net)) {
-				tgt_net = net;
-				netnsid = -1;
-			}
+			if (IS_ERR(tgt_net))
+				return PTR_ERR(tgt_net);
 		}
 
 		if (tb[IFLA_EXT_MASK])
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] rtnetlink: Fail dump if target netnsid is invalid
  2018-09-28 19:28 [PATCH net] rtnetlink: Fail dump if target netnsid is invalid David Ahern
@ 2018-10-02  6:22 ` David Miller
  2018-10-02 10:04 ` Jiri Benc
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2018-10-02  6:22 UTC (permalink / raw)
  To: dsahern; +Cc: netdev, jbenc, dsahern

From: David Ahern <dsahern@kernel.org>
Date: Fri, 28 Sep 2018 12:28:41 -0700

> From: David Ahern <dsahern@gmail.com>
> 
> Link dumps can return results from a target namespace. If the namespace id
> is invalid, then the dump request should fail if get_target_net fails
> rather than continuing with a dump of the current namespace.
> 
> Fixes: 79e1ad148c844 ("rtnetlink: use netnsid to query interface")
> Signed-off-by: David Ahern <dsahern@gmail.com>

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] rtnetlink: Fail dump if target netnsid is invalid
  2018-09-28 19:28 [PATCH net] rtnetlink: Fail dump if target netnsid is invalid David Ahern
  2018-10-02  6:22 ` David Miller
@ 2018-10-02 10:04 ` Jiri Benc
  2018-10-02 14:41   ` David Ahern
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Benc @ 2018-10-02 10:04 UTC (permalink / raw)
  To: David Ahern; +Cc: netdev, davem, David Ahern

On Fri, 28 Sep 2018 12:28:41 -0700, David Ahern wrote:
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -1898,10 +1898,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
>  		if (tb[IFLA_IF_NETNSID]) {
>  			netnsid = nla_get_s32(tb[IFLA_IF_NETNSID]);
>  			tgt_net = get_target_net(skb->sk, netnsid);
> -			if (IS_ERR(tgt_net)) {
> -				tgt_net = net;
> -				netnsid = -1;
> -			}
> +			if (IS_ERR(tgt_net))
> +				return PTR_ERR(tgt_net);
>  		}
>  
>  		if (tb[IFLA_EXT_MASK])

Sorry for the late review, I see it has been applied.

I intentionally chose the behavior to preserve the behavior of the
older kernels: that attribute was silently ignored. Note that the
IFLA_IF_NETNSID is not returned in such case, thus it's easy to
distinguish that it was not applied. And the user space has to do such
check anyway to support old kernels.

But you're right that there was no way to distinguish "the kernel does
not support IFLA_IF_NETNSID" from "wrong IFLA_IF_NETNSID provided". I'm
okay with the patch, I just don't think the "Fixes" tag is justified but
whatever, can't be unapplied :-) (and it's my fault for not reviewing
the patches timely).

Thanks!

 Jiri

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] rtnetlink: Fail dump if target netnsid is invalid
  2018-10-02 10:04 ` Jiri Benc
@ 2018-10-02 14:41   ` David Ahern
  0 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2018-10-02 14:41 UTC (permalink / raw)
  To: Jiri Benc, David Ahern; +Cc: netdev, davem

On 10/2/18 4:04 AM, Jiri Benc wrote:
> On Fri, 28 Sep 2018 12:28:41 -0700, David Ahern wrote:
>> --- a/net/core/rtnetlink.c
>> +++ b/net/core/rtnetlink.c
>> @@ -1898,10 +1898,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
>>  		if (tb[IFLA_IF_NETNSID]) {
>>  			netnsid = nla_get_s32(tb[IFLA_IF_NETNSID]);
>>  			tgt_net = get_target_net(skb->sk, netnsid);
>> -			if (IS_ERR(tgt_net)) {
>> -				tgt_net = net;
>> -				netnsid = -1;
>> -			}
>> +			if (IS_ERR(tgt_net))
>> +				return PTR_ERR(tgt_net);
>>  		}
>>  
>>  		if (tb[IFLA_EXT_MASK])
> 
> Sorry for the late review, I see it has been applied.
> 
> I intentionally chose the behavior to preserve the behavior of the
> older kernels: that attribute was silently ignored. Note that the
> IFLA_IF_NETNSID is not returned in such case, thus it's easy to
> distinguish that it was not applied. And the user space has to do such
> check anyway to support old kernels.

First, rtnl_dellink, rtnl_newlink and rtnl_getlink all fail if net
namespace id is invalid. Second, the user is requesting data from a
target namespace and the dump happily continued with the current
namespace which is not what the user requested. Hence, it makes no sense
for a dump to continue which is why I sent the patch.

> 
> But you're right that there was no way to distinguish "the kernel does
> not support IFLA_IF_NETNSID" from "wrong IFLA_IF_NETNSID provided". I'm
> okay with the patch, I just don't think the "Fixes" tag is justified but
> whatever, can't be unapplied :-) (and it's my fault for not reviewing
> the patches timely).

The id was the commit that added the code to ignore the error.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-02 21:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-28 19:28 [PATCH net] rtnetlink: Fail dump if target netnsid is invalid David Ahern
2018-10-02  6:22 ` David Miller
2018-10-02 10:04 ` Jiri Benc
2018-10-02 14:41   ` David Ahern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).