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=1796384894; b=ci8FbFKvO+MxzA2TPMSZNj9jdg9ixlZKPQgPKD4twqMF1st0E1f+wYmNBwA5fOWXL1Sb qgSAXOpaIXkUsRDdgZAFCheiN2utUzUalzeqGF1dRKOqbRbrgnAKVDfyCMs89Ov5uggOw /TJoLY2lA9dyNpZZvLyV8qY/25+INVOUKTTzjJWHvM5sgcbGinv5d1OvyZssvbBHKcYuz Rev/1I7tzYjycigKURM2VqhGzo+c9zRXJAIEq3a5L33fOn9E8nq8FPvKuQBaa7s3CQPrl dzx9FsWdmyTMciccrgyUQZEXJRyT5eSxhNbwjbJ6q2yXYmEz4xYVwAyknZY+A89Q+jQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384894; 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=FDaGuLPJFUMxTrKTvEF5JdH9y/FrqCc3VAj5RrvIVXA=; b=cofSc9oUXldFReE1vndCNqz0rbTluDDvL4lBlGaPCU5dNLX8/sDBimBpdowPOVhkPdnp GmqlhkmqwMedY8r2TNdqOCvVZJX0/UAsC0H5aE/tM2fAghduRrCnh3u+Hf8Y7FK7/7lT+ FFxN/EgfHP6bdEiXY9XF/TNmGeUzt6w9ijZUlzZhavazEp2+XPwasNIY3mbPJnPelcULJ hPGeGjPRPZycJfijqCzu+IIQ7akyPFW0GjsnhqHfJzJ4FGWfIeg9VirdGAy7IpFqkFoZE zzlWqPlk6UBmITeCMALdE2CKNnYqmhF/aMXTNt9aCYaniCmcARXG94D7F1Pb8l9e6mg== 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=R6BmI3YY; 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 59931606A32C; Fri, 4 Dec 2026 11:48:14 +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=R6BmI3YY Received: by smtp.kernel.org (Postfix) with ESMTPSA id 999261F00939; Fri, 4 Dec 2026 11:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384894; bh=FDaGuLPJFUMxTrKTvEF5JdH9y/FrqCc3VAj5RrvIVXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=R6BmI3YYiytrNkG/nCQdMjKe9bqS784kID0Qxwx44hwuv0nBGZjCPQrjLifVY8t71 ZgbG8YIRfKD10RFEfUSDkumcARqhcnyTDD2kodJdCtuQUtMXXOxq238Ux2uxkl+Xlh P4kcff3t5B1FRwYa5T86U+sunDbI6T7RLId4e2tA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Puranjay Mohan , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.6 0339/1167] bpf: Look at frame 0 when telling async callback entries apart Date: Fri, 4 Dec 2026 18:56:06 +0900 Message-ID: <20261204100710.824531973@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Puranjay Mohan [ Upstream commit e55220162aae99622d9e80d4700e51c13a6f2a16 ] push_async_cb() sets in_async_callback_fn and async_entry_cnt on the callback's own frame, which is frame 0 of the fresh state it starts, and setup_func_entry() copies neither, so a subprog called by the callback carries neither. Two places read them from the innermost frame instead. is_state_visited() skips the infinite loop check when two states differ in async_entry_cnt, because seeing the same state on a second entry into an async callback is not a loop. A callback which re-arms itself and calls a subprog therefore compares the two entries at a loop inside that subprog, where the innermost frame is the subprog's and has no flag set, and the state is rejected: infinite loop detected at insn 60 push_callback_call() numbers a new entry as the caller's count plus one. When the callback re-arms itself from a subprog, the caller is that subprog's frame with a count of 0, so every entry is numbered 1, the check above never sees a difference, and a loop anywhere in such a callback is rejected the same way. Read the flag and the count from frame 0 in both places. A loop within a single entry still has a matching count and is still caught, and frame 0 of a non-async state does not have the flag set, so nothing else changes. The two other readers are already correct: check_return_code() reads frame[0], and the one in do_check() is reached only after an early return for curframe != 0. Fixes: bfc6bb74e4f1 ("bpf: Implement verifier support for validation of async callbacks.") Signed-off-by: Puranjay Mohan Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20260924162609.1746610-2-puranjay@kernel.org [ sashal: Applied the upstream three-line change to is_state_visited() in verifier.c, since the upstream states.c file doesn't exist in this tree. ] Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index cf54ebba430d8..5d28bd3ece833 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9512,7 +9512,7 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *ins if (!async_cb) return -EFAULT; callee = async_cb->frame[0]; - callee->async_entry_cnt = caller->async_entry_cnt + 1; + callee->async_entry_cnt = state->frame[0]->async_entry_cnt + 1; /* Convert bpf_timer_set_callback() args into timer callback args */ err = set_callee_state_cb(env, caller, callee, insn_idx); @@ -16995,10 +16995,10 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx) goto next; if (sl->state.branches) { - struct bpf_func_state *frame = sl->state.frame[sl->state.curframe]; + struct bpf_func_state *frame = sl->state.frame[0]; if (frame->in_async_callback_fn && - frame->async_entry_cnt != cur->frame[cur->curframe]->async_entry_cnt) { + frame->async_entry_cnt != cur->frame[0]->async_entry_cnt) { /* Different async_entry_cnt means that the verifier is * processing another entry into async callback. * Seeing the same state is not an indication of infinite -- 2.53.0