netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: ebiederm@xmission.com (Eric W. Biederman),
	Andrey Ignatov <rdna@fb.com>, <netdev@vger.kernel.org>,
	<davem@davemloft.net>, <kernel-team@fb.com>
Subject: Re: [PATCH net] rtnetlink: Return correct error on changing device netns
Date: Mon, 30 Aug 2021 09:43:01 -0700	[thread overview]
Message-ID: <20210830094301.4f6ada72@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> (raw)
In-Reply-To: <20210830075948.73fda029@hermes.local>

On Mon, 30 Aug 2021 07:59:48 -0700 Stephen Hemminger wrote:
> On Thu, 26 Aug 2021 11:15:22 -0500
> ebiederm@xmission.com (Eric W. Biederman) wrote:
> 
> > The analysis and the fix looks good to me.
> > 
> > The code calling do_setlink is inconsistent.  One caller of do_setlink
> > passes a NULL to indicate not name has been specified.  Other callers
> > pass a string of zero bytes to indicate no name has been specified.
> > 
> > I wonder if we might want to fix the callers to uniformly pass NULL,
> > instead of a string of length zero.
> > 
> > There is a slight chance this will trigger a regression somewhere
> > because we are changing the error code but this change looks easy enough
> > to revert in the unlikely event this breaks existing userspace.
> > 
> > Reviewed-by: "Eric W. Biederman" <ebiederm@xmission.com>  
> 
> This patch causes a new warning from Coverity:
> ________________________________________________________________________________________________________
> *** CID 1490867:  Null pointer dereferences  (FORWARD_NULL)
> /net/core/rtnetlink.c: 2701 in do_setlink()
> 2695     
> 2696     	/*
> 2697     	 * Interface selected by interface index but interface
> 2698     	 * name provided implies that a name change has been
> 2699     	 * requested.
> 2700     	 */
>  [...]  
> 2701     	if (ifm->ifi_index > 0 && ifname[0]) {
> 2702     		err = dev_change_name(dev, ifname);
> 2703     		if (err < 0)
> 2704     			goto errout;
> 2705     		status |= DO_SETLINK_MODIFIED;
> 2706     
> 
> Originally, the code was not accepting ifname == NULL and would
> crash. Somewhere along the way some new callers seem to have gotten
> confused.
> 
> What code is call do_setlink() with NULL as ifname, that should be fixed.

It's a false positive. There's only one caller with ifname=NULL:

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

Which has one caller, under this condition:

		if (ifm->ifi_index == 0 && tb[IFLA_GROUP])
			return rtnl_group_changelink(skb, net, ...

condition which excludes evaluating the check in question:

	if (ifm->ifi_index > 0 && ifname[0]) {
		err = dev_change_name(dev, ifname);

Proving ifm->ifi_index has to be 0 for ifname to be NULL.

      reply	other threads:[~2021-08-30 16:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26  0:25 [PATCH net] rtnetlink: Return correct error on changing device netns Andrey Ignatov
2021-08-26 11:10 ` patchwork-bot+netdevbpf
2021-08-26 16:15 ` Eric W. Biederman
2021-08-30 14:59   ` Stephen Hemminger
2021-08-30 16:43     ` Jakub Kicinski [this message]

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=20210830094301.4f6ada72@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=ebiederm@xmission.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=rdna@fb.com \
    --cc=stephen@networkplumber.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).