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=1795020881; b=Xryjb9R7KvVE2ZXgjBe8wyTC2EKBVHYlHZuIKOvFpmKDoIuMDAdj2jWa5FAPyYKCGhJK WF7UhRstzVp65Ib8jFPdNJ0N6Hrh0uyy1PmScoSYHetSqIGatEA9yP9SnZYHljpmAQaUe zwP1Ryv7XpyksM4d+fCqZwcrwksJKWMeB4wbpYrUM5x7A0SHj6Oz+RTFvzTfJwj2sTCED 3n83FSW52Sw/pzmrKWwF+9zAkKg2Dei5smLU8x0P0t+rnrD3IcjGGhjxNuMQxT+I7wzWK WpxUr5TYCzEVjgN0PS1OH8oQIcfcPdseIbewri5j4auUSCQk4DvqddZtdufW8v7+kNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795020881; 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=1ZQyVfBRYxmftpVVrzN0OOXQbdYMNWI5DXT8KOTPDj8=; b=qvPcxfJ0qaAE/RootDnQP9iu/6D388HML/pKcah7zvQanb0ciCgJ78Kb55LHQJgcQVlg m/MGcm/3neIKdVJmLunc/CdeWclIgJc92dbBLuuGpOMiSOgUx+0NY6x25XWPIABXWEwvg YRQyn7PUmFQA9gLV8RiDezcwINaBJvy+EN4KARQ4DZV4DtHi/Qg37llTyo16ziEdJa3ER ZK8G1Q43UWqX+iwuurtScEU8duLo+BMs3/cI4c1XN9YhQZ1tfTjXxmpY6hlCLzQXociLf V2yA3Xnj3z8L/mM71VmmzDW95K2FcPkH00SrjVcGeGg1FVzSzl7HJ0KjSc/FGdIvfjA== 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=aiJBmZIF; 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 164DC606A325; Wed, 18 Nov 2026 16:54: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=aiJBmZIF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 692441F000C4; Wed, 18 Nov 2026 16:54:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795020880; bh=1ZQyVfBRYxmftpVVrzN0OOXQbdYMNWI5DXT8KOTPDj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aiJBmZIFPsm3RLER4p6jzWy3gYGqfoi7jVI7sOjR39seKFPB08MqxurD3vUc1YuJN Gjzu2I+ulkyLBRXTGSATX+epRF9Qy4AeTNp6ZaoBz713G9uYcRM6i1ggvxTTkb+7TH qjOTaPvgDQ70KMserYx2lPWfO/Fjan1qnkfTbQKk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josef Bacik , Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 2110/2651] bpf: Count sleepable callbacks as sleepable map users Date: Wed, 18 Nov 2026 15:55:50 +0100 Message-ID: <20261118150401.918535886@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: Josef Bacik [ Upstream commit 927c9c985f3ef4d30c086884b7e0ecb933f742ef ] map->sleepable_refcnt tells bpf_map_fd_put_ptr() whether an inner map that is taken out of its outer map has to wait for an RCU Tasks Trace grace period as well. It counts the sleepable programs that use the outer map. The bpf_wq or bpf_task_work callback of a program that is not sleepable runs under rcu_read_lock_trace() only, and is not counted. Such a callback can look an inner map up and keep it while user space deletes it from the outer map. The inner map is freed behind a plain RCU grace period, under the callback: BUG: KASAN: slab-use-after-free in array_map_update_elem+0x6bc/0x7d0 Count a program with such a callback. The maps are bound before the verifier meets the callback, so raise the count of those that are bound when it does. Fixes: 8e83da9732d9 ("bpf: add bpf_wq_start") Signed-off-by: Josef Bacik Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261017163745.3341787-24-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/core.c | 2 +- kernel/bpf/syscall.c | 2 +- kernel/bpf/verifier.c | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index b803819fce83c..593c0f2523114 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -3035,7 +3035,7 @@ void __bpf_free_used_maps(struct bpf_prog_aux *aux, bool sleepable; u32 i; - sleepable = aux->prog->sleepable; + sleepable = bpf_prog_runs_sleepable(aux->prog); for (i = 0; i < len; i++) { map = used_maps[i]; if (map->ops->map_poke_untrack) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 3a11d7233a3e4..ffd6802706d4f 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -6236,7 +6236,7 @@ static int bpf_prog_bind_map(union bpf_attr *attr) /* The bpf program will not access the bpf map, but for the sake of * simplicity, increase sleepable_refcnt for sleepable program as well. */ - if (prog->sleepable) + if (bpf_prog_runs_sleepable(prog)) atomic64_inc(&map->sleepable_refcnt); memcpy(used_maps_new, used_maps_old, sizeof(used_maps_old[0]) * prog->aux->used_map_cnt); diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 327b6d5025a43..8ddab1b7db904 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -537,6 +537,19 @@ static bool is_async_cb_sleepable(struct bpf_verifier_env *env, struct bpf_insn return false; } +/* From here on the maps of the program count it as a sleepable user. */ +static void mark_sleepable_async_cb(struct bpf_verifier_env *env) +{ + int i; + + if (bpf_prog_runs_sleepable(env->prog)) + return; + + env->prog->aux->sleepable_async_cb = true; + for (i = 0; i < env->used_map_cnt; i++) + atomic64_inc(&env->used_maps[i]->sleepable_refcnt); +} + bool bpf_is_may_goto_insn(struct bpf_insn *insn) { return insn->code == (BPF_JMP | BPF_JCOND) && insn->src_reg == BPF_MAY_GOTO; @@ -9954,7 +9967,7 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *ins if (IS_ERR(async_cb)) return PTR_ERR(async_cb); if (is_async_cb_sleepable(env, insn)) - env->prog->aux->sleepable_async_cb = true; + mark_sleepable_async_cb(env); callee = async_cb->frame[0]; callee->async_entry_cnt = state->frame[0]->async_entry_cnt + 1; @@ -19074,7 +19087,7 @@ static int __add_used_map(struct bpf_verifier_env *env, struct bpf_map *map) if (err) return err; - if (env->prog->sleepable) + if (bpf_prog_runs_sleepable(env->prog)) atomic64_inc(&map->sleepable_refcnt); /* hold the map. If the program is rejected by verifier, -- 2.53.0