Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 6.12.y v2] bpf: Reject NULL data/sig in bpf_verify_pkcs7_signature
@ 2026-11-19 16:55 Yingke Xiao
  0 siblings, 0 replies; 3+ messages in thread
From: Yingke Xiao @ 2026-11-19 16:55 UTC (permalink / raw)
  To: stable; +Cc: bpf, kpsingh, sashal

[ Upstream commit 49b18315be4e590fae0fc39c87d46c87e9ec903c ]

bpf_verify_pkcs7_signature() passes the return values of
__bpf_dynptr_data(data_ptr, data_len) and __bpf_dynptr_data(sig_ptr, sig_len)
directly to verify_pkcs7_signature() without checking for NULL. If an
empty/null dynptr or non-linear skb/xdp dynptr is passed, __bpf_dynptr_data()
returns NULL, leading to a NULL pointer dereference in verify_pkcs7_signature().

Check for NULL and return -EINVAL.

[ In 6.12.y, bpf_verify_pkcs7_signature() is located in
  kernel/trace/bpf_trace.c instead of kernel/bpf/helpers.c. Adapt upstream
  commit 49b18315be4e to kernel/trace/bpf_trace.c. ]

Fixes: 9b2d3e911295 ("bpf: Add bpf_verify_pkcs7_signature kfunc")
Signed-off-by: KP Singh <kpsingh@kernel.org>
Signed-off-by: Yingke Xiao <inkxiao12@gmail.com>
---
v1 -> v2:
  - Fix diff formatting and line wrapping in patch body.

 kernel/trace/bpf_trace.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index bac2db7..41e237d 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1384,8 +1384,13 @@ __bpf_kfunc int
bpf_verify_pkcs7_signature(struct bpf_dynptr *data_p,

  data_len = __bpf_dynptr_size(data_ptr);
  data = __bpf_dynptr_data(data_ptr, data_len);
+ if (!data)
+ return -EINVAL;
+
  sig_len = __bpf_dynptr_size(sig_ptr);
  sig = __bpf_dynptr_data(sig_ptr, sig_len);
+ if (!sig)
+ return -EINVAL;

  return verify_pkcs7_signature(data, data_len, sig, sig_len,
       trusted_keyring->key,
-- 
2.56.1

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

* [PATCH 6.12.y v2] bpf: Reject NULL data/sig in bpf_verify_pkcs7_signature
@ 2026-11-19 17:17 Yingke Xiao
  2026-11-20 20:39 ` Sasha Levin
  0 siblings, 1 reply; 3+ messages in thread
From: Yingke Xiao @ 2026-11-19 17:17 UTC (permalink / raw)
  To: stable; +Cc: sashal, kpsingh

[ Upstream commit 49b18315be4e590fae0fc39c87d46c87e9ec903c ]

bpf_verify_pkcs7_signature() passes the return values of
__bpf_dynptr_data(data_ptr, data_len) and __bpf_dynptr_data(sig_ptr, sig_len)
directly to verify_pkcs7_signature() without checking for NULL. If an
empty/null dynptr or non-linear skb/xdp dynptr is passed, __bpf_dynptr_data()
returns NULL, leading to a NULL pointer dereference in verify_pkcs7_signature().

Check for NULL and return -EINVAL.

[ In 6.12.y, bpf_verify_pkcs7_signature() is located in
  kernel/trace/bpf_trace.c instead of kernel/bpf/helpers.c. Adapt upstream
  commit 49b18315be4e to kernel/trace/bpf_trace.c. ]

Fixes: 9b2d3e911295 ("bpf: Add bpf_verify_pkcs7_signature kfunc")
Signed-off-by: KP Singh <kpsingh@kernel.org>
Signed-off-by: Yingke Xiao <inkxiao12@gmail.com>
---
v1 -> v2:
  - Fix diff formatting and line wrapping in patch body.

 kernel/trace/bpf_trace.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index bac2db7..41e237d 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1384,8 +1384,13 @@ __bpf_kfunc int
bpf_verify_pkcs7_signature(struct bpf_dynptr *data_p,

  data_len = __bpf_dynptr_size(data_ptr);
  data = __bpf_dynptr_data(data_ptr, data_len);
+ if (!data)
+ return -EINVAL;
+
  sig_len = __bpf_dynptr_size(sig_ptr);
  sig = __bpf_dynptr_data(sig_ptr, sig_len);
+ if (!sig)
+ return -EINVAL;

  return verify_pkcs7_signature(data, data_len, sig, sig_len,
       trusted_keyring->key,
-- 
2.56.1

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

* Re: [PATCH 6.12.y v2] bpf: Reject NULL data/sig in bpf_verify_pkcs7_signature
  2026-11-19 17:17 [PATCH 6.12.y v2] bpf: Reject NULL data/sig in bpf_verify_pkcs7_signature Yingke Xiao
@ 2026-11-20 20:39 ` Sasha Levin
  0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2026-11-20 20:39 UTC (permalink / raw)
  To: stable; +Cc: Sasha Levin, kpsingh, Yingke Xiao

> [ Upstream commit 49b18315be4e590fae0fc39c87d46c87e9ec903c ]

This one doesn't apply: the patch is whitespace-damaged (tabs turned into
spaces, the hunk header wrapped), and git apply stops with "corrupt patch at
line 13".

A few other things to fix in a v3:

 - 49b18315be4e590fae0fc39c87d46c87e9ec903c is not a commit. The upstream
   commit is 49b18315be4eecfc36b75f4aecb4d40a87d68a20.
 - The Fixes: tag should be 865b0566d8f1 ("bpf: Add
   bpf_verify_pkcs7_signature() kfunc").
 - Please keep the upstream commit message and trailers, and add a
   "From: KP Singh <kpsingh@kernel.org>" line so authorship is kept.
 - The selftest hunk in kfunc_dynptr_param.c is missing; without it 6.12's
   own selftest fails.

Please send v3 with git send-email.

-- 
Thanks,
Sasha

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

end of thread, other threads:[~2026-11-20 20:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 17:17 [PATCH 6.12.y v2] bpf: Reject NULL data/sig in bpf_verify_pkcs7_signature Yingke Xiao
2026-11-20 20:39 ` Sasha Levin
  -- strict thread matches above, loose matches on Subject: below --
2026-11-19 16:55 Yingke Xiao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox