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 AC17F1F540C; Tue, 21 Jan 2025 18:06:25 +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=1737482785; cv=none; b=jbkGSGGKIkQG2a7Mb72u0Y/UGAApgee5mxGf1LTbOoeQ3DTMpQsT9lEXMOk+GbU8Ms/SkymdY4qODwE66IJTb3Rpo7NC9mpjoj2t3MF/TYkuoXPXrbfr3kziNl0GTjeDLbbaJrmJISnxzV6Y36NmPNrr2WhLWM6QzoswNPE8jTs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737482785; c=relaxed/simple; bh=ZHEQSy7nKCohJvpNZjNbBZP2jI1R13WoVvy0mT0SRQw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nHXPx4yEtOTwOawHLz2JsvDsf67UtuQzk8NWRf7nA72OTMgBqQUIHOhEljhjjKKWhMfxHPFYmR4Hpp6Ncv+OKhEuPX3MGYNsJ81ZCBw/k1Sntfayl5tnXRN6qLxB8OE+S5SJQfGxKYij2c5GI3CbLfp0NcNjCiiOTj8+mzG9+DU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=D5fw7eAD; 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="D5fw7eAD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 351FEC4CEDF; Tue, 21 Jan 2025 18:06:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1737482785; bh=ZHEQSy7nKCohJvpNZjNbBZP2jI1R13WoVvy0mT0SRQw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D5fw7eADWOtfmXjSU28LEA/3NP3CmFjOq5tStLnFNEexz42B7iuTdJ8EmFli4MeES 9IR/pbtb6ijXIbWhcYzqGzYt1bitfp6K4Fj12hQeIzCNWpSyRjpx3mS8mfpKlllF2e ec1W3jdB5d1J8dSa+Jp+mVo61BGCGWDNvjoEhEmY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+6c0b301317aa0156f9eb@syzkaller.appspotmail.com, Gao Xiang Subject: [PATCH 6.1 61/64] erofs: handle NONHEAD !delta[1] lclusters gracefully Date: Tue, 21 Jan 2025 18:53:00 +0100 Message-ID: <20250121174523.886309044@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250121174521.568417761@linuxfoundation.org> References: <20250121174521.568417761@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gao Xiang commit 0bc8061ffc733a0a246b8689b2d32a3e9204f43c upstream. syzbot reported a WARNING in iomap_iter_done: iomap_fiemap+0x73b/0x9b0 fs/iomap/fiemap.c:80 ioctl_fiemap fs/ioctl.c:220 [inline] Generally, NONHEAD lclusters won't have delta[1]==0, except for crafted images and filesystems created by pre-1.0 mkfs versions. Previously, it would immediately bail out if delta[1]==0, which led to inadequate decompressed lengths (thus FIEMAP is impacted). Treat it as delta[1]=1 to work around these legacy mkfs versions. `lclusterbits > 14` is illegal for compact indexes, error out too. Reported-by: syzbot+6c0b301317aa0156f9eb@syzkaller.appspotmail.com Closes: https://lore.kernel.org/r/67373c0c.050a0220.2a2fcc.0079.GAE@google.com Tested-by: syzbot+6c0b301317aa0156f9eb@syzkaller.appspotmail.com Fixes: d95ae5e25326 ("erofs: add support for the full decompressed length") Fixes: 001b8ccd0650 ("erofs: fix compact 4B support for 16k block size") Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20241115173651.3339514-1-hsiangkao@linux.alibaba.com Signed-off-by: Greg Kroah-Hartman --- fs/erofs/zmap.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -256,7 +256,7 @@ static int compacted_load_cluster_from_d unsigned int amortizedshift; erofs_off_t pos; - if (lcn >= totalidx) + if (lcn >= totalidx || vi->z_logical_clusterbits > 14) return -EINVAL; m->lcn = lcn; @@ -441,7 +441,7 @@ static int z_erofs_get_extent_decompress u64 lcn = m->lcn, headlcn = map->m_la >> lclusterbits; int err; - do { + while (1) { /* handle the last EOF pcluster (no next HEAD lcluster) */ if ((lcn << lclusterbits) >= inode->i_size) { map->m_llen = inode->i_size - map->m_la; @@ -453,14 +453,16 @@ static int z_erofs_get_extent_decompress return err; if (m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) { - DBG_BUGON(!m->delta[1] && - m->clusterofs != 1 << lclusterbits); + /* work around invalid d1 generated by pre-1.0 mkfs */ + if (unlikely(!m->delta[1])) { + m->delta[1] = 1; + DBG_BUGON(1); + } } else if (m->type == Z_EROFS_LCLUSTER_TYPE_PLAIN || m->type == Z_EROFS_LCLUSTER_TYPE_HEAD1 || m->type == Z_EROFS_LCLUSTER_TYPE_HEAD2) { - /* go on until the next HEAD lcluster */ if (lcn != headlcn) - break; + break; /* ends at the next HEAD lcluster */ m->delta[1] = 1; } else { erofs_err(inode->i_sb, "unknown type %u @ lcn %llu of nid %llu", @@ -469,8 +471,7 @@ static int z_erofs_get_extent_decompress return -EOPNOTSUPP; } lcn += m->delta[1]; - } while (m->delta[1]); - + } map->m_llen = (lcn << lclusterbits) + m->clusterofs - map->m_la; return 0; }