From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78A0572624; Mon, 23 Jun 2025 21:53:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715594; cv=none; b=LJh37HxzzLqL3VmcDjHk+hqElDRZLt7UsYop4sAdNPYINTxcQwIph9fd4IqbkMHhPKy0gxFZ4e8vt27c6vsoNUG3dojlijvdWO6o2ZLdDbCGoRQ8HhWg2+DTcJDm2Tkzuu5U/eF4gNYolR801iIibWNbPVA1KFT2AaGYmfyuMnM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715594; c=relaxed/simple; bh=14nm5H3nhTnBLFk33o0mg222+asTlknC1cz/VNtmWuU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EUV1JbnS3z3oGLt8JbbFz6PtbqPdgq+KFY5NuDeACOy+BvoFKD2H7p0rVOR8uG8ySU3qy3mITv+7v9AW0XxMZnMf20DuI8AtXtMw34oOGKLOkPGjJj58t9kmQoxDuBofsd14YgWbHMU2ChdYAIixIr7MScDkQ1i81tYhEvxjb/g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MgcDoRta; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MgcDoRta" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10D49C4CEEA; Mon, 23 Jun 2025 21:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750715594; bh=14nm5H3nhTnBLFk33o0mg222+asTlknC1cz/VNtmWuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MgcDoRtamNSh6EgyCcuW/pIKIBxwm9Oqoc7vBAUM1RP3kiLtTseVSr1KAHHLhe8NV JZg6+yD2+s9MxVSIC91A9ytXVl7of/dW87rHFher+6q+cHsOlNjkjZT8xOELwJGWAw 6M4KktdyGP0PmLX/gX46EkvojIKp5zj4xTI6DIdI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+dce5aae19ae4d6399986@syzkaller.appspotmail.com, Hou Tao , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.12 195/414] bpf: Check rcu_read_lock_trace_held() in bpf_map_lookup_percpu_elem() Date: Mon, 23 Jun 2025 15:05:32 +0200 Message-ID: <20250623130646.890205794@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130642.015559452@linuxfoundation.org> References: <20250623130642.015559452@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hou Tao [ Upstream commit d4965578267e2e81f67c86e2608481e77e9c8569 ] bpf_map_lookup_percpu_elem() helper is also available for sleepable bpf program. When BPF JIT is disabled or under 32-bit host, bpf_map_lookup_percpu_elem() will not be inlined. Using it in a sleepable bpf program will trigger the warning in bpf_map_lookup_percpu_elem(), because the bpf program only holds rcu_read_lock_trace lock. Therefore, add the missed check. Reported-by: syzbot+dce5aae19ae4d6399986@syzkaller.appspotmail.com Closes: https://lore.kernel.org/bpf/000000000000176a130617420310@google.com/ Signed-off-by: Hou Tao Link: https://lore.kernel.org/r/20250526062534.1105938-1-houtao@huaweicloud.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/helpers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index a05aeb3458964..9173d107758d4 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -129,7 +129,8 @@ const struct bpf_func_proto bpf_map_peek_elem_proto = { BPF_CALL_3(bpf_map_lookup_percpu_elem, struct bpf_map *, map, void *, key, u32, cpu) { - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && + !rcu_read_lock_bh_held()); return (unsigned long) map->ops->map_lookup_percpu_elem(map, key, cpu); } -- 2.39.5