kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Ignatov <rdna@fb.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: <kernel-janitors@vger.kernel.org>, Jakub Kicinski <kuba@kernel.org>
Subject: Re: [bug report] rtnetlink: Return correct error on changing device netns
Date: Tue, 31 Aug 2021 00:06:21 -0700	[thread overview]
Message-ID: <YS3U7SwGhXVTdI1g@rdna-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <20210830090405.GA6314@kili>

Dan Carpenter <dan.carpenter@oracle.com> [Mon, 2021-08-30 02:04 -0700]:
> Hello Andrey Ignatov,
> 
> This is a semi-automatic email about new static checker warnings.
> 
> The patch 96a6b93b6988: "rtnetlink: Return correct error on changing
> device netns" from Aug 25, 2021, leads to the following Smatch
> complaint:
> 
>     net/core/rtnetlink.c:2698 do_setlink()
>     error: we previously assumed 'ifname' could be null (see line 2608)
> 
> net/core/rtnetlink.c
>   2607		if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD] || tb[IFLA_TARGET_NETNSID]) {
>   2608			const char *pat = ifname && ifname[0] ? ifname : NULL;
>                                           ^^^^^^
> The patch adds a new check for if "ifname" is NULL.  Is this required?

Yes. There is one do_setlink() call that passes NULL as ifname:

net/core/rtnetlink.c

static int rtnl_group_changelink(const struct sk_buff *skb,
...
			err = do_setlink(skb, dev, ifm, extack, tb, NULL, 0);

It handles IFLA_GROUP that can be used with these netns attributes.

W/o the NULL check something like `ip link set group GROUP netns NETNS`
would cause a panic like this:

# ./ifname.sh
+ ip netns add ns0
+ ip link add g1 group 1 type dummy
+ ip link show group 1
10: g1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group 1 qlen 1000
    link/ether ba:3c:5e:9d:8e:ab brd ff:ff:ff:ff:ff:ff
+ ip link set group 1 netns ns0
[    7.566918] BUG: kernel NULL pointer dereference, address: 0000000000000000
[    7.567746] #PF: supervisor read access in kernel mode
[    7.568299] #PF: error_code(0x0000) - not-present page
[    7.568853] PGD 8000000107758067 P4D 8000000107758067 PUD 107757067 PMD 0
[    7.569638] Oops: 0000 [#1] SMP PTI
[    7.570007] CPU: 2 PID: 242 Comm: ip Not tainted 5.14.0-rc7-00093-g1a6436f37512-dirty #533
[    7.570918] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
[    7.572126] RIP: 0010:do_setlink+0x69/0x1070
...

>   2609			struct net *net;
>   2610			int new_ifindex;
>   2611	
>   2612			net = rtnl_link_get_net_capable(skb, dev_net(dev),
>   2613							tb, CAP_NET_ADMIN);
>   2614			if (IS_ERR(net)) {
>   2615				err = PTR_ERR(net);
>   2616				goto errout;
>   2617			}
>   2618	
>   2619			if (tb[IFLA_NEW_IFINDEX])
>   2620				new_ifindex = nla_get_s32(tb[IFLA_NEW_IFINDEX]);
>   2621			else
>   2622				new_ifindex = 0;
>   2623	
>   2624			err = __dev_change_net_namespace(dev, net, pat, new_ifindex);
>   2625			put_net(net);
>   2626			if (err)
>   2627				goto errout;
>   2628			status |= DO_SETLINK_MODIFIED;
>   2629		}
...
>   2693		/*
>   2694		 * Interface selected by interface index but interface
>   2695		 * name provided implies that a name change has been
>   2696		 * requested.
>   2697		 */
>   2698		if (ifm->ifi_index > 0 && ifname[0]) {
>                                           ^^^^^^^^^
> The existing code does not check.

+Jakub

As Jakub explained in [0] this code can not be called with ifname=NULL
because the only do_setlink() call with ifname=NULL is done only when
`ifm->ifi_index == 0` so it looks like false positive.

[0]
https://lore.kernel.org/netdev/20210830094301.4f6ada72@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com/


-- 
Andrey Ignatov

  reply	other threads:[~2021-08-31  7:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30  9:04 [bug report] rtnetlink: Return correct error on changing device netns Dan Carpenter
2021-08-31  7:06 ` Andrey Ignatov [this message]
2021-08-31  9:03   ` Dan Carpenter

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=YS3U7SwGhXVTdI1g@rdna-mbp.dhcp.thefacebook.com \
    --to=rdna@fb.com \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    /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).