From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796380429; b=YAefg7GDWfu6O42tYCu/wc6ByQT2C858q98SH/KvWYMWGAq/pVkfqkhOBPBt5HhFKE7c /TXR9y5+uZCtAMrYgsBV/0iGWtWvn7sEhsoxGntdlOMi8Gl7cvc5cwy2jYF4VCfp1l1+3 xpTMGp8UL5pCeYTDlLYgWth00ZCa0KPoG3Dk7kpyxKn/PzEV6EwaUdgdSx9KWmc34YYZk n7MuRpMjLfszqajiT2DSw8NsZOh23zTK8ErYXhbx+BoWjKjUxUk+aMNJVJ8J1ssM/wzQU Tbh160/3dn9RVUA8lM+M7tYiOs/BgFLlULmxhUZkKnpZRmQBYxufmOYHZLRpOKg9eNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380429; 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=bvGwsvQKgMz9T/WDj4xuJZHdasuppeNamN2t9rZy4S8=; b=BFhhnANGjHtSSxL3Iv2wcY6CgpeJaC5jHXSRCfMBBO/nzTVPC1zWUniQw6ARDS8E2fF4 oigp3UN6Sk1exbQlSwGT+HAEIKmbXL4tQbiN3ehJGTe3rKgqfidCLE4XvgLiDNTJ6eiWA /A4TruSbZhNDUjJBq8nbC2N/TmkGBoYYxVyiWnBIO3AUWsTgx1FJ3kzbi9lWkrLVeA8Kx e6q1gxXjHgqVYwfcQN9rvVn3OphP0ZpaARzbxNh8HPpJ9dMSsL4MCIx5Mkg4zh2VecdGM BBTjM5I4rDkR+Sttqb7WB4fG17HohJtdw8dRPyVcc6vWc08gFsRWw5OfawBZ5GqhzgA== 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=pbZ7RVGX; 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 9E698606A689; Fri, 4 Dec 2026 10:33:49 +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=pbZ7RVGX Received: by smtp.kernel.org (Postfix) with ESMTPSA id C85AF1F000C2; Fri, 4 Dec 2026 10:33:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380429; bh=bvGwsvQKgMz9T/WDj4xuJZHdasuppeNamN2t9rZy4S8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pbZ7RVGXhmAlF2F/aY1h0MXiMVomHR5UKOUZvPVaY/xvF/+/If0Gzn3tlmyYfRLrp L29uK+9YQJyyiqi7F7TaYLfkrMYvorYG0biMnQ38kCw7jn8hM9KqHSpUzJ4TNMRLVN ec1LQOqR/is5W/Rp+Trp/dt23nqYg7YDyJ9vhECk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Kumar Kartikeya Dwivedi , Sasha Levin Subject: [PATCH 7.3 229/742] bpf: Let the bpf_fastcall boundary cover the longest pattern Date: Fri, 4 Dec 2026 19:01:33 +0900 Message-ID: <20261204100641.157110102@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org 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: Alexei Starovoitov [ Upstream commit 95d366cb57752fb8821488676f607ebd0050fa9e ] A subprog can have bpf_fastcall patterns of different length: *(u64 *)(r10 - 8) = r2 *(u64 *)(r10 - 16) = r1 call bpf_get_smp_processor_id r1 = *(u64 *)(r10 - 16) r2 = *(u64 *)(r10 - 8) *(u64 *)(r10 - 16) = r1 call bpf_get_smp_processor_id r1 = *(u64 *)(r10 - 16) r0 = *(u64 *)(r10 - 8) For each pattern, take the offset just above its highest spill slot: 0 for the first pattern here, -8 for the second. Currently mark_fastcall_pattern_for_call() keeps the lowest of these offsets in fastcall_stack_off, the bpf_fastcall boundary of the subprog, which is -8 here. check_fastcall_stack_contract() looks only at accesses below the boundary, so the last load, at -8, does not switch the rewrite off. bpf_remove_fastcall_spills_fills() then removes all three pairs of a spill and a fill, and the load reads a slot that nothing wrote, while the verifier took it for a slot with the type of R2. Keep the highest of these offsets instead: every slot of every pattern is below it. Start from S16_MIN, the value that says that nothing is rewritten. Stop at 0, as min() did, because a pattern in code that never runs may end above the frame pointer. Fixes: 5b5f51bff1b6 ("bpf: no_caller_saved_registers attribute for helper calls") Signed-off-by: Alexei Starovoitov Signed-off-by: Kumar Kartikeya Dwivedi Link: https://patch.msgid.link/adbe7671c30f744adf6682d6431b9d818039cefb.1795462417.git.memxor@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 4bb0f362f44a8..8b80c25cd3695 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -18176,7 +18176,11 @@ static void mark_fastcall_pattern_for_call(struct bpf_verifier_env *env, env->insn_aux_data[insn_idx].fastcall_spills_num = i - 1; else subprog->keep_fastcall_stack = 1; - subprog->fastcall_stack_off = min(subprog->fastcall_stack_off, off); + /* + * The upper end of the longest pattern: no slot of a pattern is above it. Code that never + * runs may have a pattern that ends above the frame pointer. + */ + subprog->fastcall_stack_off = max(subprog->fastcall_stack_off, min_t(s16, off, 0)); } static int mark_fastcall_patterns(struct bpf_verifier_env *env) @@ -18187,6 +18191,7 @@ static int mark_fastcall_patterns(struct bpf_verifier_env *env) int s, i; for (s = 0; s < env->subprog_cnt; ++s, ++subprog) { + subprog->fastcall_stack_off = S16_MIN; /* find lowest stack spill offset used in this subprog */ lowest_off = 0; for (i = subprog->start; i < (subprog + 1)->start; ++i) { -- 2.53.0