Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1209578ybg; Tue, 2 Jun 2020 04:17:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF5zvg9+2AEkGSNJRkrokyJPba+mZa+clxyRKe9k9dmnwGZg2R6yt+JsPL8jnklM4VSSkd X-Received: by 2002:a17:906:454b:: with SMTP id s11mr5965649ejq.546.1591096621130; Tue, 02 Jun 2020 04:17:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591096621; cv=none; d=google.com; s=arc-20160816; b=JB8dlo5hBKW77NQ+3u3yJzRRFzvIFlZgZISirNmrw/i36HdgijtOfaIzXEv4ty2T7J bR2UQN+PUqlEVFtsWmTE5EM1m3zVKs5kKQN8pLYHa90Wc9oR54Qp6wULGv/MAs9A4/Qj MieS20GXhY6Oh9SAja4XuCevBxmdbd3ocmpJTCNhJ6tfCFQRKqirL7yt7AFIVQqlydyU 9sZEeeDVbg7cPFnQosNv6YDKh7CmKnTY+aeozAl9pIs5p9Oq0nDgVe0XXqGh8c21ta14 qDprzA772HNyL07eQ1iKu7nsWMbJb4L5CSI1a6XFltQniyKJK7v1KCfrN66dRAloPQ2W fLCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=btHFuk+Jwk9hX3hIEyUHZhOkZ14ko8bqilMx734t3yM=; b=Oa7BXvkcT+Mxs+CLjt2/dbUE8rgeYKR410Rf1nPlMkrjsiDzhkVAzRC80xBYwYCF6P OTlXgcPutjRLhBh39+k30XXb02NC53xSuLRK99pYkR4gVTCQkF9/FH1rPa8xc/vgvFXG TOsGTVbxwU+40HnH73erDiYbUw3DUP6Tq3kPJ0WToWqX/isKp/bXZvv8HiahgIkWpU6I vBIk+b0aS1Q1zwXeZTikIsOhiJzqcBGjbyNLoAHPjkAEM8CMt7AvK3ABPKYoIOH7mD2e /2XTGDwc5FKS/gh8S/H6W7S/EIqLsEpX8H+pGehclCsQtmxq+xlhVPfikb5n2DAo4Lfp inng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id du22si1522374ejc.330.2020.06.02.04.16.37; Tue, 02 Jun 2020 04:17:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbgFBLLi (ORCPT + 99 others); Tue, 2 Jun 2020 07:11:38 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5332 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725919AbgFBLLi (ORCPT ); Tue, 2 Jun 2020 07:11:38 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 5220A24BEFBA87BEF44D; Tue, 2 Jun 2020 19:11:35 +0800 (CST) Received: from [127.0.0.1] (10.166.213.18) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Tue, 2 Jun 2020 19:11:26 +0800 Subject: Re: [PATCH] ubi: fastmap: Don't produce the initial anchor PEB when fastmap is disabled To: Sascha Hauer CC: , , , References: <20200601091134.3794265-1-chengzhihao1@huawei.com> <20200602092346.GK11869@pengutronix.de> From: Zhihao Cheng Message-ID: Date: Tue, 2 Jun 2020 19:11:26 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200602092346.GK11869@pengutronix.de> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.166.213.18] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2020/6/2 17:23, Sascha Hauer ะด??: > Hi, > > On Mon, Jun 01, 2020 at 05:11:34PM +0800, Zhihao Cheng wrote: >> Following process triggers a memleak caused by forgetting to release the >> initial anchor PEB (CONFIG_MTD_UBI_FASTMAP is disabled): >> 1. attach -> __erase_worker -> produce the initial anchor PEB >> 2. detach -> ubi_fastmap_close (Do nothing, it should have released the >> initial anchor PEB) >> >> Don't produce the initial anchor PEB in __erase_worker() when fastmap >> is disabled. >> >> Signed-off-by: Zhihao Cheng >> Fixes: f9c34bb529975fe ("ubi: Fix producing anchor PEBs") >> Reported-by: syzbot+d9aab50b1154e3d163f5@syzkaller.appspotmail.com >> --- >> drivers/mtd/ubi/wl.c | 8 +++++++- >> 1 file changed, 7 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c >> index 5146cce5fe32..5ebe1084a8e7 100644 >> --- a/drivers/mtd/ubi/wl.c >> +++ b/drivers/mtd/ubi/wl.c >> @@ -1079,13 +1079,19 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk) >> if (!err) { >> spin_lock(&ubi->wl_lock); >> >> - if (!ubi->fm_anchor && e->pnum < UBI_FM_MAX_START) { >> +#ifdef CONFIG_MTD_UBI_FASTMAP >> + if (!ubi->fm_disabled && !ubi->fm_anchor && >> + e->pnum < UBI_FM_MAX_START) { > Rather than introducing another #ifdef you could do a > > if (IS_ENABLED(CONFIG_MTD_UBI_FASTMAP) && > !ubi->fm_disabled && !ubi->fm_anchor && > e->pnum < UBI_FM_MAX_START) > > And I am not sure if the IS_ENABLED(CONFIG_MTD_UBI_FASTMAP) is necessary > at all because we do a ubi->fm_disabled = 1 when fastmap is disabled. > > Regards, > Sascha > Agree.