From: sashiko-bot@kernel.org
To: "Syeda Mahnur Asif" <s.mahnur.a@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2] bpf: Fix NULL pointer dereference in bpf_sock_from_file
Date: Thu, 20 Aug 2026 15:44:06 +0000 [thread overview]
Message-ID: <20260820154407.4269F1F00ADF@smtp.kernel.org> (raw)
In-Reply-To: <20260820152532.621639-1-s.mahnur.a@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Incomplete validation allows ERR_PTR to cause kernel panic in bpf_sock_from_file.
- [High] Missing NULL pointer checks in BPF helpers taking ARG_PTR_TO_BTF_ID lead to kernel panics.
--
--- Patch [1]: [PATCH bpf v2] bpf: Fix NULL pointer dereference in bpf_sock_from_file ---
commit a54db842fd2086671fb2b904beab51f691e8cc8b
Author: Syeda Mahnur Asif <s.mahnur.a@gmail.com>
bpf: Fix NULL pointer dereference in bpf_sock_from_file
Adds a NULL check to bpf_sock_from_file to prevent kernel panics when
fentry/fexit programs pass a NULL file pointer.
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 16845987b2449..7c3caae4bafc3 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -12182,7 +12182,10 @@ const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = {
>
> BPF_CALL_1(bpf_sock_from_file, struct file *, file)
> {
> - return (unsigned long)sock_from_file(file);
> + if (file)
> + return (unsigned long)sock_from_file(file);
[Severity: High]
This isn't a bug introduced by this patch, but does this check adequately
handle error pointers?
If an eBPF fexit program attaches to a kernel function returning a
struct file pointer that fails (e.g., returning ERR_PTR(-ENOENT)), the BPF
verifier treats this as a valid PTR_TO_BTF_ID.
Since an error pointer is not NULL, this condition will pass, and
sock_from_file() will attempt to dereference it, leading to a crash.
Could we use IS_ERR_OR_NULL(file) instead to catch these cases as well?
Also, while not introduced by this patch, are there similar missing NULL
pointer checks in other BPF helpers taking ARG_PTR_TO_BTF_ID?
When fentry/fexit programs pass context arguments, the verifier lacks BTF
nullability annotations for most parameters. This means helpers can receive
and blindly dereference NULL pointers.
For instance, bpf_task_pt_regs() directly dereferences the task without
checking:
kernel/trace/bpf_trace.c:bpf_task_pt_regs() {
return (unsigned long) task_pt_regs(task);
}
Similarly, __bpf_get_task_stack() calls try_get_task_stack() which will
dereference the task:
kernel/bpf/stackmap.c:__bpf_get_task_stack() {
if (!try_get_task_stack(task))
return -EFAULT;
}
And bpf_xdp_get_buff_len() accesses the xdp buffer directly:
net/core/filter.c:bpf_xdp_get_buff_len() {
return xdp_get_buff_len(xdp);
}
Do these helpers need similar runtime validation to prevent panics in the
same execution context?
> +
> + return (unsigned long)NULL;
> }
>
> BTF_ID_LIST(bpf_sock_from_file_btf_ids)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260820152532.621639-1-s.mahnur.a@gmail.com?part=1
prev parent reply other threads:[~2026-08-20 15:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 15:25 [PATCH bpf v2] bpf: Fix NULL pointer dereference in bpf_sock_from_file Syeda Mahnur Asif
2026-08-20 15:44 ` sashiko-bot [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=20260820154407.4269F1F00ADF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=s.mahnur.a@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.