From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796560904; b=KRR5IwWZx+Hw1LoYHCgzaF8banTM8SdSBEy6SexM94ksiP8/g+T8wLcjuNG6Gkz2WZW0 tgsOl0rOcurh+/UV4Ja7Byz/7E/TyQ083rPXs3yyRC3oE1HgQnFMZEUrUBQY7L0HJB7kt kQvmFQ4fONn0GmZRRvfbVnZ49jIZSNyFRB/VP4pb7TDdjidTC9qNXCl37NhivTkG0txnK 32Ax9+VQiDJUuWH3A3qnYEMlqJn3/7+95VKMvtFicgChqdR44jnPOYa/iLBvGYMxyHNjs PZ96b5PvOA25DQdHqnwPtxZirKqVcgg7xPctqkjsx0D0PVgihT5VQm6ZsztgLhMU2vA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796560904; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=9/aBuvSjrtshc5FCqbJSo0gpIbnpurREC1PFDaXM0hw=; b=nIYOZclFBstkvbVGzD7veQFm7nyQVak93snGy2Fqn39S+RphfpeBPC7WCtJWrIer9Zwz y1vuIUof87+EJwSK2aJrlXQ0kltn+A54LesjtC31+Q+sZpOGSnpzOM8n6AOuVmYndZEy0 38oYk1gi3VVRxJHlIjSFc7iynJ4AHFwN2c9Y8kJzgSdt5IsDcI7D5Kp6qOfXPP0KK8dQg EChxVzy84bN6aWEmglfifmHL1MInlwIew6tm8Y4hBnc7fmZcNoyLgOf9jn+kjUB2wssQz hZXUUArCl1Ar+EreJ15wftEZ8bZ82HCwa8vut31W7NLAFvpDewhV1UrjAZkIn5T9Wbw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=iiitd.ac.in; spf=pass smtp.mailfrom=iiitd.ac.in; dkim=pass header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=UPq2WkRE; arc=none smtp.remote-ip=74.125.82.175 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08C6A606A31F for ; Sun, 6 Dec 2026 12:41:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 08C6A606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=UPq2WkRE Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-3282db206d3so1937164eec.0 for ; Sun, 06 Dec 2026 04:41:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796560903; x=1797165703; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9/aBuvSjrtshc5FCqbJSo0gpIbnpurREC1PFDaXM0hw=; b=UPq2WkREePSQNNRqLQvcb8LJXEQHkvQsS4utWOv9oX4Xq/aQdI+inEllEQ3kJAikHu 2FTHFfVmKbWXXlu6iHk3IY2ETndSGDGopDF0Pln4IqwTTjLVkfJjjQaKrjFNmwZqMbzO xIayW936LCQDkdSEdP8L+2A4oWpFGsEc19a3Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796560903; x=1797165703; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9/aBuvSjrtshc5FCqbJSo0gpIbnpurREC1PFDaXM0hw=; b=nAh/RoTeXWa/rUIr80bD09JkRA9Wb2bjEISxtyjbtZl79YjvqTHqmd2k13alyIva4V IXtJmxMKqh3K4DwVFnrQR4q4Ud4uNkc+sicW2YO91CnFAdOwgY2C06bbZnMw2XP5upQj d/Wwku+Z6KlulQRHdwYBJkR8PcjhnO/jN46Jr7VBIj8P9/ikCs7pRUffLJ2sfrVAjnYD 1IxzCN9dvgdQvSHa8gMeQ9s1o0tdxRKm6fFeYx6+bSACSUjk7OcJqFBJQ8xyACGLA0BQ 4zYc4cPc7Cl97wtxX3C4tg0gSjHYLdLQp3LMAbKoSbXkbsJVTCMNqB/KgvJm0o3kRzNa ul+w== X-Forwarded-Encrypted: i=1; AL+hErFFQlmZIPh7tc+hMiKxxxSKx3W79zsCYOo0mg9P9jqFRQuSPEfmh751ATLLP8GdyxHD7ZfJdJjnp9C35SU=@vger.kernel.org X-Gm-Message-State: AB4q+uFY9MHp0ofKRnpM3tdvLWlhG3htlaftIFblolwMRv5HW8mrMHyg pRL0DiB1xCY0M1A/MFHjHAeyIq+Uy8+Vi5TP9sdPPsSmlm2SNpQFhc6llWUlhtbP+2o= X-Gm-Gg: AZFdTZfz1AKEP+D1leL4IWnd8kBac0D47sE8zzc43bu4Nt1SEEWXT24j6YdrhOctrau n2Gwdt59QrlPjuiGPYhZ5JssvhY8NqHWIEOKzoF/f3p39rypUgQkKIQR6hALfW2rRnHQbryKIVA y8SO7EOU2VboFnYKMF5lak9r5nql+LQX2HBIwPZqElF0AFVh4p0z+P5HpXLpXw7C4MGjFBRP8b+ 5647PtyTiVx52wlUw3QLSdSPrdmRl1SnEcgnT2iFEv++R91ldS2U6OkuEnCzPThcnao62ZmebM6 s53X/iGRJuxQRmoSxq6allZIOCLTDGqaKoKiT2qjij3bePQJVWecTtgQzvPPTE9VZ/zzLIdFpAr sJkOYWckesR/iCsThbj8IXNUCF/B6aee4PvtmRoydkhXR+yhOKVnrpyB107hGUPWxlBu43fFEUO FWo4PUB62VTlaA5DXzNM/tCRotMO2AH/NKqeAL4+fePMACMw5vx2NvvD2b0Zy2U0Z+9szSQ7ya1 YP/MUPvFiDt1XM9P/n01ECO7sTA7dxLNaot6E+3k6hl2YWtC2/y0z1l7ObQKX6GYVx7+gl+SS9k YqQcZZb+Std+CEzjlzcm25PGA0IOiyE103J19jN/9U/v0annRr9ScSRWvC87429k/z6hj+qlNPE JRZCfAeASx4VG35FPR/TCHGCqGu1x4EDhHeLWnK6IHh5Vvu/I2HSNYgGly0wPhr8w X-Received: by 2002:a05:7301:4307:b0:386:e4ce:7524 with SMTP id 5a478bee46e88-38752199bd4mr7085067eec.36.1796560903101; Sun, 06 Dec 2026 04:41:43 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e5e7dsm33550289eec.19.2026.12.06.04.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 04:41:42 -0800 (PST) From: Piyus Kedia To: Carlos Maiolino , linux-xfs@vger.kernel.org Cc: "Darrick J . Wong" , Ibrahim Hashimov , linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [PATCH] xfs: check buffer log item regions against the dirty bitmap in recovery Date: Sun, 6 Dec 2026 18:11:38 +0530 Message-Id: <20261206124138.1307637-1-piyus@iiitd.ac.in> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-Mailing-List: linux-kernel@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 xlog_recover_do_reg_buffer() copies one logged region per run of set bits in a buffer log item's dirty bitmap, and xlog_recover_do_inode_buffer() reads each di_next_unlinked from the region of the run that covers it. Both find the region by counting runs into item->ri_buf[], but ri_buf[] has as many entries as the item's blf_size asked for when xlog_recover_add_to_trans() sized it, the item may have been committed with fewer, and nothing ties either number, or a region's length, to the bitmap. Only ASSERTs check them. Commit 813f8136a2ce ("xfs: bounds-check buffer log item's dirty bitmap") bounded the bitmap by the buffer. A buffer item with one region and a bitmap of several runs still reads ri_buf[] past its end when a crafted image is mounted: BUG: KASAN: slab-out-of-bounds in xlog_recover_do_reg_buffer+0x235/0x580 Read of size 8 at addr ffff8880216d70e8 by task x/9437 xlog_recover_do_reg_buffer (fs/xfs/xfs_buf_item_recover.c:518) xlog_recover_buf_commit_pass2 (fs/xfs/xfs_buf_item_recover.c:1128) xlog_recover_items_pass2 (fs/xfs/xfs_log_recover.c:2020) xlog_recover_commit_trans (fs/xfs/xfs_log_recover.c:2089) ... xfs_log_mount (fs/xfs/xfs_log.c:621) The buggy address is located 8 bytes to the right of allocated 32-byte region (kmalloc-32, xlog_recover_add_to_trans()) and then memcpy()s from the iov_base it read there. In xlog_recover_do_inode_buffer() a run longer than its region has di_next_unlinked read past the region: BUG: KASAN: slab-out-of-bounds in xlog_recover_do_inode_buffer+0x29a/0x4c0 Read of size 4 at addr ffff88801cd77fe0 by task poc/9456 xlog_recover_do_inode_buffer (fs/xfs/xfs_buf_item_recover.c:702) xlog_recover_buf_commit_pass2 (fs/xfs/xfs_buf_item_recover.c:1100) xlog_recover_items_pass2 (fs/xfs/xfs_log_recover.c:2020) The buggy address is located 96 bytes to the right of allocated 128-byte region (kmalloc-128, the logged region) and a second run with no region left reads ri_buf[2] past its end, as above. Stop at a run that has no region left in both, and check that di_next_unlinked lies inside the region it is read from. We found this with a syzkaller-based fuzzing harness driven by an AI tool. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Closes: https://lore.kernel.org/r/xfs-log-buf-regions.20261206@iiitd.ac.in/ Cc: stable@vger.kernel.org Signed-off-by: Kapil Vaswani Signed-off-by: Piyus Kedia --- Tested on ksmbd-for-next (d70570cf8003), whose fs/xfs is identical to mainline master (9437ee8b6cf6) and to xfs/for-next (ab1a77ab136c), where this applies as is; KASAN, the same config and image before and after. A dirty log with one field changed and the record CRC recomputed: before buffer items of one region given a bitmap of every other 128-byte chunk: KASAN at :518 in 3 of 3 runs, then a general protection fault in the memcpy(); the unlinked-list inode buffer item's bitmap moved to chunks 3-4: KASAN at :702 in 3 of 3; chunks 1 and 4: KASAN at :700 and a fault, 1 of 1 after no report; the mount fails with EUCLEAN and the messages added control the same logs written back unchanged: both kernels recover and mount fs/xfs/xfs_buf_item_recover.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/fs/xfs/xfs_buf_item_recover.c b/fs/xfs/xfs_buf_item_recover.c index 57929f115055..5b973aebbe44 100644 --- a/fs/xfs/xfs_buf_item_recover.c +++ b/fs/xfs/xfs_buf_item_recover.c @@ -486,6 +486,19 @@ xlog_recover_do_reg_buffer( nbits = xfs_contig_bits(buf_f->blf_data_map, buf_f->blf_map_size, bit); ASSERT(nbits > 0); + + /* + * Each run of the bitmap is copied from the next logged region, + * but the number of regions is the item's own blf_size, and + * nothing ties it to the bitmap. Do not index past the regions + * the item has. + */ + if (XFS_IS_CORRUPT(mp, i >= item->ri_cnt)) { + xfs_alert(mp, + "Too few regions (%d) for buffer log item bitmap at daddr 0x%llx.", + item->ri_cnt - 1, xfs_buf_daddr(bp)); + return -EFSCORRUPTED; + } ASSERT(item->ri_buf[i].iov_base != NULL); ASSERT(item->ri_buf[i].iov_len % XFS_BLF_CHUNK == 0); /* @@ -688,6 +701,22 @@ xlog_recover_do_inode_buffer( if (next_unlinked_offset < reg_buf_offset) continue; + /* + * di_next_unlinked is read from the logged region of this run, + * at its offset in the run. Neither the number of regions nor + * their lengths are tied to the bitmap, so make sure the field + * lies inside a region the item has. + */ + if (XFS_IS_CORRUPT(mp, item_index >= item->ri_cnt || + next_unlinked_offset - reg_buf_offset + + sizeof(xfs_agino_t) > + item->ri_buf[item_index].iov_len)) { + xfs_alert(mp, + "No logged region for inode buffer offset %d at daddr 0x%llx.", + next_unlinked_offset, xfs_buf_daddr(bp)); + return -EFSCORRUPTED; + } + ASSERT(item->ri_buf[item_index].iov_base != NULL); ASSERT((item->ri_buf[item_index].iov_len % XFS_BLF_CHUNK) == 0); ASSERT((reg_buf_offset + reg_buf_bytes) <= BBTOB(bp->b_length)); -- 2.34.1