From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 B507E3C0635 for ; Wed, 26 Aug 2026 10:57:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787741877; cv=none; b=h+uBtwE8uX3hSgLwO+GLXZMyEVmJRkFmv0ux4OTt84qKv7iaZhGKPBTqcwmyaccu1d7Fhk6KoG11DZlx/QpVq3Im+tSaoMRRwKqE8fXR6oJuOvvcIsRT3T5AzHk5tEM7m/epLO1I2FAkGL+d7s9qjuAvxrg/NOnn0Y+b6fNe/SU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787741877; c=relaxed/simple; bh=4+WSJvq7FFCohKxrQHlR5eQEC0xO+sYnwruNN1Q4LeA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z6PSAyjp312P7zGaJnabXiLzaUF7waX842dXiZGCyMFTxOlRpj7stvKaf4fKROEmqbpuWC3z2hYkSTVS8KOH9dK2E6ikG78nkC2pFVwkffUPCDh/l13okzBMZ+39xtnMo6PYoFqB17bPx17/nVyzDK5cPzWAF6cLKZM2y47R5V0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UuQ49L0k; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UuQ49L0k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B45531F00A3D; Wed, 26 Aug 2026 10:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787741865; bh=vSJT/4FeUPugkKjaAn4dyHqgKVdnIenxrBdYCvzvGzw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UuQ49L0kk9cTGdwiDCD7UgRgtOcE01i9ACZOpyH4JGIKuwLpIZdNhiw77FSaGyCGi mbhVYSCfzxXmxGlWJ9p0tL8jqcsWOk1dcvIEldIHkYPGvEKYKI6q5VsU9rytVyz5oO HuoNTkKTY629HmiUp5x9oR7rJudCISYwwgcEtBQJOA3++7+8Er4awB380A0faBU6UN xkETLax5DHz3FLj65lKKDVK6Vx5A6bcWr0c/fHKHrBiAP1wZXMNASSWOKmmvjvFadf 3DjX3cIgBMVJj9YK5+z9MJdAUsCFR+OwZ1jHQ2fjrKIwzvVKq/e18gsKnchiiGDaI4 YFD6rd3QzlPnQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Ryusuke Konishi , syzbot+c37bed40868932d790e9@syzkaller.appspotmail.com, wuyankun , Viacheslav Dubeyko , Sasha Levin Subject: [PATCH 5.10.y] nilfs2: reject invalid block index in GC ioctl Date: Wed, 26 Aug 2026 06:57:42 -0400 Message-ID: <20260826105742.2608961-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026082455-batch-papyrus-5e86@gregkh> References: <2026082455-batch-papyrus-5e86@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ryusuke Konishi [ Upstream commit a1735eae55448bc79c2da6593455791e886f6ed8 ] Syzbot reported list corruption caused by a double list_add_tail() call on bh->b_assoc_buffers within nilfs_lookup_dirty_data_buffers(). Analysis revealed that the root cause was the insertion of a page/folio with a page index of ULONG_MAX into the page cache via the GC ioctl. filemap_get_folios_tag(), called by nilfs_lookup_dirty_data_buffers(), repeatedly detects a dirty folio with a page index of ULONG_MAX due to index wrap-around, leading to duplicate processing of dirty buffers. As a preparatory step, the GC ioctl loads the page/folio of the block to be moved during GC and inserts it into the page cache based on information in the nilfs_vdesc structure passed as an argument. Normally, this does not cause issues because the user-space GC library configures the nilfs_vdesc structure properly. However, since there is no range check on the parameters determining the page index, a request with artificially crafted parameters -- such as those generated by Syzbot -- can result in a page/folio being inserted with a page index of ULONG_MAX, triggering the above problem. This resolves the issue by checking the ranges of 'vd_offset' and 'vd_vblocknr' in the nilfs_vdesc structure that determine the page index, thereby preventing the invalid page/folio insertions. Reported-by: syzbot+c37bed40868932d790e9@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c37bed40868932d790e9 Fixes: 7942b919f732 ("nilfs2: ioctl operations") Cc: wuyankun Cc: stable@vger.kernel.org Signed-off-by: Ryusuke Konishi Signed-off-by: Viacheslav Dubeyko Signed-off-by: Sasha Levin --- fs/nilfs2/ioctl.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c index e56e871927417..9f10a9cec3e0a 100644 --- a/fs/nilfs2/ioctl.c +++ b/fs/nilfs2/ioctl.c @@ -544,6 +544,8 @@ static int nilfs_ioctl_get_bdescs(struct inode *inode, struct file *filp, * Return Value: On success, 0 is returned. On error, one of the following * negative error codes is returned. * + * %-EINVAL - Invalid virtual block descriptor. + * * %-EIO - I/O error. * * %-ENOMEM - Insufficient amount of memory available. @@ -557,15 +559,30 @@ static int nilfs_ioctl_move_inode_block(struct inode *inode, struct list_head *buffers) { struct buffer_head *bh; + __u64 limit_blkidx = (__u64)inode->i_sb->s_maxbytes >> inode->i_blkbits; int ret; - if (vdesc->vd_flags == 0) + /* + * vblocknr 0 is reserved as an invalid pointer. Also, limit_blkidx + * ensures that the page index converted from vd_vblocknr never + * overflows the page cache limit and respects the architecture's bmap + * key width. + */ + if (unlikely(vdesc->vd_vblocknr == 0 || + vdesc->vd_vblocknr >= limit_blkidx)) + return -EINVAL; + + if (vdesc->vd_flags == 0) { + if (unlikely(vdesc->vd_offset >= limit_blkidx)) + return -EINVAL; + ret = nilfs_gccache_submit_read_data( inode, vdesc->vd_offset, vdesc->vd_blocknr, vdesc->vd_vblocknr, &bh); - else + } else { ret = nilfs_gccache_submit_read_node( inode, vdesc->vd_blocknr, vdesc->vd_vblocknr, &bh); + } if (unlikely(ret < 0)) { if (ret == -ENOENT) -- 2.53.0