BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mahe Tardy" <mahe.tardy@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next] bpf: allow ksock kfuncs call from wq
Date: Tue, 13 Oct 2026 16:42:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-170139@kernel.org> (raw)
In-Reply-To: <20261013163101.205638-1-mahe.tardy@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] bpf: bpf_ksock_create causes NULL pointer deref on task exit
- [High] bpf: bpf_ksock_create in workqueue escapes network namespace
--

commit 34ed977b7943eebacf7e605dc8f26f2576ba2664
Author: Mahe Tardy <mahe.tardy@gmail.com>

bpf: allow ksock kfuncs call from wq

This commit relaxes the constraints on ksock kfuncs by removing the check
that ensures they are executed in a user task context. This change was
made to allow ksock kfuncs to be invoked from asynchronous workqueues,
bypassing the original LSM hook considerations.

> diff --git a/net/core/bpf_ksock.c b/net/core/bpf_ksock.c
> index e9943aeeadd32..21d5fd1eb403d 100644
> --- a/net/core/bpf_ksock.c
> +++ b/net/core/bpf_ksock.c
> @@ -73,16 +64,6 @@ bpf_ksock_create(const struct bpf_ksock_create_opts *opts, u32 opts__sz,
>  	struct bpf_ksock *ks;
>  	int err;
>  
> -	/*
> -	 * sock_create() derives the network namespace, credentials, and cgroup
> -	 * from current. Kernel threads, including BPF workqueue callbacks, do
> -	 * not carry the context of the task that invoked the BPF program.
> -	 */
> -	if (!bpf_ksock_has_user_task_context()) {
> -		err = -EOPNOTSUPP;
> -		goto err_out;
> -	}
> -

[Severity: High]
Does removing this check expose us to a NULL pointer dereference during task
exit?

If a sleepable BPF program running via task_work during do_exit() calls
bpf_ksock_create() after exit_nsproxy_namespaces() has cleared
current->nsproxy, it appears this could trigger a kernel panic.

Without the bpf_ksock_has_user_task_context() guard, bpf_ksock_create() will
now unconditionally call sock_create():

net/socket.c:sock_create() {
	return __sock_create(current->nsproxy->net_ns, family, type, protocol, res, 0);
}

Is it safe to allow sock_create() to dereference current->nsproxy here without
checking if it is NULL?

[Severity: High]
Additionally, does this change allow containerized workloads to escape their
network namespace?

When bpf_ksock_create() is invoked from a workqueue callback, the executing
context is a kthread.

Because sock_create() uses current->nsproxy->net_ns, a kthread will resolve
this to the host namespace (init_net), causing the socket to be created in the
host namespace rather than the container's netns.

Could this allow BPF programs inside containers to bypass container routing
and firewall policies by creating host-namespace sockets?

>  	if (!opts || opts__sz != sizeof(struct bpf_ksock_create_opts)) {
>  		err = -EINVAL;
>  		goto err_out;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013163101.205638-1-mahe.tardy@gmail.com?part=1

  reply	other threads:[~2026-10-13 16:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 16:31 [PATCH bpf-next] bpf: allow ksock kfuncs call from wq Mahe Tardy
2026-10-13 16:42 ` sashiko-bot [this message]
2026-10-13 17:10   ` Mahe Tardy

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=sashiko-outbox-170139@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=mahe.tardy@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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