From patchwork Tue Jan 10 07:49:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 41335 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2611112wrt; Mon, 9 Jan 2023 23:54:44 -0800 (PST) X-Google-Smtp-Source: AMrXdXvpZM0q3QuGWxSl3ru9KLmdnqs951pF+Q5bhiANXpDW6rOpq4RECpnkZvUsaVsJBmigOHJd X-Received: by 2002:a17:90b:1086:b0:227:13f3:cb6d with SMTP id gj6-20020a17090b108600b0022713f3cb6dmr6331739pjb.0.1673337284275; Mon, 09 Jan 2023 23:54:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673337284; cv=none; d=google.com; s=arc-20160816; b=CnjCMCV92EVv9a5UtsDCvUDKtBOKgg6tFPmnaNKJLKJhJI5d9gs5kHmHNOXtYQoEg7 ejqD/YMhTB5TEBQfGmWNS2RZzDlh2fApWq0hZQuuskAvHC6vRlXl0nZSO1k3uPl5v9/l KQsar/9I/qZymHI5Vl/h++JTbMbyevxv1nevzUu6G8nBb+6k0n/jQ+2n9AMj8nDj4Qmd Wowib2h7p/h7SrA4Y9FpnyjbXElprJRNlCqL6QIXTncXxNhf+J6xC96qWhwMBEEq38ul zOFOnMH0W2vKBKUFlseLGaAdEDpXtxN/NMDoC3ZCAMk0sZMtgFzOeMX3NKw5BHDnrV2Q n2lQ== 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=2IwXOapjDhHtyAaubvTO2KjhV6Sop5s+Gn6eMqlU4+g=; b=SRualn3WerR7/mi5QWu8YQnZuViekrU0XFB6gSz6r6ADwWQ+VC7aNJD8Pp2dq2mzZW yivPXvsOFNk65mydgAQa2PbuCjbXfk1wG9abbtzg5V6ZyNQXNz99ySRAjX5F7IxUUKpp Mn+zt4MxMwuA0m+IFXZ3Cl1NbxbuA3LEVFWUrVyG0x0XeKsPYtwPNI1JF+i1g7E0Rdqm fisr27rdvJpUN/7G1JtDlgxEun6O7iZGkNOqd7B51ULzLcfcnPTiojKUdY8BEZ0nHle+ aG4LtZhMeE4ATNSBKhmcfSpEhjZ/W/t8Shrjj9R6bv3x9mT3DtL8bV0A9mWaNd8+eme6 Vavw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rj4-20020a17090b3e8400b0021e41006030si11289781pjb.76.2023.01.09.23.54.31; Mon, 09 Jan 2023 23:54:44 -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 S237273AbjAJHtn (ORCPT + 99 others); Tue, 10 Jan 2023 02:49:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231349AbjAJHtm (ORCPT ); Tue, 10 Jan 2023 02:49:42 -0500 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A728178B2 for ; Mon, 9 Jan 2023 23:49:40 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R241e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VZIMt1I_1673336968; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VZIMt1I_1673336968) by smtp.aliyun-inc.com; Tue, 10 Jan 2023 15:49:37 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu , Yue Hu , Jeffle Xu Cc: LKML , Gao Xiang , syzbot+c3729cda01706a04fb98@syzkaller.appspotmail.com Subject: [PATCH v2] erofs: fix kvcalloc() misuse with __GFP_NOFAIL Date: Tue, 10 Jan 2023 15:49:27 +0800 Message-Id: <20230110074927.41651-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20230106031937.113318-1-hsiangkao@linux.alibaba.com> References: <20230106031937.113318-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754242219071741831?= X-GMAIL-MSGID: =?utf-8?q?1754621316098353916?= As reported by syzbot [1], kvcalloc() cannot work with __GFP_NOFAIL. Let's use kcalloc() instead. [1] https://lore.kernel.org/r/0000000000007796bd05f1852ec2@google.com Reported-by: syzbot+c3729cda01706a04fb98@syzkaller.appspotmail.com Fixes: fe3e5914e6dc ("erofs: try to leave (de)compressed_pages on stack if possible") Fixes: 4f05687fd703 ("erofs: introduce struct z_erofs_decompress_backend") Reviewed-by: Chao Yu Signed-off-by: Gao Xiang --- changes since v1: - should use kfree() instead of kvfree() as well (Chao); - add Chao's r-v-b. fs/erofs/zdata.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index ccf7c55d477f..5200bb86e264 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -1032,12 +1032,12 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be, if (!be->decompressed_pages) be->decompressed_pages = - kvcalloc(be->nr_pages, sizeof(struct page *), - GFP_KERNEL | __GFP_NOFAIL); + kcalloc(be->nr_pages, sizeof(struct page *), + GFP_KERNEL | __GFP_NOFAIL); if (!be->compressed_pages) be->compressed_pages = - kvcalloc(pclusterpages, sizeof(struct page *), - GFP_KERNEL | __GFP_NOFAIL); + kcalloc(pclusterpages, sizeof(struct page *), + GFP_KERNEL | __GFP_NOFAIL); z_erofs_parse_out_bvecs(be); err2 = z_erofs_parse_in_bvecs(be, &overlapped); @@ -1085,7 +1085,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be, } if (be->compressed_pages < be->onstack_pages || be->compressed_pages >= be->onstack_pages + Z_EROFS_ONSTACK_PAGES) - kvfree(be->compressed_pages); + kfree(be->compressed_pages); z_erofs_fill_other_copies(be, err); for (i = 0; i < be->nr_pages; ++i) { @@ -1104,7 +1104,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be, } if (be->decompressed_pages != be->onstack_pages) - kvfree(be->decompressed_pages); + kfree(be->decompressed_pages); pcl->length = 0; pcl->partial = true;