Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795021841; b=yFXoVm0g7JyZltf05ktkgiMFTm2dRPNq6d7VTevEYqmj4CnB41EBsDYmz3HC7yhhz9qU dRZCWG9Ue8Z6MxyhlKwnPxvtOqkkBx1/RCKz7qs1cqP6k6xmp9QN4z3O0Zd0XBvQb0TEP 4qdhKEixKNm+Qf4+gfPwtXzeBu5PoGowPbnw6W8bGp0I/8lrBYSCy+ITZlRlco+22bhFw QK4xgQifHajYsGY3wD/aJ+i5XOJTwEefJDlXbNBZoGUWF/byL8M0o+IpZpjGHWxyUwCm7 upknvQKv6mnuD4ynhGiMBvabuvTS/L6OzeXu44F3sJIYOC/NHoGHIrhdf/0qcf04j+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795021841; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Di2luzc0+HB1iqN8PsglmIynQa5b20K7hLWBgABLfvs=; b=kq6kL56iSjMfc/bLiHKzql9bFAtUWTpI1pa51sbchhUqAodd4YAz8a9vCmwf/eRK+0FS K5I2MgwTzlgyvJRdwpyUhLLg+5A5UIzM+xE9gF2brfeooJCTzv/KB0eM99bxvchgde68u ej5cKiWX7njGtBY83GGOfcgkanxWdEx9BLD3ceS2GxJO56avlSh/jzTz5BJK2XMez5gjj 4GJ9AUNAapD/PI4BlT8go5dFgvzm9CwSO5vHESlGNETZRM6IxzI5+fyf+5Jy6OFiESV3j wMeefryua42Xt/tzvyEDHnAQiA9DBd9Afumow5XKdwh4jR+tQAI4RJErf6wA8CLeh2Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EfhOq6X7; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D628606A320; Wed, 18 Nov 2026 17:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EfhOq6X7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 023A11F000C4; Wed, 18 Nov 2026 17:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795021841; bh=Di2luzc0+HB1iqN8PsglmIynQa5b20K7hLWBgABLfvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EfhOq6X7fJFXX7RHrOLXD2S//LFW5E2wJNGX9yES1hu7X6FNDV4GLBm3csLQYMGkn Z87DNmuuLjoRWu9bLCiC5udPI8gMLUCWtKuVmMiRJdu6TX+a7bZp3/hKZsmk5ysNsZ UZQJg9p/kPSX9RymyA4IMjahWLYFvE9NGlDwt+Lk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, co+eada64ce90ecebce@bugs.sh, Weiming Shi , Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 2409/2651] bpf: Validate stack arg reads against caller state Date: Wed, 18 Nov 2026 16:00:49 +0100 Message-ID: <20261118150412.039600328@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150247.972732815@linuxfoundation.org> References: <20261118150247.972732815@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Weiming Shi [ Upstream commit 90aedf8854c05713c02b381c41c59081b5cedbcc ] check_stack_arg_read() bounds a stack argument index with the callee's BTF-derived argument count, then uses the index in the caller's stack_arg_regs[] array. The array's actual logical length is recorded in caller->out_stack_arg_cnt, so the bound and indexed object can diverge. A crafted BPF_PROG_LOAD can use an argument mismatch to mark a static subprogram's BTF information unreliable. Later calls return from btf_check_subprog_call() before check_outgoing_stack_args(), while check_func_call() continues the static call on -EINVAL. The callee can then read a slot that the caller never allocated or initialized. The earlier commit 4286f5deee14 ("bpf: Validate outgoing stack args when btf_prepare_func_args fails") closed this hole for the first call, but not for later calls after the subprogram has been marked unreliable. Callbacks have a related problem. The verifier can make incoming stack arguments readable from outgoing slots at the helper call site. However, helpers and kfuncs invoke callbacks through an ABI that passes at most five arguments, so the runtime callback receives no stack arguments. Async callback verification can also reach check_stack_arg_read() without a caller frame. On x86-64, KASAN reports the direct-call out-of-bounds copy as: BUG: KASAN: slab-out-of-bounds in check_load_mem+0xb51/0xc60 Read of size 80 at addr ffff8881009af550 by task poc/131 Call Trace: check_stack_arg_read at kernel/bpf/verifier.c:4234 (inlined by) check_load_mem at kernel/bpf/verifier.c:6645 do_check_common at kernel/bpf/verifier.c:19568 bpf_check at kernel/bpf/verifier.c:21318 bpf_prog_load at kernel/bpf/syscall.c:3134 Reject callback subprograms with incoming stack arguments before their state is pushed. For direct calls, retrieve the slot with bpf_get_spilled_stack_arg(), which validates the index against the caller's out_stack_arg_cnt and rejects uninitialized slots before copying the register state. Fixes: 0f6bd5e7a804 ("bpf: Support stack arguments for bpf functions") Reported-by: Signed-off-by: Weiming Shi Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261026015250.1674676-1-bestswngs@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 46c21d90820c8..2ed356a03a57b 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -4278,7 +4278,12 @@ static int check_stack_arg_read(struct bpf_verifier_env *env, struct bpf_func_st } caller = vstate->frame[vstate->curframe - 1]; - arg = &caller->stack_arg_regs[spi]; + arg = bpf_get_spilled_stack_arg(spi, caller); + if (!arg) { + verbose(env, "invalid read from uninitialized stack arg off %d\n", off); + return -EACCES; + } + cur = vstate->frame[vstate->curframe]; bpf_diag_mod_begin(env, &cur->regs[dst_regno], arg, BPF_DIAG_MOD_WRITE); cur->regs[dst_regno] = *arg; @@ -10040,6 +10045,10 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *ins err = btf_check_subprog_call(env, subprog, caller->regs); if (err == -EFAULT) return err; + if (bpf_in_stack_arg_cnt(&env->subprog_info[subprog])) { + verbose(env, "callback subprog cannot have stack args\n"); + return -EINVAL; + } /* set_callee_state is used for direct subprog calls, but we are * interested in validating only BPF helpers that can call subprogs as -- 2.53.0