netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	daniel@iogearbox.net, opurdila@ixiacom.com
Subject: Re: [PATCH net 1/5] net: fix ifname in netlink ntf during netns move
Date: Mon, 16 Oct 2023 13:21:23 -0700	[thread overview]
Message-ID: <20231016132123.50094c45@kernel.org> (raw)
In-Reply-To: <20231016201657.1754763-2-kuba@kernel.org>

On Mon, 16 Oct 2023 13:16:53 -0700 Jakub Kicinski wrote:
> +static int dev_prep_valid_name(struct net *net, struct net_device *dev,
> +			       const char *want_name, char *out_name)

> +	if (strchr(want_name, '%')) {
> +		ret = __dev_alloc_name(net, want_name, out_name);
> +		return ret < 0 ? ret : 0;

> -	if (strchr(name, '%'))
> -		return dev_alloc_name_ns(net, dev, name);
> -	else if (netdev_name_in_use(net, name))
> -		return -EEXIST;
> -	else if (dev->name != name)
> -		strscpy(dev->name, name, IFNAMSIZ);
> -
> -	return 0;
> +	return dev_prep_valid_name(net, dev, name, dev->name);

Humpf, this is not right. IDK what magic seeing something on the ML
has but I looked at this 3 times, and the moment I see it on the list
I immediately realize that the dev_alloc_name_ns() -> __dev_alloc_name()
conversion here is not really exact. We need to go thru a temp buffer
like dev_alloc_name_ns() does, because for whatever reason
__dev_alloc_name_ns() uses its input argument as a scratch buffer.
So if we pass dev->name directly and it fails the name will be
scrambled.
-- 
pw-bot: cr

  reply	other threads:[~2023-10-16 20:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-16 20:16 [PATCH net 0/5] net: fix bugs in device netns-move and rename Jakub Kicinski
2023-10-16 20:16 ` [PATCH net 1/5] net: fix ifname in netlink ntf during netns move Jakub Kicinski
2023-10-16 20:21   ` Jakub Kicinski [this message]
2023-10-16 20:16 ` [PATCH net 2/5] net: check for altname conflicts when changing netdev's netns Jakub Kicinski
2023-10-17  7:21   ` Jiri Pirko
2023-10-16 20:16 ` [PATCH net 3/5] net: avoid UAF on deleted altname Jakub Kicinski
2023-10-17  7:51   ` Jiri Pirko
2023-10-17 14:52     ` Jakub Kicinski
2023-10-17 16:10       ` Jiri Pirko
2023-10-17 16:35         ` Jiri Pirko
2023-10-17 18:07           ` Jakub Kicinski
2023-10-16 20:16 ` [PATCH net 4/5] net: move altnames together with the netdevice Jakub Kicinski
2023-10-17  7:51   ` Jiri Pirko
2023-10-16 20:16 ` [PATCH net 5/5] selftests: net: add very basic test for netdev names and namespaces Jakub Kicinski
2023-10-17 11:25   ` Przemek Kitszel
2023-10-17 14:58     ` Jakub Kicinski

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=20231016132123.50094c45@kernel.org \
    --to=kuba@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=opurdila@ixiacom.com \
    --cc=pabeni@redhat.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).