All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sechang Lim" <rhkrqnwk98@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf] bpf: fix NULL pointer dereference in bpf_task_from_vpid()
Date: Wed, 03 Jun 2026 20:56:31 +0000	[thread overview]
Message-ID: <20260603205631.951A81F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260603204206.773482-1-rhkrqnwk98@gmail.com>

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

Pre-existing issues:
- [High] The patch prevents a NULL pointer dereference in `bpf_task_from_vpid()`, but leaves the root vulnerability unpatched in `find_pid_ns()` and `find_task_by_vpid()`, exposing other callers like `trace_user_stack_print()` to the exact same crash.
- [High] `bpf_task_from_vpid()` uses `current` to determine the target PID namespace, which produces arbitrary, non-deterministic results when called from interrupt/network BPF programs.
--

commit 061d0db0a968fb39f30d4aaead03a668556d0e21
Author: Sechang Lim <rhkrqnwk98@gmail.com>

bpf: fix NULL pointer dereference in bpf_task_from_vpid()
    
bpf_task_from_vpid() looks up a task in the pid namespace of the current
task. This patch adds a check to bail out when current has no pid namespace
to avoid a NULL pointer dereference in find_pid_ns().

> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index b5314c9fed3cf..4646a915bf98c 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -2913,6 +2913,10 @@ __bpf_kfunc struct task_struct *bpf_task_from_vpid(s32 vpid)
>  	struct task_struct *p;
>  
>  	rcu_read_lock();
> +	if (!task_active_pid_ns(current)) {
> +		rcu_read_unlock();
> +		return NULL;
> +	}

[Severity: High]
This is a pre-existing issue, but while this patch prevents the crash in
bpf_task_from_vpid(), does it leave other callers of find_task_by_vpid()
vulnerable to the exact same NULL pointer dereference?

find_task_by_vpid() evaluates task_active_pid_ns(current) and passes the
result directly to find_pid_ns():

kernel/pid.c:find_pid_ns() {
        return idr_find(&ns->idr, nr);
}

If current has cleared its thread_pid during do_exit(), the namespace
pointer is NULL, and find_pid_ns() unconditionally dereferences it.

Other callers like trace_user_stack_print() in kernel/trace/trace_output.c
can still trigger this crash. For example, if the kernel oopses inside
do_exit() after detach_pid(), ftrace_dump_on_oops() can be invoked in a
panic context. If the trace buffer contains a user stack entry,
trace_user_stack_print() calls find_task_by_vpid(), potentially triggering
a recursive double-fault that prevents the panic log from flushing.

Would it be safer to add the NULL check directly inside find_pid_ns()
or find_task_by_vpid() instead?

[Severity: High]
This isn't a bug introduced by this patch, but does the use of current here
lead to arbitrary results for BPF programs running in interrupt context?

This kfunc is available for program types like cgroup_skb and xdp, which
can run in softirq or hardware interrupt context. In these contexts, current
points to whatever random task happened to be interrupted by the packet.

Since bpf_task_from_vpid() looks up the virtual PID relative to
task_active_pid_ns(current), won't passing the same vpid for the same
packet look up the PID in a completely random container or root namespace?

>  	p = find_task_by_vpid(vpid);
>  	if (p)
>  		p = bpf_task_acquire(p);

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

  reply	other threads:[~2026-06-03 20:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 20:42 [PATCH bpf] bpf: fix NULL pointer dereference in bpf_task_from_vpid() Sechang Lim
2026-06-03 20:56 ` sashiko-bot [this message]
2026-06-05 16:59 ` Yonghong Song
2026-06-05 19:00   ` Sechang Lim

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=20260603205631.951A81F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=rhkrqnwk98@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.