The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: zcliangcn@gmail.com
Cc: aconole@redhat.com, echaudro@redhat.com, i.maximets@ovn.org,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, pshelar@nicira.com,
	jesse@nicira.com, netdev@vger.kernel.org, dev@openvswitch.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] net: openvswitch: avoid hashing the network namespace pointer
Date: Sun, 22 Nov 2026 08:52:05 +0000	[thread overview]
Message-ID: <179533752531.3135.16631437077733586224@kernel.org> (raw)
In-Reply-To: <4e124b37fc972925a825881c50f95eb6b3c2e231.1794989369.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 replaces the pointer-derived seed in hash_bucket()
  (net/openvswitch/vport.c) with a seed computed only from…

--

net: openvswitch: avoid hashing the network namespace pointer

This patch changes the seed for the Open vSwitch vport name hash. It
used the struct net pointer and now uses a jhash_2words() of the
namespace cookie. The goal is to stop a timing side channel on vport
lookups from leaking the init_net pointer and the KASLR base.

> diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
> index 083f7a8d9d4e4..6689c8370ec13 100644
> --- a/net/openvswitch/vport.c
> +++ b/net/openvswitch/vport.c
> @@ -53,7 +53,10 @@ void ovs_vport_exit(void)
>  
>  static struct hlist_head *hash_bucket(const struct net *net, const char *name)
>  {
> -	unsigned int hash = jhash(name, strlen(name), (unsigned long) net);
> +	u32 seed = jhash_2words(lower_32_bits(net->net_cookie),
> +				upper_32_bits(net->net_cookie), 0);
> +	unsigned int hash = jhash(name, strlen(name), seed);

[Severity: Medium]

This fixes the pointer leak. Does it also make bucket placement in the
global dev_table fully predictable?

In setup_net() the cookie is just the namespace id:

net/core/net_namespace.c:setup_net() {
    ...
	net->net_cookie = to_ns_common(net)->ns_id;
    ...
}

For init_net, that id is the uAPI constant NET_NS_INIT_ID (7) from
include/uapi/linux/nsfs.h. For every other namespace,
__ns_tree_gen_id() hands out the next value of a global counter:

	ns->ns_id = atomic64_inc_return(&namespace_cookie);

Userspace can read its own cookie with getsockopt(SO_NETNS_COOKIE). It
can find other ids through nsfs (NS_GET_ID) or listns.

That makes the init_net seed jhash_2words(7, 0, 0) on every system. The
bucket for any (netns, name) pair can then be computed offline.

The lookup oracle described in the commit message is still there.
ovs_vport_locate() walks a bucket chain that all namespaces share:

	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))

OVS_VPORT_CMD_GET and OVS_DP_CMD_GET both have .flags = 0, so
unprivileged users can reach this lookup.

With a public seed, could an unprivileged user in a container learn
whether a vport or datapath name exists in init_net? The steps would be:

  - pick a missing name in its own namespace that lands in the same
    bucket as the candidate name
  - time a GET request on the missing name

Before this patch, that attack needed the kernel pointer of the victim
namespace.

A second case: OVS_VPORT_CMD_NEW and OVS_DP_CMD_NEW only need
GENL_UNS_ADMIN_PERM, which a user has inside its own user namespace.
Could an attacker create vports with names chosen to land in the
buckets that hold another namespace's vports? Name lookups for those
vports would then walk long strcmp chains. Only control-plane name
lookups would be affected, since the datapath fast path looks ports up
by port_no in dp->ports.

A secret per-netns random value already exists:

net/core/net_namespace.c:preinit_net() {
    ...
	net->hash_mix = get_random_u32();
    ...
}

Would using net_hash_mix(net) as the seed, or mixing the cookie with a
get_random_once() key, close the KASLR leak while keeping bucket
placement secret?

> +
>  	return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)];
>  }

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

      parent reply	other threads:[~2026-11-22  8:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  8:37 [PATCH net-next] net: openvswitch: avoid hashing the network namespace pointer Zhengchuan Liang
2026-11-18  8:49 ` Eric Dumazet
2026-11-18 11:02   ` Ilya Maximets
2026-11-22  8:52 ` 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=179533752531.3135.16631437077733586224@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=aconole@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dev@openvswitch.org \
    --cc=echaudro@redhat.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=i.maximets@ovn.org \
    --cc=jesse@nicira.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pshelar@nicira.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