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 E4E681D6DB5; Tue, 11 Nov 2025 00:52:18 +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=1762822339; cv=none; b=clO4mcTTLDzS9nH7w9j/vSglX0lmP3+tNoSI6VHOUXvwZjxY2LWJX52lWther6hFREGpV+tnfwtG4ibgNZgmJogvEGTxbDoRpJVNF6Qx9ooBdFPtAr7KsNLKXR49dkfZWfHm94e6vkGiJ1WbPkAmjgh1bZdZWF5l4/LkAzfkCiQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762822339; c=relaxed/simple; bh=ZO8usT2MzsPV42FpWymzUJ4V+DfNEjMsyUR6T31rXZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X4xwk+VI0FW7t39FsfiMLZZoGQwFV+88L5mINM+bywaPM3LbXKJyaSAwFv8787NT/vBkVuJ6P2SOXNGhxJrxgOEaHfyd9S6o1wjd7Z1i0y8TFQ1cdmwVP5heV3/epOEUA2e7SfpmFB04vKg5Wdv9NJG0VIPJHHWJxAkowQmHc8w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MY3SFe3F; 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="MY3SFe3F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83853C116B1; Tue, 11 Nov 2025 00:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1762822338; bh=ZO8usT2MzsPV42FpWymzUJ4V+DfNEjMsyUR6T31rXZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MY3SFe3FbhmrN9UvTguufGmzJKyRXFfAVDsALabjMKxVDXcMii9vmn2lj2CBCiZ76 qmBbOtNiGC+Ewx5djl32/t+YTyvvGW8GF0kjcmpzNnU5r2XLvSCww5v7S0xdxwION7 rfWHcN/iAgM2nyU1EsGXsBObkT9EsYXDSbLn/7Rg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+2617fc732430968b45d2@syzkaller.appspotmail.com, Noorain Eqbal , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.12 030/565] bpf: Sync pending IRQ work before freeing ring buffer Date: Tue, 11 Nov 2025 09:38:06 +0900 Message-ID: <20251111004527.560069786@linuxfoundation.org> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251111004526.816196597@linuxfoundation.org> References: <20251111004526.816196597@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev 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: Noorain Eqbal [ Upstream commit 4e9077638301816a7d73fa1e1b4c1db4a7e3b59c ] Fix a race where irq_work can be queued in bpf_ringbuf_commit() but the ring buffer is freed before the work executes. In the syzbot reproducer, a BPF program attached to sched_switch triggers bpf_ringbuf_commit(), queuing an irq_work. If the ring buffer is freed before this work executes, the irq_work thread may accesses freed memory. Calling `irq_work_sync(&rb->work)` ensures that all pending irq_work complete before freeing the buffer. Fixes: 457f44363a88 ("bpf: Implement BPF ring buffer and verifier support for it") Reported-by: syzbot+2617fc732430968b45d2@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=2617fc732430968b45d2 Tested-by: syzbot+2617fc732430968b45d2@syzkaller.appspotmail.com Signed-off-by: Noorain Eqbal Link: https://lore.kernel.org/r/20251020180301.103366-1-nooraineqbal@gmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/ringbuf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c index 1499d8caa9a35..1f2c504809023 100644 --- a/kernel/bpf/ringbuf.c +++ b/kernel/bpf/ringbuf.c @@ -215,6 +215,8 @@ static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr) static void bpf_ringbuf_free(struct bpf_ringbuf *rb) { + irq_work_sync(&rb->work); + /* copy pages pointer and nr_pages to local variable, as we are going * to unmap rb itself with vunmap() below */ -- 2.51.0