The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH net-next] net: openvswitch: avoid hashing the network namespace pointer
@ 2026-11-18  8:37 Zhengchuan Liang
  2026-11-18  8:49 ` Eric Dumazet
  2026-11-22  8:52 ` netdev-bot+sashiko
  0 siblings, 2 replies; 4+ messages in thread
From: Zhengchuan Liang @ 2026-11-18  8:37 UTC (permalink / raw)
  To: Aaron Conole
  Cc: Eelco Chaudron, Ilya Maximets, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Pravin B Shelar,
	Jesse Gross, netdev, dev, linux-kernel, Zhengchuan Liang

The Open vSwitch vport name table uses the network namespace pointer as
the Jenkins hash seed. When an Open vSwitch vport already exists in the
attacker's network namespace, unprivileged OVS_VPORT_CMD_GET requests can
look up attacker-chosen missing names and time whether those lookups
traverse an occupied bucket. Ranking the resulting collision pattern
across possible KASLR slides recovers the init_net pointer and thus the
kernel text base.

Use the namespace cookie instead. It is a stable, unique, non-address
identifier that is deliberately exposed to userspace. setup_net() assigns
it before per-net initializers run, and it remains unchanged for the
namespace lifetime. Fold both halves into the seed so vports in different
namespaces retain namespace-dependent bucket placement.

Found by AI-assisted code review and reproduced on an unmodified kernel
without fault injection. After privileged setup created the resident
vport, the timing measurements ran as an unprivileged user with no
effective capabilities. With this change, the pointer-derived prediction
fails. Existing and missing vport lookups behave as expected. Identically
named vports in separate network namespaces remain independent.

Fixes: 46df7b814548 ("openvswitch: Add support for network namespaces.")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Zhengchuan Liang <zcliangcn@gmail.com>
---
 net/openvswitch/vport.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 083f7a8d9d4e..6689c8370ec1 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);
+
 	return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)];
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] net: openvswitch: avoid hashing the network namespace pointer
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2026-11-18  8:49 UTC (permalink / raw)
  To: Zhengchuan Liang
  Cc: Aaron Conole, Eelco Chaudron, Ilya Maximets, David S . Miller,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Pravin B Shelar,
	Jesse Gross, netdev, dev, linux-kernel

Le mer. 18 nov. 2026 à 09:40, Zhengchuan Liang <zcliangcn@gmail.com> a écrit :
>
> The Open vSwitch vport name table uses the network namespace pointer as
> the Jenkins hash seed. When an Open vSwitch vport already exists in the
> attacker's network namespace, unprivileged OVS_VPORT_CMD_GET requests can
> look up attacker-chosen missing names and time whether those lookups
> traverse an occupied bucket. Ranking the resulting collision pattern
> across possible KASLR slides recovers the init_net pointer and thus the
> kernel text base.
>
> Use the namespace cookie instead. It is a stable, unique, non-address
> identifier that is deliberately exposed to userspace. setup_net() assigns
> it before per-net initializers run, and it remains unchanged for the
> namespace lifetime. Fold both halves into the seed so vports in different
> namespaces retain namespace-dependent bucket placement.
>
> Found by AI-assisted code review and reproduced on an unmodified kernel
> without fault injection. After privileged setup created the resident
> vport, the timing measurements ran as an unprivileged user with no
> effective capabilities. With this change, the pointer-derived prediction
> fails. Existing and missing vport lookups behave as expected. Identically
> named vports in separate network namespaces remain independent.
>
> Fixes: 46df7b814548 ("openvswitch: Add support for network namespaces.")
> Cc: stable@vger.kernel.org

Same remark as for your dev_name_hash() patch: local KASLR attacks are
not a serious concern, a "Cc: stable" tag does not belong in a
net-next patch.

> Assisted-by: LLM
> Signed-off-by: Zhengchuan Liang <zcliangcn@gmail.com>
> ---
>  net/openvswitch/vport.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
> index 083f7a8d9d4e..6689c8370ec1 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);

Nit: hash_64(net->net_cookie, 32) would be simpler.

Reviewed-by: Eric Dumazet <edumazet@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] net: openvswitch: avoid hashing the network namespace pointer
  2026-11-18  8:49 ` Eric Dumazet
@ 2026-11-18 11:02   ` Ilya Maximets
  0 siblings, 0 replies; 4+ messages in thread
From: Ilya Maximets @ 2026-11-18 11:02 UTC (permalink / raw)
  To: Eric Dumazet, Zhengchuan Liang
  Cc: Aaron Conole, Eelco Chaudron, Ilya Maximets, David S . Miller,
	Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, dev,
	linux-kernel

On 11/18/26 9:49 AM, Eric Dumazet wrote:
> Le mer. 18 nov. 2026 à 09:40, Zhengchuan Liang <zcliangcn@gmail.com> a écrit :
>>
>> The Open vSwitch vport name table uses the network namespace pointer as
>> the Jenkins hash seed. When an Open vSwitch vport already exists in the
>> attacker's network namespace, unprivileged OVS_VPORT_CMD_GET requests can
>> look up attacker-chosen missing names and time whether those lookups
>> traverse an occupied bucket. Ranking the resulting collision pattern
>> across possible KASLR slides recovers the init_net pointer and thus the
>> kernel text base.
>>
>> Use the namespace cookie instead. It is a stable, unique, non-address
>> identifier that is deliberately exposed to userspace. setup_net() assigns
>> it before per-net initializers run, and it remains unchanged for the
>> namespace lifetime. Fold both halves into the seed so vports in different
>> namespaces retain namespace-dependent bucket placement.
>>
>> Found by AI-assisted code review and reproduced on an unmodified kernel
>> without fault injection. After privileged setup created the resident
>> vport, the timing measurements ran as an unprivileged user with no
>> effective capabilities. With this change, the pointer-derived prediction
>> fails. Existing and missing vport lookups behave as expected. Identically
>> named vports in separate network namespaces remain independent.
>>
>> Fixes: 46df7b814548 ("openvswitch: Add support for network namespaces.")
>> Cc: stable@vger.kernel.org
> 
> Same remark as for your dev_name_hash() patch: local KASLR attacks are
> not a serious concern, a "Cc: stable" tag does not belong in a
> net-next patch.
> 
>> Assisted-by: LLM
>> Signed-off-by: Zhengchuan Liang <zcliangcn@gmail.com>
>> ---
>>  net/openvswitch/vport.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
>> index 083f7a8d9d4e..6689c8370ec1 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);
> 
> Nit: hash_64(net->net_cookie, 32) would be simpler.

I agree.  Also, both jhash* and hash_64 actually return u32, so we should
probably swap the type of the local 'hash' variable here as well.  Having
a mix of u32 and unsigned int for the values of the same nature within the
same function is not the greatest.

Otherwise, the change looks fine to me.

Best regards, Ilya Maximets.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] net: openvswitch: avoid hashing the network namespace pointer
  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-22  8:52 ` netdev-bot+sashiko
  1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-22  8:52 UTC (permalink / raw)
  To: zcliangcn
  Cc: aconole, echaudro, i.maximets, davem, edumazet, kuba, pabeni,
	horms, pshelar, jesse, netdev, dev, linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-22  8:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox