Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1104635pxa; Thu, 20 Aug 2020 02:35:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxclOo5/+DVxjtBhEZhn7dbbcQy5naIs9/kIL7w+G0qunqMo6dX6rheSFq6Un/b0jVKZxel X-Received: by 2002:aa7:c246:: with SMTP id y6mr2114841edo.78.1597916122281; Thu, 20 Aug 2020 02:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597916122; cv=none; d=google.com; s=arc-20160816; b=Yj2hfSAtkZERZP+aseHtnJN6g/Wi3qC5QBJP4VxY9c/7gr0lXW/c9FLxBABOJmsGw9 9lIhbE6TREt0Rer3NwKjHyzvaE6cGNurxssaGY9+ZZKJZk4Viq5rZpneXMWFzrS+T5vp +G/Zvhkeq1wz1+nXM/Y2Lc8uqiYKqkWVdIblq7JF8tbfz5+onCua8iYg8Y/hUetDwlBt hz5erzNHn7+OpPNtbrm/JURZBxmgCd5n8m04BsP/bUozEs0MddaFgkdlMxLp7qcXdZGT DxjaQwmBK1gUGPkCzuUVQrd6/HBjE9wU3FWpkuuyD0wx8i//3y0G2dThFG+zDdpV6bNL TQ6w== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IwEmokqR4CCR2auyfpU/oBn62J12BLshQSVhcjDmvzM=; b=cp3zKTHCwl9g2llZI2FAHYYbkTVJmQaaeuYJ56Mbf9bpcu7bNFH4K+NWH7/FfDtDY9 +VCZYO2/PgMSQUbiGLnYPMzhpBcmeo2//x2dMUvogurkk9+WiBnoudXy5lp7laL6ja5e JdKDEHinvAFrhdkITumH17Vn3Q4EuZThuZn/0qkUKyFyUoz3BCbIMshU6r6NDzf1+hgL WIgciDNY1HL8skbnxNYTgvBPsyA9NiAMsIhRKYjlI7Cjwnc/z+3IMQ4pJzP/KvDPupOm Ld+wkTWRWFvSv4UbXWMO5ZuMAw3KagYY9iYFaAZLf1ivlAOJmYXMBNQnb4ZItNEA8zpR 7pyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jHg4W3l6; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si1035288edy.473.2020.08.20.02.34.58; Thu, 20 Aug 2020 02:35:22 -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; dkim=pass header.i=@kernel.org header.s=default header.b=jHg4W3l6; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728327AbgHTJeU (ORCPT + 99 others); Thu, 20 Aug 2020 05:34:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:43094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728236AbgHTJbi (ORCPT ); Thu, 20 Aug 2020 05:31:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9337122B3F; Thu, 20 Aug 2020 09:31:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915898; bh=wp8G5LoikT6tMvWTrOAsmUvkum57qThOs0SmGsnDMmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHg4W3l6z93G80sxfHYFssGiWTOf3pRCVpzsSvJJ+mbowONt1j7a8A6MXS4iME8eC wCz2rMzYrPi3ocl34AOQn9vWdzMwLTpWYnvYpMbZNB1fuXpzVCc0C31nQcxdOURNDa QkbI3mgPQugCXO42e1tMkmcEfbT24rW2TH6x3U7E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhihao Cheng , Sascha Hauer , syzbot+d9aab50b1154e3d163f5@syzkaller.appspotmail.com, Richard Weinberger , Sasha Levin Subject: [PATCH 5.8 174/232] ubi: fastmap: Dont produce the initial next anchor PEB when fastmap is disabled Date: Thu, 20 Aug 2020 11:20:25 +0200 Message-Id: <20200820091621.246072260@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhihao Cheng [ Upstream commit 3b185255bb2f34fa6927619b9ef27f192a3d9f5a ] Following process triggers a memleak caused by forgetting to release the initial next anchor PEB (CONFIG_MTD_UBI_FASTMAP is disabled): 1. attach -> __erase_worker -> produce the initial next anchor PEB 2. detach -> ubi_fastmap_close (Do nothing, it should have released the initial next anchor PEB) Don't produce the initial next anchor PEB in __erase_worker() when fastmap is disabled. Signed-off-by: Zhihao Cheng Suggested-by: Sascha Hauer Fixes: f9c34bb529975fe ("ubi: Fix producing anchor PEBs") Reported-by: syzbot+d9aab50b1154e3d163f5@syzkaller.appspotmail.com Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin --- drivers/mtd/ubi/wl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 27636063ed1bb..42cac572f82dc 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c @@ -1086,7 +1086,8 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk) if (!err) { spin_lock(&ubi->wl_lock); - if (!ubi->fm_next_anchor && e->pnum < UBI_FM_MAX_START) { + if (!ubi->fm_disabled && !ubi->fm_next_anchor && + e->pnum < UBI_FM_MAX_START) { /* Abort anchor production, if needed it will be * enabled again in the wear leveling started below. */ -- 2.25.1