From nobody Sat Feb 7 17:04:31 2026 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 D74CE395257 for ; Tue, 3 Feb 2026 08:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770106616; cv=none; b=r7ukYNiB5pmvpit/c2ObtMXb7FIFH+Xqppn8Gx8nlYjusXUPiVLL1L/FIu8QNHBUIzRiRlQxO9xxk4EGwg0xdB/YDPzQGNMjSfKcI1/Ggcs1vxihufNixM0mMnz/MV3wzvexZn2EHLaQJJWLS8TSDBSpzrRgI3WEjildGU8iBfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770106616; c=relaxed/simple; bh=uoaW/GbKMTCzuhUo7n1z6MW5aLYf4gS9FeQ448+bkSY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NCmYajwCMLu3ZP7Eaq/ObJKbtTutljMJY+zjiov5Er7eVSmrMg7NNyxv5XgQ306AAaXeqXAh3rxYGAOpd9IvJLuMzEX7VmoDZ+NzIvhgylxPeJc+h8skfNqd38U7EJWWwgg5tsorGY9ZrUCA8G4q+DK3Iwvz6K21PhRsPqX3wB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=OeUNZSgl; arc=none smtp.client-ip=115.124.30.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="OeUNZSgl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1770106609; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=ZYEgjxmJ3iIFuceax46uWWA5yrD+Novk/fxD9M513G4=; b=OeUNZSglJ7Gzct02bDbrqK9Ii2Er7PS0zHnHRzIFtWO1zzGFYik/gP0I3UNLkHgI6BAAZXt7t1rmLrN9qB01tCbom2g7aX2Tzs+89nfAEiyfdYxuTn/zTp4RhVjlBZSxuSrKRWAS6LxQ++NNjlOwERTha/TRN7WEJZ8MElrUE4o= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WySLkKC_1770106604 cluster:ay36) by smtp.aliyun-inc.com; Tue, 03 Feb 2026 16:16:48 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , oliver.yang@linux.alibaba.com, Gao Xiang , Zhiguo Niu Subject: [PATCH] erofs: fix inline data read failure for ztailpacking pclusters Date: Tue, 3 Feb 2026 16:16:43 +0800 Message-ID: <20260203081643.954474-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Compressed folios for ztailpacking pclusters must be valid before adding these pclusters to I/O chains. Otherwise, z_erofs_decompress_pcluster() may assume they are already valid and then trigger a NULL pointer dereference. It is somewhat hard to reproduce because the inline data is in the same block as the tail of the compressed indexes, which are usually read just before. However, it may still happen if a fatal signal arrives while read_mapping_folio() is running, as shown below: erofs: (device dm-1): z_erofs_pcluster_begin: failed to get inline data -4 Unable to handle kernel NULL pointer dereference at virtual address 000000= 0000000008 ... pc : z_erofs_decompress_queue+0x4c8/0xa14 lr : z_erofs_decompress_queue+0x160/0xa14 sp : ffffffc08b3eb3a0 x29: ffffffc08b3eb570 x28: ffffffc08b3eb418 x27: 0000000000001000 x26: ffffff8086ebdbb8 x25: ffffff8086ebdbb8 x24: 0000000000000001 x23: 0000000000000008 x22: 00000000fffffffb x21: dead000000000700 x20: 00000000000015e7 x19: ffffff808babb400 x18: ffffffc089edc098 x17: 00000000c006287d x16: 00000000c006287d x15: 0000000000000004 x14: ffffff80ba8f8000 x13: 0000000000000004 x12: 00000006589a77c9 x11: 0000000000000015 x10: 0000000000000000 x9 : 0000000000000000 x8 : 0000000000000000 x7 : 0000000000000000 x6 : 000000000000003f x5 : 0000000000000040 x4 : ffffffffffffffe0 x3 : 0000000000000020 x2 : 0000000000000008 x1 : 0000000000000000 x0 : 0000000000000000 Call trace: z_erofs_decompress_queue+0x4c8/0xa14 z_erofs_runqueue+0x908/0x97c z_erofs_read_folio+0x128/0x228 filemap_read_folio+0x68/0x128 filemap_get_pages+0x44c/0x8b4 filemap_read+0x12c/0x5b8 generic_file_read_iter+0x4c/0x15c do_iter_readv_writev+0x188/0x1e0 vfs_iter_read+0xac/0x1a4 backing_file_read_iter+0x170/0x34c ovl_read_iter+0xf0/0x140 vfs_read+0x28c/0x344 ksys_read+0x80/0xf0 __arm64_sys_read+0x24/0x34 invoke_syscall+0x60/0x114 el0_svc_common+0x88/0xe4 do_el0_svc+0x24/0x30 el0_svc+0x40/0xa8 el0t_64_sync_handler+0x70/0xbc el0t_64_sync+0x1bc/0x1c0 Fix this by reading the inline data before allocating and adding the pclusters to the I/O chains. Fixes: cecf864d3d76 ("erofs: support inline data decompression") Reported-by: Zhiguo Niu Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 20d7df31a51f..3b6d078c5ba3 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -806,14 +806,27 @@ static int z_erofs_pcluster_begin(struct z_erofs_fron= tend *fe) struct erofs_map_blocks *map =3D &fe->map; struct super_block *sb =3D fe->inode->i_sb; struct z_erofs_pcluster *pcl =3D NULL; - void *ptr; + void *ptr =3D NULL; int ret; =20 DBG_BUGON(fe->pcl); /* must be Z_EROFS_PCLUSTER_TAIL or pointed to previous pcluster */ DBG_BUGON(!fe->head); =20 - if (!(map->m_flags & EROFS_MAP_META)) { + if (map->m_flags & EROFS_MAP_META) { + ret =3D erofs_init_metabuf(&map->buf, sb, + erofs_inode_in_metabox(fe->inode)); + if (ret) + return ret; + ptr =3D erofs_bread(&map->buf, map->m_pa, false); + if (IS_ERR(ptr)) { + erofs_err(sb, "failed to read inline data %pe @ pa %llu of nid %llu", + ptr, map->m_pa, EROFS_I(fe->inode)->nid); + return PTR_ERR(ptr); + } + folio_get(page_folio(map->buf.page)); + ptr =3D map->buf.page; + } else { while (1) { rcu_read_lock(); pcl =3D xa_load(&EROFS_SB(sb)->managed_pslots, map->m_pa); @@ -853,18 +866,7 @@ static int z_erofs_pcluster_begin(struct z_erofs_front= end *fe) /* bind cache first when cached decompression is preferred */ z_erofs_bind_cache(fe); } else { - ret =3D erofs_init_metabuf(&map->buf, sb, - erofs_inode_in_metabox(fe->inode)); - if (ret) - return ret; - ptr =3D erofs_bread(&map->buf, map->m_pa, false); - if (IS_ERR(ptr)) { - ret =3D PTR_ERR(ptr); - erofs_err(sb, "failed to get inline folio %d", ret); - return ret; - } - folio_get(page_folio(map->buf.page)); - WRITE_ONCE(fe->pcl->compressed_bvecs[0].page, map->buf.page); + WRITE_ONCE(fe->pcl->compressed_bvecs[0].page, ptr); fe->pcl->pageofs_in =3D map->m_pa & ~PAGE_MASK; fe->mode =3D Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE; } --=20 2.43.5