Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6071650rwb; Mon, 5 Dec 2022 07:38:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf6GUEexcCIbobW5kMU5w4Adu3fsB3PBe7B80DxtwhbJYsfDAfaRzZpW8ndqNstz71u3ZdMp X-Received: by 2002:a17:907:9c0a:b0:7ae:1e53:8dd4 with SMTP id ld10-20020a1709079c0a00b007ae1e538dd4mr27186797ejc.42.1670254726388; Mon, 05 Dec 2022 07:38:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670254726; cv=none; d=google.com; s=arc-20160816; b=Oz8LjbIbXRfHTB10gozRbR1JTZ/gOL8HnJ5ZGoihkXkJM8nvKw3pcm5LTA4RLJSpmh /hkNmB8yCqQC0qOGdymUKrmnMpIXWeCNmSZtSKodEmpSq5GN0vOJIzGeX84VSFFaK0U5 pfZDGmLUC/7TnxV8kQQCzi6fX/nJjMFSb6ZBSUACra6BXvPS0AY/80oNL+h9csi9DhYc t4avbJPm0fL9QxJeUa7cxDHY/QyVYI4GRnBKpynRB6Sd0Ax5Htz5oaOPGDQG4IR5WCFH sQeml9BZQQQ/6YNXlR7ikYeS6p2K2cRwBZ32pC5hw+D6QVo/yIO97ISUVrr+9K0VI04s Sc/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xD7f8lnicWaGRodZ3XHs72LXWQ5rJ87fEHJyOndcnPU=; b=XoRz0cQCV4KQdAzjfRAGTXHrdRcmjF/7Jjpzpr7k2umIvPC6AgzkzB/Klj0SfJFxkq LnR8f2lU3DOPNrR6A8XKlHrT2qLA1OJjKj+enwVh67x5TCW/0uI4mczPRwX4icwStgFH WwK7ANivMrJd4ScqV0J/vEHr7wx6tqQ5kpKimUlKhTWnjrtNvngBzcz854bdJXU9jp19 Mi/UNEYBOaSyEo/B/xGD+X4kPDZ/VQ/Gp+ecxURP4gHxVaIgjlqGmFyDL+D2Sx94zsl0 LuAj84KI73EZcBdaH7PqQ0hwhk6f7BIv8ll4us25h0HgWlSu2UCyLyCr2jg7+mET3bRL PRng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a1709063c4600b007c0baa5000csi2280014ejg.340.2022.12.05.07.38.26; Mon, 05 Dec 2022 07:38:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231960AbiLEPBW (ORCPT + 81 others); Mon, 5 Dec 2022 10:01:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232341AbiLEPBD (ORCPT ); Mon, 5 Dec 2022 10:01:03 -0500 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F0A11D0FD for ; Mon, 5 Dec 2022 07:01:01 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R321e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=hsiangkao@linux.alibaba.com;NM=0;PH=DS;RN=5;SR=0;TI=SMTPD_---0VWWWV0Z_1670252457; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VWWWV0Z_1670252457) by smtp.aliyun-inc.com; Mon, 05 Dec 2022 23:00:58 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang , syzbot+2ae90e873e97f1faf6f2@syzkaller.appspotmail.com Subject: [PATCH 2/2] erofs: validate the extent length for uncompressed pclusters Date: Mon, 5 Dec 2022 23:00:50 +0800 Message-Id: <20221205150050.47784-2-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20221205150050.47784-1-hsiangkao@linux.alibaba.com> References: <20221205150050.47784-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Signed-off-by: Gao Xiang --- fs/erofs/zmap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 98eff1259de4..0150570c33aa 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.24.4