From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD89DC4167B for ; Wed, 28 Dec 2022 15:21:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233760AbiL1PVf (ORCPT ); Wed, 28 Dec 2022 10:21:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233720AbiL1PVS (ORCPT ); Wed, 28 Dec 2022 10:21:18 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA06214033 for ; Wed, 28 Dec 2022 07:21:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6D9A3B8170E for ; Wed, 28 Dec 2022 15:21:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9DB8C433EF; Wed, 28 Dec 2022 15:21:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1672240874; bh=oAFmwgTa0iWjrNoNZpBerzG958B+wbIs72xunWuwJbc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P/I6xU0mSbNVI70Uqg3Rrbsou48mAnIpXf5i60r+Tj/ALkDd3eD1tLYgbXvjvzqmW 270Rs+TcmaYDtCfuckV7TquMmKVWwdC7gw7dtyUx3/OzNYSFWgew692hj8EodAWFcA laRcq69mw4pm5xJoi04+/tGt71+rZOu1Mf140YkM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+2ae90e873e97f1faf6f2@syzkaller.appspotmail.com, Chao Yu , Gao Xiang , Sasha Levin Subject: [PATCH 6.1 0177/1146] erofs: validate the extent length for uncompressed pclusters Date: Wed, 28 Dec 2022 15:28:36 +0100 Message-Id: <20221228144334.963687449@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221228144330.180012208@linuxfoundation.org> References: <20221228144330.180012208@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gao Xiang [ Upstream commit c505feba4c0d76084e56ec498ce819f02a7043ae ] syzkaller reported a KASAN use-after-free: https://syzkaller.appspot.com/bug?extid=2ae90e873e97f1faf6f2 The referenced fuzzed image actually has two issues: - m_pa == 0 as a non-inlined pcluster; - The logical length is longer than its physical length. The first issue has already been addressed. This patch addresses the second issue by checking the extent length validity. Reported-by: syzbot+2ae90e873e97f1faf6f2@syzkaller.appspotmail.com Fixes: 02827e1796b3 ("staging: erofs: add erofs_map_blocks_iter") Reviewed-by: Chao Yu Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20221205150050.47784-2-hsiangkao@linux.alibaba.com Signed-off-by: Sasha Levin --- fs/erofs/zmap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index f49295b9f2e1..e6d5d7a18fb0 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -698,6 +698,11 @@ static int z_erofs_do_map_blocks(struct inode *inode, } if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN) { + if (map->m_llen > map->m_plen) { + DBG_BUGON(1); + err = -EFSCORRUPTED; + goto unmap_out; + } if (vi->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER) map->m_algorithmformat = Z_EROFS_COMPRESSION_INTERLACED; -- 2.35.1