Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1554746rwb; Thu, 1 Dec 2022 20:11:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf4kr+U2OqC5PVL97GclGiSmNSAM73Oi3x+GeCIrtBQFUOll/Dor8gn/x0w2Cjd9V/dzgeDn X-Received: by 2002:a17:906:8156:b0:7c0:8fe9:cd0a with SMTP id z22-20020a170906815600b007c08fe9cd0amr12172517ejw.348.1669954280215; Thu, 01 Dec 2022 20:11:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669954280; cv=none; d=google.com; s=arc-20160816; b=upQNN7F5rF/3MIh/X9EAtZpX3ZU5YxY57p0KnmTqPxdgSK3T74ELyhsw+DcNFks9gv eS7Zmc/OSbUj6QUBEorxWVHv17jndaJT5txMWDDiLibhq5n2HU4C4C5SCTY73A36G2su 094lKssOnYs9ZK/5wy/3cE+Josii3TqDKoLNMnrLGB3Ij1rJrT0puFeWQ7PrFBSYTOAu 7wQGtlZo0HGfjPwGe9P+UfbNZOOjchyc1tsvm2ctBlnLssNl1E/SNl88WbktDuMUF4uX w80zuEVLxjiqWjDi5E2zYkTZ+RezqsXNribNLVjqyZmDR9eeyu+LiU+XDD6/QkCL13sU 9zsQ== 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 :message-id:date:subject:cc:to:from; bh=qU8p20n+Ei+ygLlRNm26/PKBI/yoAd1KvvxOjaF+6mQ=; b=yd30yNDlmMb0KlW9HpkN6bVG1j8uvv0DiPur4BuJDOnyL+qVOdwBz3OgjKtwLDgx4u YieJkbhN7mvOePzPmOpsKGG1pqcIlQGkbKwAKfQ3dwQMbTVVM0ABzbKW2++X+YczOj6I uuAjK5jI3AvLdWZQ0ZiWpFuxfnr+u80mBlxOwtx1Ef3jim8Xw6pL5lwsUkoJr56t8SE7 XHW0WtsCf7/irM4Aj7oCcAvHMN1PXxzn0QpeRj5korJw82vI/TbBh9o7438asVYRtT03 eeLosgBooxUzrZTt0nARjeL9pmax1vBBH9ndFN3iCG07V6qbIoLck5Vpe7Ffg0I47q9p ws/g== 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 i5-20020a05640242c500b00469572f4937si6378342edc.374.2022.12.01.20.11.00; Thu, 01 Dec 2022 20:11:20 -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 S232118AbiLBDgj (ORCPT + 81 others); Thu, 1 Dec 2022 22:36:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232129AbiLBDgU (ORCPT ); Thu, 1 Dec 2022 22:36:20 -0500 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D81AEDC4C3 for ; Thu, 1 Dec 2022 19:33:43 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VWB6jkA_1669952008; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VWB6jkA_1669952008) by smtp.aliyun-inc.com; Fri, 02 Dec 2022 11:33:41 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Yue Hu , Chao Yu Cc: LKML , Gao Xiang , syzbot+6f8cd9a0155b366d227f@syzkaller.appspotmail.com, Yue Hu Subject: [PATCH] erofs: fix inline pcluster memory leak Date: Fri, 2 Dec 2022 11:33:27 +0800 Message-Id: <20221202033327.52702-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 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 Inline pcluster should be freed right after it is decompressed. Otherwise inline pclusters will be leaked. Reported-by: syzbot+6f8cd9a0155b366d227f@syzkaller.appspotmail.com Fixes: cecf864d3d76 ("erofs: support inline data decompression") Cc: Yue Hu Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index ab22100be861..e14e6c32e70d 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -496,7 +496,8 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe) struct erofs_workgroup *grp; int err; - if (!(map->m_flags & EROFS_MAP_ENCODED)) { + if (!(map->m_flags & EROFS_MAP_ENCODED) || + !(map->m_pa >> PAGE_SHIFT)) { DBG_BUGON(1); return -EFSCORRUPTED; } @@ -1114,6 +1115,8 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be, /* pcluster lock MUST be taken before the following line */ WRITE_ONCE(pcl->next, Z_EROFS_PCLUSTER_NIL); mutex_unlock(&pcl->lock); + if (z_erofs_is_inline_pcluster(pcl)) + z_erofs_free_pcluster(pcl); return err; } -- 2.24.4