Re: [PATCH] bpf: Add network namespace boundary inspection kfuncs
From: Alexei Starovoitov
Date: Thu Nov 05 2026 - 11:47:23 EST
On Thu, Nov 05, 2026 at 04:16 AM Abhishek Khade <abhishekkhade69@xxxxxxxxx> wrote:
> Currently, dereferencing task->nsproxy->net_ns directly via BPF CO-RE
> presents safety and architectural challenges:
No. The prog does all of it today without new kfuncs:
inum = task->nsproxy->net_ns->ns.inum;
is_init_net = inum == NET_NS_INIT_INO;
The verifier accepts these loads in tp_btf, fentry and lsm progs.
A load that faults reads zero. It doesn't crash.
NET_NS_INIT_INO is uapi. No need for the address of init_net.
For a socket it's sk->__sk_common.skc_net.net->ns.inum.
Networking progs also have bpf_get_netns_cookie().
> + rcu_read_lock();
> + nsproxy = rcu_dereference(task->nsproxy);
> + if (nsproxy) {
> + net = READ_ONCE(nsproxy->net_ns);
> + if (net)
> + inum = net->ns.inum;
This is a use-after-free when task != current.
So much for 'this is safer than CO-RE' :(
pw-bot: cr