From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796561039; b=l3dpxJYZAORpiY6Z8xUh0tBUsecshUNWnGbw1ZgYDqEXETjFH744gihjkkp4tizmXg69 SgyWCU+KSgXyHwGg3vv1vXm7g16o2JioAM4QYw0tMeL1FlHcbTyZ4PmIrvFWOqHq8Bhvl MkyOOo+Cqt5RrY8Y+m4zyrGCoylAviXNRjfLJg8H1lutsz39FyDnGs12ZeDu5t7TqT0JH auUUigT0w+Nc0SsKqUDTbDjerc+rxgGUL9Lv2ZMYICnGjAeNZxfsDstVkVLL1MZTR2cbk 0UuY/gqcCpuXKCpMbxH1S94wFEGLZAH43Dwwl0mzJQc4U78s3WpYz6297KTvBwtFQyw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796561039; 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:MIME-Version: Content-Transfer-Encoding; bh=PFuuuTk+BOHgP2RglIU/O9uXjBMICbYFREScXO9U6yk=; b=hdnB83dIR//QFDvQnmZPx+v59iVW07DU82zBo0pBnOew/XfVr7lE1PLQQj4HstEQikno lTH40h72Np0Lx4eMdYEefeYAN9HKyB0NOizhu/uQwTyGqNkmtpoYFlQWdV5/aMy2oKQjB 6rmeLR5Xh8F+YNa5r0Kg0vJLzKfJg90Q0ucG2hgiDwhCbv4Wt4PIGbNlNnfPQGt8C2CJW nvPdMDqW1LbfU+yYXDbEBvaeY7UGJG2wJj1Yp5FqaHQRm6WG/NVL3u3Ym39rAKdo2KVd/ +NuqH+x8GxCEdfanZSMnK3Qb2y3eyRCJGvLH1PBntm7RYoQIF7o6vlypqPfo8Y9Jkww== 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=Vn2Gra0g; arc=none smtp.remote-ip=74.125.82.179 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (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 22BD1606A321 for ; Sun, 6 Dec 2026 12:43:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 22BD1606A321 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=Vn2Gra0g Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-386ab9ab619so3958137eec.1 for ; Sun, 06 Dec 2026 04:43:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796561038; x=1797165838; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=PFuuuTk+BOHgP2RglIU/O9uXjBMICbYFREScXO9U6yk=; b=Vn2Gra0gPDlB++7fp/yx1bq9ZWxNsK2uFH/3k7rsPqQfa4MKXPKHEw5q4tfetrCk0l LowalWWJ9wiYjPB3RCKvpcnCMJjyRufQACwu0e2fmS/7Hf2i9pNN9n1KIxr/N3Nicy0j nPXPxoaiMoiQhNFlHu5asev4VJdxRVMnfF1zE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796561038; x=1797165838; h=content-transfer-encoding:mime-version: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=PFuuuTk+BOHgP2RglIU/O9uXjBMICbYFREScXO9U6yk=; b=ZH9UkAN9C4UHaTi5PKaTY0MyXl80ntwuE9CO/eo5k59fjr35sxK1bWkvdJG7NK3qMr MG5bpSSTWp4Sb5gqTpZcWFEST3HLJ0qTLdov9M1fVYK/XuPac0FMr512HZeW3wXNenus xCGFjBB3mkqREC5OtWFP8mkn0KTnGAme67H/WeM6UgnJ5DLqNdTRSv98yb1THIhXP4sE HMkLT+fIovglcUmEABAmP4nOlze6XcPe0UjQXI9ld9O3SDwBqdiz9gBcZ8xO65I67gI9 o98OYH6kJh04QJVJ89VkX7ErCINIBNS6e2fSTrQ/DSs4JiT6brUTSrvCl1w5tsJ3X6l+ GLYQ== X-Forwarded-Encrypted: i=1; AL+hErEKMYo01Ehv5Y0ipffBAcqDmcBe/JqqOKdbJ986bWfLYo9XUxqmN/jDNigXbPQrtcd0/COnvM86JHdturU=@vger.kernel.org X-Gm-Message-State: AB4q+uFK9ryrNXrHeski6F79H2PTryKnXVd2b7plIeOQHk6vFBnLDycZ veNKTGaDOUmr7EQbiIC3XR2BOSjIcHpR1vpbCitAT8FBcIfRxl/1mZ6YEEgEkIRR06A= X-Gm-Gg: AZFdTZcZJij0wKLqoZFSlOYZ7F3aM36zX7b4gbZmzV+qHsEdm9Rw5kN9hD8cCFmPkAY 5XH7Hd8kO4OMvGoXriQw+lPwsB3QZbr0koA4II878upWgVkhVznNJsRvBlncm2WkhH2LGvXoOJ5 wcmt/WIZ/v2178QSIMhwgcsOSo9Pei6w0GWG0y62k159FhdA00XD8nKEk44QGCfQB7VChri44+w B/7aCBflWoxxAUZCh8ut7mwhE9gACmWt+UWG7K3tQgFkXQsPrFuFlzacfe72rPZW64dY6Ma+bOk h4S73t/q99gM90DDbNlCz5hquEeB+YtaaHH9KOWlEHiOPYWl++NuC77U9FrOwiA1hSo583PiLws C5ZmhRjnTmGp94n8QJgvukotemny9yUowDcP9hzskSDpw0F9hEVy78phcNE5UVgKowkPi6qL39f ZJdMN6jGUnCJyj42p8XbjAJHAaFXlvi1TxO1RjPfNGbYZCOYiFEancDGaw6HhiqOk3SmkioZvBu 5Ue9h2z3WgJqxj7HKcFDACA4SpUlnFeU4P5ma2xuuTv48esCGgsDgQxFa0gh35/i2dlWJynnO4Z 7ZIHuiZzqO+xq1YtMfHqtk+JXXqpCo8pxVoBK9ukvbQeX0/RPU1ime7MahJsOh0MNhdkOnDHKuM cNs7QZ28WmxILsT9lR8qhnoWK8nHxjE6wjXV4eJhkhmMNfIUvER/RihuMWS5NW+bs X-Received: by 2002:a05:7301:106:b0:384:d59d:199c with SMTP id 5a478bee46e88-38751fc30d4mr7761073eec.1.1796561037979; Sun, 06 Dec 2026 04:43:57 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521f1360sm30478854eec.20.2026.12.06.04.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 04:43:57 -0800 (PST) From: Piyus Kedia To: Carlos Maiolino , linux-xfs@vger.kernel.org Cc: "Darrick J . Wong" , Long Li , linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] xfs: dquot log item recovery reads and writes at an unchecked qlf_boffset Date: Sun, 6 Dec 2026 18:13:52 +0530 Message-Id: X-Mailer: git-send-email 2.34.1 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 Hi, Mounting an XFS image whose log is dirty, with quota accounting on, replays the dquot items in the log, and xlog_recover_dquot_commit_pass2() finds the dquot at the item's qlf_boffset in the buffer it reads for it, without checking the offset against that buffer. Our fuzzer found an out-of-bounds read this way, inside mount(2), and the logged dquot is then copied past the buffer, which we measured. The code is identical in 7.4-rc5, mainline and xfs/for-next, and the line numbers below hold for all three. fs/xfs/xfs_dquot_item_recover.c:135 dqb = xfs_buf_offset(bp, dq_f->qlf_boffset); ddq = &dqb->dd_diskdq; if (xfs_has_crc(mp)) { xfs_lsn_t lsn = be64_to_cpu(dqb->dd_lsn); if (lsn && lsn != -1 && XFS_LSN_CMP(lsn, current_lsn) >= 0) goto out_release; } memcpy(ddq, recddq, item->ri_buf[1].iov_len); qlf_boffset is not checked against the buffer, and the length of the copy, ri_buf[1].iov_len, only from below. The image below is one filesystem whose dirty log has a field of its dquot items changed and the record's CRC recomputed; the same log written back unchanged recovers and mounts on every kernel we ran. qlf_boffset 1024 on a 1 KiB dquot buffer, mounted -o uquota: BUG: KASAN: slab-out-of-bounds in xlog_recover_dquot_commit_pass2+0x2f8/0x5e0 Read of size 8 at addr ffff88802770b470 by task poc/9461 xlog_recover_dquot_commit_pass2 (fs/xfs/xfs_dquot_item_recover.c:143) 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 112 bytes to the right of allocated 1024-byte region (kmalloc-rcl-1k, the dquot buffer) The dd_lsn found there did not stop the replay: with kasan_multi_shot the next reports are the copy and the checksum, BUG: KASAN: slab-out-of-bounds in xlog_recover_dquot_commit_pass2+0x3e2/0x5e0 Write of size 104 at addr ffff8880285c1c00 by task poc/9455 xlog_recover_dquot_commit_pass2 (fs/xfs/xfs_dquot_item_recover.c:150) at the first byte past the buffer, then xfs_update_cksum() (:152). KASAN's memcpy() skips a copy it reports; in our runs without kasan_multi_shot only the dd_lsn read is reported, the copy goes ahead, and recovery stops later at "Bad dquot after recovery" (:159). Both this function and xlog_recover_dquot_ra_pass2() also take ri_buf[1] of an item sized for one region (qlf_size 1): the NULL check there catches a region that did not arrive, not an array entry that does not exist (KASAN reports the readahead's read, at :37). Impact - who can trigger it - A crafted XFS image with a dirty log has to be mounted with quota accounting (m_qflags, from the mount options; -o uquota here); all of the above happens inside mount(2), before the filesystem can be used. XFS is not FS_USERNS_MOUNT, so mount(2) needs CAP_SYS_ADMIN in the initial user namespace: root, or a service that mounts on a user's behalf. We have not tested whether desktop auto-mounting of removable media mounts such an image. Recovery runs at every mount of a dirty log but -o norecovery (which has to be read-only); a read-only mount (MS_RDONLY) replays the log too, measured on both kernels. The image chooses its own geometry and contents. - What is read, and what is written: the dquot block anywhere up to 4 GiB past the buffer. dd_lsn is read there, and unless it looks newer than the transaction, the logged dquot (104 bytes as the kernel logs it, unbounded above) is copied there and a CRC stored after it. Measured: a 104-byte copy to the first byte past a 1 KiB buffer (KASAN skips the copies it reports, and in our runs without kasan_multi_shot did not report it, so it ran). - The write lands in whatever follows the buffer, here a 1 KiB kmalloc object. We have not looked at what such writes could be made to do on a kernel without KASAN. Seen on 7.4.0-rc5 (twice) and REPRODUCED ON UPSTREAM: on ksmbd-for-next (d70570cf8003, 2026-12-04), our upstream base, whose fs/xfs is identical to mainline master (9437ee8b6cf6), with KASAN. fs/xfs/xfs_dquot_item_recover.c is also unchanged in mainline c3500c5ef648 (2026-12-04) and in xfs-linux for-next (ab1a77ab136c), where the patch applies as is. Same config and image before and after, the patch the only change; one boot per run, the fuzzer's own program included where it had one: without the patch KASAN report qlf_boffset 1024 in a 1 KiB buffer 4 of 4 qlf_size 1 1 of 1 with the patch, kasan_multi_shot on: no report, alone in one boot and together with our other log recovery fixes in three more (one of them the fuzzer's own program). The mount fails with EUCLEAN after an XFS_IS_CORRUPT() report and one of dquot ID 0x0 log item offset 1024 in 1024-byte buffer. NULL dquot in xlog_recover_dquot_commit_pass2. and a read-only mount fails the same way. controls, the same logs written back unchanged: both kernels recover and mount. Not covered by the patch, by the source and not run: the dquot format region (24 bytes) is read in readahead and pass 2 without a length check, and so is a QUOTAOFF item's qf_flags. We can send a patch for those. A patch follows in reply to this mail. It checks that the item has its dquot region, that the region is sizeof(struct xfs_disk_dquot) as the kernel logs it, and that the dquot block at qlf_boffset lies in the buffer. The error goes out through out_release, which e2b4a856085e ("xfs: don't swallow dquot recovery verification errors") made return it. We are reporting four related log recovery bugs separately, each with its own patch: buffer items whose dirty bitmap outruns their regions, inode items whose fork regions are missing, an unchecked inode ilf_boffset, and the inode buffer verifier's inode count. This was found by AI-driven fuzzing built on top of syzkaller; its analysis was then checked by hand against the code, and every access above was reproduced. The reproducer is one program that carries its filesystem image, and we are happy to send it on request. Kapil Vaswani Piyus Kedia