From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796455554; b=u8Bt0L7TiVO/pBgfCmIkxVfXS9ceuoRQ3v06YEHL5JKqXFw70iCsnQ1MX95Wz9s2lSsu P+W2STurMVlQ5H0JKgcD92NYFoELwTov1lSMIGpTVxclK6+fqHYX1bNXc3o13TZaYrq+L q6zJ+TZeq0xh2oGZGqtcH4O98hcZN59s8Kr8qFpCo/SkeLbbKl8VHshzsyWsje2SV/rHX ZSNo4aV5yI1Hhklxq6N7i755pOybuHnk/rYWKN01zCjxcnKtjeX+rvWpoQP1gMrrhsJh2 BeoSuh4MUlhP29CFxf2AqGHJYOoMtCHs9sNB6SKya9vxZnYUiJuHcefmCKNSGOwlmjw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796455554; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Mime-Version:Content-Transfer-Encoding:Content-Type:Date:Message-Id: Cc:Subject:From:To:X-Mailer:References:In-Reply-To; bh=1t8zlN9DhanBqRMKujWfa00I+X1zb6fKM2PylzvtgCU=; b=stUaOYEIBfOMjaU0MTpjHmTPT89q1kLhA2JyvsC4Ri34NiYkCTobtFy2zYWCifY5zAfL axz09tVzWSt0IxR6rC+C3XA//KGjrtKKDm5tp+IRs+FnwbWbfZgjmGz3BU2VQNpqr0kSi Cxk+CpIl54HPyOkiInYJtdkKKYWKgCwcFr9koun7azvunn3rf3gtRPaa9DddnbLAFTJIH wlk3295m6ypFXMqXR5HYp36ZXWpQpWClpFN9bWzwBq0ZxJ0Yss1DjONAHMosSLJv37Ibv vy4y2dWKV5P1UHc7z6jCi+pDsyGHSGjVDlb056w2e0i2cb0jUIzWA2iFwtTv9p9I+fQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xNCf8d8M; arc=none smtp.remote-ip=209.85.214.172 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14392606A322 for ; Sat, 5 Dec 2026 07:25:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 14392606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xNCf8d8M Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2f066274caeso10484795ad.2 for ; Fri, 04 Dec 2026 23:25:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796455553; x=1797060353; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=1t8zlN9DhanBqRMKujWfa00I+X1zb6fKM2PylzvtgCU=; b=xNCf8d8MtO8TUHXb8gDvZXQwDXIERePRgJYqhyv0tthfSMEDKxZ3yMwx/yFyk5qlRl 5JVBsa4mjs1MWAt1aSdjdIwmcaJmwpBxSwhN1lG57MS8IFO4tvaY9y2Gpg0ug99qVyvX /+W8Cir5JrkqyyCTkpnyUdO1WqkmsEjl6snhwIiKEYVZBCfHQCVBTbvzptZ8H3cg8vyp XmvwvxbE4Yh9FKL4rZdcjac1xgSnsPnw0y15r9gsTaK91A0cM8mdHMbt7BRu+PeWqmg+ o2LMYW5Teguq/RNE0ETljJCT1QonpGByH5DRVoVJgQO19R4BbVbYF5nz0NCFOz24G9tu bKAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796455553; x=1797060353; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:content-transfer-encoding:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1t8zlN9DhanBqRMKujWfa00I+X1zb6fKM2PylzvtgCU=; b=2x58OBHUGLgsOJvQV3TFCWQGPuAhI/lbhB8UoOxGStj7/NorAXCnIoIwedA1U8HDru TFUBEgt3nyj0IvKu/BbWuKOZ9twqLAUd1DMNvWEnN2KDxvO+hfawRjEJHfucPD46WaKX 9L1baHNFRkz+VaCMOqP7weQohDUWFKOTspK0ykvJxREeYEcVzEBEbgjLgQAD+O607bvz VXFcfcmVtc+H5gF4px0DnSPu/rNhlRjzetPxBzdy4Yo1CTwDY82MsPRWo1CrVYhTrgbK 9WnxETjFtOSJY7zB40zM+plCo7BCQ9cZIKwP2uBS8wsR0NkU0diwVGufrHhGCif68iec +8VQ== X-Forwarded-Encrypted: i=1; AL+hErGy2sUDl4kErZeDStPIRmRCR1zVPfhkdLI2Srpm0DgUMz/yMALnXbxYOVr7C0FxZ27IZYM=@vger.kernel.org X-Gm-Message-State: AB4q+uEYzkQ02pJy0/Qub7p/e3GvIhLVLXapXDJhaLOymolKOR8Uer1H ZFT7O3PHUUJ34AQtvrfeNjOfyK5unnSvlEdXswl6OZTBe6X8vD/EDcMf X-Gm-Gg: AZFdTZfzCSMncUNC51GiqngINTC+vxIUm2w8RibeL7YjdkINMo/eV6iTQgGGB0Wean4 VKNvhCtnsZ2PpN814kHcC6X+y2OhUoWlyb9vghuVCCjwSJLZGTUqKNDQOGSKlbXrJgnaN4wyDeJ 5AOCaAsbgZmHhAT5AxYZS9X/9jXAjupjAQ0uIVuTfob7UZ1RdfHZtYX4FxEaPI1mShqrzafpyyS /PJ1dRI2WKeRgZZ7CGcfigOlpo4g6nndUj/2lcxTTozaKEAu+Hj4ToueRSMLV4pIaYuAHVB2qmx hu80y8vbOLZEe4bdFBVUeaxWWBGjaXlz4Z8CwxUdT3H/zggh3ou0tW8sCPxbbLDDpOljpdoBary +/IEhqI4Nf5QPAvGKRvvLGi4Z/Cgc4HDHieXSn0KUKI/AiEtpgDWmPZj7WHKMOCb9MsC1cest99 nz/5hoSYJndVH3OQDgF2SQ8x0mEnBq3a/DHQYVBE94RiWZp2bM2dmIjeSDzrBb4xVUh4T82uJ5y XCPfDEXW7ME2azNcbY8IGpLf808uT6TD4QJdm9SHmkrnAQl1pMkGH0GqXhjy1CpVLJQ2XMLk3h0 VlCrPNaIpAzVJVeNgDXpQF+BavkK0XAQ6Rn4UAWX38P+7xW6DoalGxKPb6NIJntFbT0XOjT3Rny 7++rShsYz0SkJfaJ9h5nClg8CPriactBPig== X-Received: by 2002:a17:90b:4990:b0:3ac:a1c7:20fd with SMTP id 98e67ed59e1d1-3b5e05373c1mr3809615a91.4.1796455553294; Fri, 04 Dec 2026 23:25:53 -0800 (PST) Received: from localhost ([153.61.198.250]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5ddc73566sm7717909a91.17.2026.12.04.23.25.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 23:25:52 -0800 (PST) X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sat, 05 Dec 2026 07:25:52 +0000 Message-Id: Cc: , , , , , , , , , "Yuan Chen" Subject: Re: [PATCH bpf-next v7 1/2] bpf: Fix kfunc implicit arg inject type detection to prevent invalid pointer deref From: "Alexei Starovoitov" To: , X-Mailer: aerc 0.20.1-357-ga8fcb8d99360 References: <20261123055708.684107-1-chenyuan_fl@163.com> <20261123055708.684107-2-chenyuan_fl@163.com> In-Reply-To: <20261123055708.684107-2-chenyuan_fl@163.com> On Mon Nov 23, 2026 at 5:57 AM UTC, chenyuan_fl wrote: > From: Yuan Chen > > 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 the argument register 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_testmo= d] > #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 get_kfunc_arg_type() so that an implicit argument that was not > recognized by is_kfunc_arg_prog_aux() is rejected with -EFAULT instead of > silently skipped. The non-bpf_prog_aux implicit arguments handled by > bpf_fixup_kfunc_call() (obj_new, percpu_obj_new, obj_drop, > percpu_obj_drop, refcount_acquire, list_push, rbtree_add) are explicitly > allowed. > > All other KF_IMPLICIT_ARGS kfuncs take a struct bpf_prog_aux * argument, > which is matched by the preceding is_kfunc_arg_prog_aux() check and > injected through insn_aux_data.arg_prog, so they never reach the new > rejection path. > > Suggested-by: Eduard Zingerman > Acked-by: Eduard Zingerman > Fixes: 64e1360524b9 ("bpf: Verifier support for KF_IMPLICIT_ARGS") > Signed-off-by: Yuan Chen > --- > kernel/bpf/verifier.c | 20 +++++++++++++++++++- > 1 file changed, 19 insertions(+), 1 deletion(-) > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -14055,8 +14055,26 @@ get_kfunc_arg_type(struct bpf_verifier_env *env,= struct bpf_call_arg_meta *meta, > if (is_kfunc_arg_prog_aux(meta->btf, &args[arg])) > return ARG_PTR_TO_PROG_AUX; > =20 > - if (is_kfunc_arg_ignore(meta->btf, &args[arg]) || is_kfunc_arg_implicit= (meta, arg)) > + if (is_kfunc_arg_ignore(meta->btf, &args[arg])) > return ARG_IGNORE; > + > + if (is_kfunc_arg_implicit(meta, arg)) { > + /* > + * These kfuncs have non-prog_aux implicit arguments that > + * bpf_fixup_kfunc_call() patches up after verification. > + */ > + if (is_bpf_obj_new_kfunc(meta->func_id) || > + is_bpf_percpu_obj_new_kfunc(meta->func_id) || > + is_bpf_obj_drop_kfunc(meta->func_id) || > + is_bpf_percpu_obj_drop_kfunc(meta->func_id) || > + is_bpf_refcount_acquire_kfunc(meta->func_id) || > + is_bpf_list_push_kfunc(meta->func_id) || > + is_bpf_rbtree_add_kfunc(meta->func_id)) > + return ARG_IGNORE; > + verbose(env, "%s unrecognized implicit argument, possible BTF mismatch= \n", > + reg_arg_name(env, argno)); > + return -EFAULT; > + } Still needed? if so, rebase and resend pw-bot: cr