Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1143193ybg; Tue, 2 Jun 2020 02:25:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwI4Mwvs7igUOwh5WOWu2+wnwYEfT//thabNTsr4hR5Yau9AlqGraW6uiXhWl9Ye+g2I7r2 X-Received: by 2002:a17:906:33c9:: with SMTP id w9mr22169839eja.284.1591089955542; Tue, 02 Jun 2020 02:25:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591089955; cv=none; d=google.com; s=arc-20160816; b=Yqfn3LaOLRHWGPp0EzXcnQD3MfNsfyHrs15PehIBTQFjB9Cm/smNCUEzifAdbkGmC3 0tREuGK2P8OZY3uO1c8ytHutFj97IW6MLZ5rTOKcen5ZhCjL7AZ8IwdMjSPr3T+xF6Xm GP//plc3ajmFGKrFQr0MmQgqB8/RzvM7AsmLUvPDV0s+It1JhD56xWmHcmvbVn9eZ5UZ fptgZ/GmayIPpZxXn+ml8dhu6fQTpN4/iKKwM8oaZYs0zodgPkCZfwIRWM2tAhswyo1H V+8IR1RBp91HgZsBNSy/r5Gfew0O/sF2JvTsgUATdlxorRYoWAjpbNm03ZpVc8NVhfMw 4/cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=WdPKWQ69dvOHnnNR7zB/9tWlFYK18LHYLrj7x5PzwJY=; b=AazC7LBxSvp/S3HAJQtsKoeWsHta0kZNSoH8QnCR7cUq9JDpu3v8Trjy2WP7bn9Rq2 S7noE3fSaZM5I0lJJOIutVB2tYJmzz/l1RbaG9bsD6SnsOHaJ6XAT2CEfu6YYDxme3f3 4U3gaPoc4sL6eXn2c99mrAHv1vT430jm+yFgsNbfbwQN4ZPPEtmSpaqUmY4FztRUssmk pGgOuANrry0mB0yi7n4hb5Mj2iFNxAwOy05epMrxhZUHQX/ALiVcTGf46TKAOOGs1AnO ibx8y0/jK1FwdpHtzz2sl5NdDp8YZSmfFWTblptHQBL4fIuVstL9CiG93TkxxYyJxhim Y/Nw== 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 w23si1158302edv.71.2020.06.02.02.25.32; Tue, 02 Jun 2020 02:25:55 -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 S1726580AbgFBJXu (ORCPT + 99 others); Tue, 2 Jun 2020 05:23:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726160AbgFBJXt (ORCPT ); Tue, 2 Jun 2020 05:23:49 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91FB9C061A0E for ; Tue, 2 Jun 2020 02:23:49 -0700 (PDT) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jg39A-0005ra-3Z; Tue, 02 Jun 2020 11:23:48 +0200 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1jg398-0002X0-Ul; Tue, 02 Jun 2020 11:23:46 +0200 Date: Tue, 2 Jun 2020 11:23:46 +0200 From: Sascha Hauer To: Zhihao Cheng Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, richard@nod.at, yi.zhang@huawei.com Subject: Re: [PATCH] ubi: fastmap: Don't produce the initial anchor PEB when fastmap is disabled Message-ID: <20200602092346.GK11869@pengutronix.de> References: <20200601091134.3794265-1-chengzhihao1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200601091134.3794265-1-chengzhihao1@huawei.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 11:00:25 up 103 days, 16:30, 118 users, load average: 0.77, 0.35, 0.25 User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |