From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86E2C31F9A5 for ; Mon, 17 Aug 2026 05:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786943014; cv=none; b=azXvxzYrmlo1dWk3U44wlDxEQt4yKCK2ToWnrkYJZB/P13oeMi2nurkYUCYvVwO/GvsTont4HKtZaHNWCV/2DtQK4cX26P30k6rrz2NfmDBj2mSeSaSuUeTwPPBwcdYuuCrKCW99K2/5pMqelXdMfGGanVePDiYZypHq2ZfdCsI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786943014; c=relaxed/simple; bh=XfcJgpLZ61FS5Avhgji4Bz2o7ECGfhW4y1IDyC/VQuI=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=At57dz4xIPOjq/V2q9tUtojSaU1ig9wwHFPdmCXNf1JfgAo0zhIzrjXlC6TaZitms868L+A2kS15vuhtWcI2qQi7ymtnUosxv5VGaz+9f3i8wKT1Eg8AEH41KXDeHcEJh66BBzX6lR64mW0ZHSunEZkDMvcrwUWBQmqwJIJ4Els= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.167.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-4b28d9952a5so162816b6e.1 for ; Sun, 16 Aug 2026 22:03:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786943011; x=1787547811; h=content-type:to:from:subject:message-id:in-reply-to:date :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=LLL+vQpyA8Lr5cO/1fkYK5FLlV44Q6nQDrSF54ksR7w=; b=bkhlME2wT6kydlSecrazFVb96pzSTpBMahtLGhwBiF07Ew1wI212jN1s6BXyvswhhP RsxYRK2ookl4oMDcfu5C9KjzeMLh3XoHVGrNBKVVPXhKBdovESam1vgRwIFATpJ5wmV1 SopsO7VGHf/4vxbojDxZ/SLOXGEkSOp0DZLwrrLpMG8Z5yoZzfOmZkMh2rxli5MuUgze +iAB22AW4kY4xwujdgmN+Tmh5f57PAjmtBE1gzOuFO4RYyooqc/sfydzIIxDgRsoldLk k2vvT4UDyi7kfkP7ebijGksAEMd3CsZSIRlwIE88cZ78DB+xG7UqZEZgQInFcxYOZbpE WRyg== X-Gm-Message-State: AOJu0YzvakFIUjOiYrEoaeWaY+Np2tMSMPRHpuTk43OqFrCq4+LWBYms Yh24D2woGnMdYIW2rLQe0H74QVyjJU3Z/OaW2UAJi7e773qEO0kpZHLma6+48L/xLQim0rA1BL6 UXWmoa6m7nRqTRgT/+2VF8Sr4c3mkbQfWW7RYSzgKNMofQEThwM7HeTB54N8= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6808:120d:b0:4a4:9e18:607a with SMTP id 5614622812f47-4b241eac3dcmr16696390b6e.21.1786943011510; Sun, 16 Aug 2026 22:03:31 -0700 (PDT) Date: Sun, 16 Aug 2026 22:03:31 -0700 In-Reply-To: <6a82354d.10853dc7.22f513.0014.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6a829623.dbb3a75c.20434b.0042.GAE@google.com> Subject: Forwarded: [PATCH] tracing: Fix use-after-free in trace_pipe read on sub-buffer order change From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] tracing: Fix use-after-free in trace_pipe read on sub-buffer order change Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master Writing to buffer_subbuf_size_kb calls ring_buffer_subbuf_order_set(), which frees every sub-buffer of the ring buffer, including the reader page, and replaces them with newly allocated ones. Readers of trace_pipe hold pointers into those pages. ring_buffer_peek() looks up an event under cpu_buffer->reader_lock but returns the event pointer after dropping the lock, and peek_next_entry() then calls ring_buffer_event_length() and ring_buffer_event_data() on it. If the sub-buffer order is changed in that window, the reader dereferences freed memory: BUG: KASAN: use-after-free in ring_buffer_peek+0x3e0/0x430 Read of size 1 at addr ffff88802a4cf010 by task syz-executor989/6002 Freed by: free_buffer_page kernel/trace/ring_buffer.c:398 [inline] ring_buffer_subbuf_order_set+0x1325/0x18e0 kernel/trace/ring_buffer.c:7444 buffer_subbuf_size_write+0x182/0x280 kernel/trace/trace.c:8221 Take trace_access_lock(RING_BUFFER_ALL_CPUS) around the order change. This is the lock trace_pipe readers already hold across their entire peek-and-print loop, so the swap can no longer race with a reader that is dereferencing a peeked event. Reported-by: syzbot+685955db58555575fdd2@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=685955db58555575fdd2 Fixes: f9b94daa542a ("ring-buffer: Set new size of the ring buffer sub page") Signed-off-by: Deepanshu Kartikey --- kernel/trace/trace.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 395238b2b715..c38a5de602e0 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -8214,6 +8214,8 @@ buffer_subbuf_size_write(struct file *filp, const char __user *ubuf, /* Do not allow tracing while changing the order of the ring buffer */ tracing_stop_tr(tr); + trace_access_lock(RING_BUFFER_ALL_CPUS); + old_order = ring_buffer_subbuf_order_get(tr->array_buffer.buffer); if (old_order == order) goto out; @@ -8253,6 +8255,7 @@ buffer_subbuf_size_write(struct file *filp, const char __user *ubuf, #endif (*ppos)++; out: + trace_access_unlock(RING_BUFFER_ALL_CPUS); if (ret) cnt = ret; tracing_start_tr(tr); -- 2.43.0