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=1796380445; b=LQyUw4AMpE4JpumA3YPDDygVihxhNgmHRF3vY3CN8aQdFaca/hHUjGyC7MkxRJ13sfbq 7TEoTkV6V56QDlIy1YVKYC6roXv/kPooN1elH/Sr93Af3sA+iKR/PYzWu21BzgnrAOzE5 qumH9OHE8+UX0shmz4qTpCHEVdP9QBbV1o/V4fooMVJj0l0jt6pZUIvA6fiPgs88/nhu/ JqGGINBaRcLoIWdYhwMikgSsC8Y1bEDY/8OAGMynjQfqQ9Wzws7O5JXana4+2fTu/tkV0 /4qbtMJkAH/Y/DOB1iza7MtIoQbPY50BefIrKCRbOIl5Sohvqc9NLVACObyDrChwRkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380445; 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=XOPUcoLrWVsGzn18QPbCRo/GLxpLJws1jxBMdfXzp64=; b=aoTxHaVBS5iQXt2rsDHOtms3EnAXZCJLGP26vsfjHWwrTSgxsBzJSLMp8ooPt3KDvMIq OefWvV1c9oibpV+LVQ8s3GE/qwnOVghVTd8VHMNiz/EDHnocATLWypE8a3uICQe73gw28 /jKD42yNkOEFWCnqvvHJHKwY8662Pkncx/Av58BsCql7YMl6hB4Rhjsgk7ll4LtssKb+C DBniAtPIqp0yvliHmzXcK2nNz3qW+Sf3xfCT4roSKg3qScxdLNpUK0NLMGucfK4SrqRZD r7yHpfcO6liRqRVWftBnFUxjelUMkt5vJlhfsJ4NtqudVNInuxbRSk4cLoy8qshGv3A== 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=gWTJuUXO; 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 1FF0B606A680; Fri, 4 Dec 2026 10:34:05 +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=gWTJuUXO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D1871F000C2; Fri, 4 Dec 2026 10:34:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380445; bh=XOPUcoLrWVsGzn18QPbCRo/GLxpLJws1jxBMdfXzp64=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gWTJuUXOFHGJLqpGJHaIrCIHqXIn68bFOCVJo/h91rSK8B01NOmAmEn84SRbpMqzs TooPCNAqZQG56qpdZgMHvLTId1+acDvZfsFnBHLIqbOKV/L4C0Pva5iLntcP8f1SLY 9qWXX0ihy+SFgIFzPxULQ7+Jqrt1LZiRQsXOsATc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 277/742] bpf: Leave nothing behind in the frame of bpf_throw() Date: Fri, 4 Dec 2026 19:02:21 +0900 Message-ID: <20261204100642.405335886@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 86cedb416c4651dde27cfb8142541de8dd2801d9 ] bpf_throw() does not return. What is kept for the return stays behind. With fexit on bpf_throw() the trampoline is never freed. With kretprobes and function_graph the next traced function up the stack takes the return address of bpf_throw() for its own. Mark it notrace and NOKPROBE_SYMBOL. kasan_unpoison_task_stack_below() takes the stack for aligned to THREAD_SIZE. The stack for interrupts of x86-64 is aligned to a page. A program that throws in softirq can leave the redzones of bpf_throw() there: BUG: KASAN: stack-out-of-bounds in stack_trace_consume_entry+0x14e/0x170 It is the only frame with redzones that is skipped. Do not instrument it. Fixes: f18b03fabaa9 ("bpf: Implement BPF exceptions") Fixes: ec5290a178b7 ("bpf: Prevent KASAN false positive with bpf_throw") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-14-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/helpers.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 13b0ee50254b3..aaa646b5be736 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -3405,7 +3405,8 @@ static bool bpf_stack_walker(void *cookie, u64 ip, u64 sp, u64 bp) return false; } -__bpf_kfunc void bpf_throw(u64 cookie) +/* It does not return. What a tracer keeps for the return would stay behind, redzones too. */ +__bpf_kfunc notrace __no_sanitize_address void bpf_throw(u64 cookie) { struct bpf_throw_ctx ctx = {}; @@ -3415,16 +3416,10 @@ __bpf_kfunc void bpf_throw(u64 cookie) WARN_ON_ONCE(!ctx.aux->exception_boundary); WARN_ON_ONCE(!ctx.bp); WARN_ON_ONCE(!ctx.cnt); - /* - * Prevent KASAN false positives for CONFIG_KASAN_STACK by unpoisoning - * deeper stack depths than ctx.sp as we do not return from bpf_throw, - * which skips compiler generated instrumentation to do the same. Some - * architectures cannot recover sp while unwinding, so fall back to bp. - */ - kasan_unpoison_task_stack_below((void *)(long)(ctx.sp ?: ctx.bp)); ctx.aux->bpf_exception_cb(cookie, ctx.sp + ctx.aux->stack_arg_sp_adjust, ctx.bp, 0, 0); WARN(1, "A call to BPF exception callback should never return\n"); } +NOKPROBE_SYMBOL(bpf_throw); __bpf_kfunc int bpf_wq_init(struct bpf_wq *wq, void *p__const_map, unsigned int flags) { -- 2.53.0