wireguard.lists.zx2c4.com archive mirror
 help / color / mirror / Atom feed
From: Xiao Liang <shaw.leon@gmail.com>
To: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: andrew+netdev@lunn.ch, b.a.t.m.a.n@lists.open-mesh.org,
	 bpf@vger.kernel.org, bridge@lists.linux.dev,
	davem@davemloft.net,  donald.hunter@gmail.com,
	dsahern@kernel.org, edumazet@google.com,  horms@kernel.org,
	idosch@nvidia.com, jiri@resnulli.us, kuba@kernel.org,
	 linux-can@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-kselftest@vger.kernel.org, linux-ppp@vger.kernel.org,
	 linux-rdma@vger.kernel.org, linux-wireless@vger.kernel.org,
	 linux-wpan@vger.kernel.org, liuhangbin@gmail.com,
	netdev@vger.kernel.org,  osmocom-net-gprs@lists.osmocom.org,
	pabeni@redhat.com, shuah@kernel.org,  wireguard@lists.zx2c4.com
Subject: Re: [PATCH net-next v7 00/11] net: Improve netns handling in rtnetlink
Date: Tue, 7 Jan 2025 18:46:38 +0800	[thread overview]
Message-ID: <CABAhCOQAqspiaFO-486UtZpEWsua51f+1f6-LocNhHVfAqW=NQ@mail.gmail.com> (raw)
In-Reply-To: <20250107085646.42302-1-kuniyu@amazon.com>

On Tue, Jan 7, 2025 at 4:57 PM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> From: Xiao Liang <shaw.leon@gmail.com>
> Date: Sat,  4 Jan 2025 20:57:21 +0800
[...]
> > - In amt_newlink() drivers/net/amt.c:
> >
> >     amt->net = net;
> >     ...
> >     amt->stream_dev = dev_get_by_index(net, ...
> >
> >   Uses net, but amt_lookup_upper_dev() only searches in dev_net.
> >   So the AMT device may not be properly deleted if it's in a different
> >   netns from lower dev.
>
> I think you are right, and the upper device will be leaked
> and UAF will happen.
>
> amt must manage a list linked to a lower dev.
>
> Given no one has reported the issue, another option would be
> drop cross netns support in a short period.

Yes. I also noticed AMT sets dev->netns_local to prevent netns
change. Probably it also assumes the same netns during creation.

[...]
> >
> > - In gtp_newlink() in drivers/net/gtp.c:
> >
> >     gtp->net = src_net;
> >     ...
> >     gn = net_generic(dev_net(dev), gtp_net_id);
> >     list_add_rcu(&gtp->list, &gn->gtp_dev_list);
> >
> >   Uses src_net, but priv is linked to list in dev_net. So it may not be
> >   properly deleted on removal of link netns.
>
> The device is linked to a list in the same netns, so the
> device will not be leaked.  See gtp_net_exit_batch_rtnl().
>
> Rather, the problem is the udp tunnel socket netns could be
> freed earlier than the dev netns.

Yes, you're right. Actually I mean the netns of the socket by "link netns"
(there's some clarification about this in patch 02).

[...]
> >
> > - In pfcp_newlink() in drivers/net/pfcp.c:
> >
> >     pfcp->net = net;
> >     ...
> >     pn = net_generic(dev_net(dev), pfcp_net_id);
> >     list_add_rcu(&pfcp->list, &pn->pfcp_dev_list);
> >
> >   Same as above.
>
> I haven't tested pfcp but it seems to have the same problem.
>
> I'll post patches for gtp and pfcp.
>

It would be nice.

>
> >
> > - In lowpan_newlink() in net/ieee802154/6lowpan/core.c:
> >
> >     wdev = dev_get_by_index(dev_net(ldev), nla_get_u32(tb[IFLA_LINK]));
> >
> >   Looks for IFLA_LINK in dev_net, but in theory the ifindex is defined
> >   in link netns.
>
> I guess you mean the ifindex is defined in src_net instead.
> Not sure if it's too late to change the behaviour.

Yes, it's source net for lowpan. I think it depends on whether
the interpretation of IFLA_LINK should be considered as part API
provided by rtnetlink core, or something customizable by driver.
In the former case, this can be considered as a bug.

Thanks.

  reply	other threads:[~2025-05-21  9:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-04 12:57 [PATCH net-next v7 00/11] net: Improve netns handling in rtnetlink Xiao Liang
2025-01-04 12:57 ` [PATCH net-next v7 01/11] rtnetlink: Lookup device in target netns when creating link Xiao Liang
2025-01-04 12:57 ` [PATCH net-next v7 02/11] rtnetlink: Pack newlink() params into struct Xiao Liang
2025-01-07 20:38   ` Jakub Kicinski
2025-01-08  8:36     ` Xiao Liang
2025-01-08 17:31       ` Jakub Kicinski
2025-01-04 12:57 ` [PATCH net-next v7 03/11] net: Use link netns in newlink() of rtnl_link_ops Xiao Liang
2025-01-04 12:57 ` [PATCH net-next v7 05/11] net: ip_tunnel: " Xiao Liang
2025-01-04 12:57 ` [PATCH net-next v7 06/11] net: ipv6: " Xiao Liang
2025-01-04 12:57 ` [PATCH net-next v7 07/11] net: xfrm: " Xiao Liang
2025-01-04 12:57 ` [PATCH net-next v7 08/11] rtnetlink: Remove "net" from newlink params Xiao Liang
2025-01-04 12:57 ` [PATCH net-next v7 09/11] rtnetlink: Create link directly in target net namespace Xiao Liang
2025-01-04 12:57 ` [PATCH net-next v7 10/11] selftests: net: Add python context manager for netns entering Xiao Liang
2025-01-04 12:57 ` [PATCH net-next v7 11/11] selftests: net: Add test cases for link and peer netns Xiao Liang
2025-01-07  8:56 ` [PATCH net-next v7 00/11] net: Improve netns handling in rtnetlink Kuniyuki Iwashima
2025-01-07 10:46   ` Xiao Liang [this message]
2025-01-07 12:53   ` Xiao Liang
2025-01-07 14:47     ` Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABAhCOQAqspiaFO-486UtZpEWsua51f+1f6-LocNhHVfAqW=NQ@mail.gmail.com' \
    --to=shaw.leon@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=bpf@vger.kernel.org \
    --cc=bridge@lists.linux.dev \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-ppp@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux-wpan@vger.kernel.org \
    --cc=liuhangbin@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=osmocom-net-gprs@lists.osmocom.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).