Skip to content

[26.04_linux-nvidia-7.3-next] NVIDIA: SAUCE: bpf: Reject unhandled implicit kfunc arguments - #717

Draft
nirmoy wants to merge 1 commit into
NVIDIA:26.04_linux-nvidia-7.3-nextfrom
nirmoy:codex/nvbug-7114748-bpf-v6
Draft

nirmoy wants to merge 1 commit into
NVIDIA:26.04_linux-nvidia-7.3-nextfrom
nirmoy:codex/nvbug-7114748-bpf-v6

Conversation

@nirmoy

@nirmoy nirmoy commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Backport the posted v6 fix to reject mismatched implicit kfunc arguments with -EFAULT at load time, preventing the Oops in NVBug 7114748.

Verified in an x86_64 VM. The input that crashed the baseline was rejected with v6, and the stock pahole 1.31 and 1.32 controls passed.

…revent invalid pointer deref

When a module kfunc declares an implicit struct bpf_prog_aux * argument,
the verifier must identify it so the kernel injects env->prog->aux into
the correct register at runtime.  The original check used
is_kfunc_arg_prog_aux() which calls btf_types_are_same() to compare the
module BTF type against vmlinux.

Root Cause

This issue was triggered by pahole 1.30 generating module BTF with
incorrect type information, which caused the kernel's distilled base
BTF deduplication for modules to fail.  As a result, the module retained
its own copy of struct bpf_prog_aux with a different BTF ID than
vmlinux's definition.  While pahole 1.31 fixed the BTF generation issue,
the kernel must be robust against such inconsistencies: a BTF mismatch
should result in a clean rejection, not a kernel crash or information
disclosure.

When the distilled base dedup fails and btf_types_are_same() cannot
match the module's bpf_prog_aux type against vmlinux's,
is_kfunc_arg_prog_aux() returned false and the code fell through
silently without setting arg_prog.  The kfunc then received whatever
value was in the argument register and dereferenced it as a
bpf_prog_aux pointer, leading to:

  BUG: kernel invalid pointer dereference, address: 00000000000009e2
  RIP: bpf_prog_get_assoc_struct_ops+0xa/0xc0
  RDI: 0x000000000000046d (stale register value)

In the observed crash the stale value was the process PID, causing a
dereference within the unmapped NULL page.  However, an attacker able
to control the register value -- for example by writing a BPF program
that explicitly sets R2 before calling a KF_IMPLICIT_ARGS kfunc --
could redirect the dereference to arbitrary kernel memory, turning
this into an information disclosure.  The fix ensures the verifier
either validates and injects the correct bpf_prog_aux pointer, or
rejects the program outright -- no silent fallthrough that could
be exploited.

Crash Stack Trace

  PID: 1133     TASK: ffff8881057d3900  CPU: 3    COMMAND: "test_progs"
   #0 machine_kexec at ffffffff812f6e26
   #1 __crash_kexec at ffffffff8145a788
   #2 crash_kexec at ffffffff8145ac24
   #3 oops_end at ffffffff812bb67c
   #4 page_fault_oops at ffffffff813053a1
   #5 exc_page_fault at ffffffff828e60a1
   #6 asm_exc_page_fault at ffffffff810012a6
      [exception RIP: bpf_prog_get_assoc_struct_ops+10]
      RIP: ffffffff815c024a  RSP: ffffc90001b57e48  RFLAGS: 00010283
      RAX: ffff8881057d3900  RBX: ffffc90001b57e68  RCX: ffff8881057d3900
      RDX: 0000607d4d1768b8  RSI: 000000000000046d  RDI: 000000000000046d
   #7 bpf_kfunc_multi_st_ops_test_1_assoc at ffffffffc0013a85 [bpf_testmod]
   #8 bpf_trace_run2 at ffffffff814f8332
   #9 __traceiter_sys_enter at ffffffff81415f45
  #10 trace_syscall_enter at ffffffff81416735
  #11 do_syscall_64 at ffffffff828e06a1

Fix

Split the combined is_kfunc_arg_ignore() || is_kfunc_arg_implicit()
check in check_kfunc_args() so that an implicit argument reaching
is_kfunc_arg_implicit() without being handled by a prior handler is
rejected with -EFAULT, instead of silently skipped.  Existing implicit
      args in bpf_fixup_kfunc_call() (obj_new, percpu_obj_new, obj_drop,
      percpu_obj_drop, refcount_acquire, list_push, rbtree_add) are
      explicitly allowed.

Suggested-by: Eduard Zingerman <[email protected]>
Fixes: 64e1360 ("bpf: Verifier support for KF_IMPLICIT_ARGS")
Signed-off-by: Yuan Chen <[email protected]>
(backported from https://lore.kernel.org/bpf/[email protected]/)
Signed-off-by: Nirmoy Das <[email protected]>
@nirmoy

nirmoy commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

BaseOS Kernel Review

Warning

⚠️ Review needs attention

BTF-local ID collisions can misclassify module kfuncs as vmlinux special kfuncs, bypass verification, and rewrite calls with an invalid implicit argument that may trigger a pointer dereference.

Findings: Critical 0 · High 1 · Medium 0 · Low 0

🔍 Review artifacts

📦 Build checks — 🔴 2/4 passed

Note

Build reports and debs are retained for 10 days after the PR closes.

  • 🟢 PR Illustrated: ready
Review metadata
  • Reviewed head: ef0a40348bc6
  • Overall status: attention needed
  • Build checks: 2/4 passed

This comment is maintained by BaseOS Reviewer and updated when the GitHub watcher publishes a newer review.

@github-actions

Copy link
Copy Markdown
Contributor

PR Validation Report

Patchscan ✅ No Missing Fixes

All cherry-picked commits checked — no missing upstream fixes found.

PR Lint ❌ Errors found

Details
Checking 1 commits...

Cherry-pick digest:
┌──────────────┬──────────────────────────────────────────────────────────────────┬────────────┬─────────┬───────────────────────────┐
│ Local        │ Referenced upstream / Patch subject                              │ Patch-ID   │ Subject │ SoB chain                 │
├──────────────┼──────────────────────────────────────────────────────────────────┼────────────┼─────────┼───────────────────────────┤
│ ef0a40348bc6 │ bpf: fix kfunc implicit arg inject type detection to prevent inv │ match      │ found   │ ok, backporter: nirmoyd   │
└──────────────┴──────────────────────────────────────────────────────────────────┴────────────┴─────────┴───────────────────────────┘

Lint: all checks passed.

PR metadata:
E: PR targets 26.04_linux-nvidia-7.3-next but body has no https://bugs.launchpad.net/... link

@jamieNguyenNVIDIA

Copy link
Copy Markdown
Collaborator

The Boro finding looks like a false positive. Module-owned kfunc IDs are above the vmlinux BTF ID range after relocation, and module kfunc registration rejects functions that resolve to vmlinux entries. A mismatch in the bpf_prog_aux parameter type therefore can’t make the module’s function ID match a vmlinux special kfunc ID.

Acked-by: Jamie Nguyen <[email protected]>

@nvmochs

nvmochs commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

I confirmed this fixes the issue on v7.3 and that the issue only shows up with pahole 1.32 (due to Pahole commit 4dce86c3c8d (https://github.com/acmel/dwarves/commit/4dce86c3c8d0dfa1ce78ae7a32cbd17c9d48f107), “Fix multi-dimensional array encoding,” changes flattened arrays into nested arrays).

Acked-by: Matthew R. Ochs <[email protected]>


@nirmoy It looks like this series stalled upstream. I wonder if we should ping on the ML (or privately?) if a v7 is planned.

@nirmoy

nirmoy commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

I confirmed this fixes the issue on v7.3 and that the issue only shows up with pahole 1.32 (due to Pahole commit 4dce86c3c8d (https://github.com/acmel/dwarves/commit/4dce86c3c8d0dfa1ce78ae7a32cbd17c9d48f107), “Fix multi-dimensional array encoding,” changes flattened arrays into nested arrays).

Acked-by: Matthew R. Ochs <[email protected]>

@nirmoy It looks like this series stalled upstream. I wonder if we should ping on the ML (or privately?) if a v7 is planned.

Ack, asked on the mainling list https://lore.kernel.org/all/[email protected]/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants