Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7577224rwb; Tue, 6 Dec 2022 07:26:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf7N8yRghCns1LgzRsM3MZyjk6YzRzPk7J2HHsm6KqOGbl5URajbPwyJueD6K1x5q81ql6yS X-Received: by 2002:a17:903:291:b0:186:994b:5b55 with SMTP id j17-20020a170903029100b00186994b5b55mr33447348plr.100.1670340364244; Tue, 06 Dec 2022 07:26:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670340364; cv=none; d=google.com; s=arc-20160816; b=rWNtcxhisr2kEPDfyiac21UbZei02BemtKuNQ3rfSLhzDS/BX8Dc2rMap8+RoTlaug 4wUCZ7o22UDNhe8SiNR+03sOjvnKseplwHiWxnwTHFU/K1KQ64q8Em0juzXJVRtlrQ71 7Pm1fu+Krv8UVRxSGVyij8KfnQICPdFFDtPlnU0Lf+PKU/FmxKWJQcb7OzxlbjvQbBvQ BFKE9Scdmnq+K5sxcAFKCxfnb1k1ai3mqPphZM008b/JrnhFUsRJSuomITbTxUVD6PaI 7CPCdEF0SjrDSg85IgIfxH4NyXUubTwfkqduOHmHdoSxlQPdbPcYfjBOn+rjWsIX2U5S e+Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=0hjKLCaMOu5QeN8sr2pHIYzwG4dvWgr7iy+hS/R7Tf8=; b=KcH44HyU+rmPFI0FF1AXnbh+PlJt559mHV7bY2Rpy2oxuh7HizsXLTOYgOyq98pU0G ieGeIMAX2vU5y3H/U13Poih2BgW1G1tkRqFFTKRafFfnOzJd4YICTVL4RlExLMGeeG+q Wk7kN9AqDunkjOwQ3HgVKBaPC2my1VVhvy4DfG7ueXUlWO32b2NWeo8HUbIib+AQc1GE fh2dJCt1dFB1eqvnfg1vGx9UN4NrpvHjNjPKBH11KWVj8mluoUIO0VkqEKkgJ2MFW+Wp Qon2miqi23diDKHKCqMJexyrKZO1aYsNBBv6gn2elf0ujh1FNN8gIgX8JQfdQrsqANFy Q2YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MIYdA8N3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x2-20020a056a00188200b0054252c63d75si19559284pfh.98.2022.12.06.07.25.52; Tue, 06 Dec 2022 07:26:04 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MIYdA8N3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232198AbiLFPLF (ORCPT + 78 others); Tue, 6 Dec 2022 10:11:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232046AbiLFPKm (ORCPT ); Tue, 6 Dec 2022 10:10:42 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 432C2B64 for ; Tue, 6 Dec 2022 07:07:36 -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 dfw.source.kernel.org (Postfix) with ESMTPS id F14D861785 for ; Tue, 6 Dec 2022 15:07:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FA27C43148; Tue, 6 Dec 2022 15:07:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670339231; bh=Ob5V/tXbNKgT/KoriEtKPMuFGstfF4RJaAV5mgAFA/s=; h=Date:Subject:To:References:From:In-Reply-To:From; b=MIYdA8N3D4tUbrP7PFSPc4eF4CWQTrNDFGIiJNjLRkGsftrTKeK2fkL/Fe4UKLNHq miyEydnH5QYTrljdLUQWHA7FXr0683GhQvYEksBSvU6sPgEYThnDbUJJIhVgD7aOWM dCp5Ym4MCzQ3aTaGv8+hrj1umcpOru/jggGf1jKvGvkDEFkcelPiRUXLZclsqtSLjr 6DzOVAAZLl1ReZZB5ZPH+6zb1unNcKu62bI0QzU7PzEtu8Rz/tgTXezMadMolX/chM HNfSIse9tUew1zmIk7ApHQajmpTNehjvvuydRPm1lySz5mHCt8PhPQFaHktj+tSV4T +/VRNve91V2Dg== Message-ID: <1022b823-b0a7-0afa-bb88-954182e372cf@kernel.org> Date: Tue, 6 Dec 2022 23:07:07 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH -next v3] erofs: Fix pcluster memleak when its block address is zero Content-Language: en-US To: Chen Zhongjin , huyue2@coolpad.com, syzbot+6f8cd9a0155b366d227f@syzkaller.appspotmail.com, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, xiang@kernel.org, jefflexu@linux.alibaba.com References: <20221205034957.90362-1-chenzhongjin@huawei.com> From: Chao Yu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 On 2022/12/5 14:08, Gao Xiang wrote: > Hi all, > > On Mon, Dec 05, 2022 at 11:49:57AM +0800, Chen Zhongjin wrote: >> syzkaller reported a memleak: >> https://syzkaller.appspot.com/bug?id=62f37ff612f0021641eda5b17f056f1668aa9aed >> >> unreferenced object 0xffff88811009c7f8 (size 136): >> ... >> backtrace: >> [] z_erofs_do_read_page+0x99b/0x1740 >> [] z_erofs_readahead+0x24e/0x580 >> [] read_pages+0x86/0x3d0 >> ... >> >> syzkaller constructed a case: in z_erofs_register_pcluster(), >> ztailpacking = false and map->m_pa = zero. This makes pcl->obj.index be >> zero although pcl is not a inline pcluster. >> >> Then following path adds refcount for grp, but the refcount won't be put >> because pcl is inline. >> >> z_erofs_readahead() >> z_erofs_do_read_page() # for another page >> z_erofs_collector_begin() >> erofs_find_workgroup() >> erofs_workgroup_get() >> >> Since it's illegal for the block address of a pcluster to be zero, add >> check here to avoid registering the pcluster which would be leaked. >> >> Fixes: cecf864d3d76 ("erofs: support inline data decompression") >> Reported-by: syzbot+6f8cd9a0155b366d227f@syzkaller.appspotmail.com >> Signed-off-by: Chen Zhongjin >> --- >> v1 -> v2: >> As Gao's advice, we should fail to register pcluster if m_pa is zero. >> Maked it this way and changed the commit message. >> >> v2 -> v3: >> Slightly fix commit message and add -next tag. > > I've updated the patch itself as below > (Since we only need to fail out for non-tailpacking cases, tailpacking > inline inodes could still have m_pa < EROFS_BLKSIZ): > > From f5e037e760d338ca0c116e507be663cb843d42f0 Mon Sep 17 00:00:00 2001 > From: Chen Zhongjin > Date: Mon, 5 Dec 2022 11:49:57 +0800 > Subject: [PATCH] erofs: Fix pcluster memleak when its block address is zero > > syzkaller reported a memleak: > https://syzkaller.appspot.com/bug?id=62f37ff612f0021641eda5b17f056f1668aa9aed > > unreferenced object 0xffff88811009c7f8 (size 136): > ... > backtrace: > [] z_erofs_do_read_page+0x99b/0x1740 > [] z_erofs_readahead+0x24e/0x580 > [] read_pages+0x86/0x3d0 > ... > > syzkaller constructed a case: in z_erofs_register_pcluster(), > ztailpacking = false and map->m_pa = zero. This makes pcl->obj.index be > zero although pcl is not a inline pcluster. > > Then following path adds refcount for grp, but the refcount won't be put > because pcl is inline. > > z_erofs_readahead() > z_erofs_do_read_page() # for another page > z_erofs_collector_begin() > erofs_find_workgroup() > erofs_workgroup_get() > > Since it's illegal for the block address of a non-inlined pcluster to > be zero, add check here to avoid registering the pcluster which would > be leaked. > > Fixes: cecf864d3d76 ("erofs: support inline data decompression") > Reported-by: syzbot+6f8cd9a0155b366d227f@syzkaller.appspotmail.com > Signed-off-by: Chen Zhongjin > Reviewed-by: Yue Hu > Reviewed-by: Gao Xiang > Signed-off-by: Gao Xiang Reviewed-by: Chao Yu Thanks,