mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: zcliangcn@gmail.com
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v2] net: avoid hashing the namespace pointer for device names
Date: Sun, 22 Nov 2026 06:43:48 +0000	[thread overview]
Message-ID: <179532982886.3135.5724232196629661925@kernel.org> (raw)
In-Reply-To: <c9b3c1a0e3410ffa70db448e2299ed420528b5ff.1794981913.git.zcliangcn@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The patch fixes only dev_name_hash().

--

net: avoid hashing the namespace pointer for device names

This commit changes dev_name_hash() to call full_name_hash() with no salt,
where it used to salt with the struct net pointer. The goal is to stop
unprivileged users from recovering init_net and the kernel text base by
timing name lookups that collide in the hash table.

> diff --git a/net/core/dev.c b/net/core/dev.c
> index d88af07aea290..12100fbf9022a 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -195,7 +195,7 @@ static inline void dev_base_seq_inc(struct net *net)
>  
>  static inline struct hlist_head *dev_name_hash(struct net *net, const char *name)
>  {
> -	unsigned int hash = full_name_hash(net, name, strnlen(name, IFNAMSIZ));
> +	unsigned int hash = full_name_hash(NULL, name, strnlen(name, IFNAMSIZ));
>  
>  	return &net->dev_name_head[hash_32(hash, NETDEV_HASHBITS)];
>  }

[Severity: Medium]
This fixes dev_name_hash(). Is there still a similar name hash in Open
vSwitch that uses the struct net pointer as its seed?

net/openvswitch/vport.c:hash_bucket() {
	unsigned int hash = jhash(name, strlen(name), (unsigned long) net);
	return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)];
}

jhash() takes a u32 initval, so the seed is the low 32 bits of the net
pointer. On x86-64 those low bits contain the KASLR slide of init_net.

ovs_vport_locate() then walks the bucket with strcmp() and net_eq(). The
lookup time therefore depends on whether a probe name shares a bucket with
a resident vport:

net/openvswitch/vport.c:ovs_vport_locate() {
	struct hlist_head *bucket = hash_bucket(net, name);
	...
	hlist_for_each_entry_rcu(vport, bucket, hash_node,
				 lockdep_ovsl_is_held())
		if (!strcmp(name, ovs_vport_name(vport)) &&
		    net_eq(ovs_dp_get_net(vport->dp), net))
			return vport;
	...
}

Unprivileged users can reach this lookup with a name they choose, since
both commands use .flags = 0:

  OVS_VPORT_CMD_GET -> lookup_vport() -> ovs_vport_locate()
  OVS_DP_CMD_GET -> lookup_datapath() -> ovs_vport_locate()

Take a host with OVS vports in init_net, such as ovs-system or br-int.
Could the collision-timing method in the commit message still recover
init_net through this path? It has not been shown that one extra strcmp()
can be measured through genetlink, which adds more timing noise.

A grep of net/ suggests this is the only hash left that uses the net
pointer as its seed. The commit message doesn't mention it.

dev_table is one global table of VPORT_HASH_BUCKETS buckets, shared by
every namespace. Would it need a random seed instead of NULL? Options
include get_random_u32() in ovs_vport_init() or net_hash_mix(). This
could be done as a separate follow-up.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/c9b3c1a0e3410ffa70db448e2299ed420528b5ff.1794981913.git.zcliangcn%40gmail.com

      parent reply	other threads:[~2026-11-22  6:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  6:26 Zhengchuan Liang
2026-11-18  8:35 ` Eric Dumazet
2026-11-22  6:43 ` netdev-bot+sashiko [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=179532982886.3135.5724232196629661925@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=zcliangcn@gmail.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

all inboxes | Powered by JetHome®