Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1514591ybb; Sat, 11 Apr 2020 05:23:30 -0700 (PDT) X-Google-Smtp-Source: APiQypKm9nmmz45w3T1lGPIY4+svMDTC9NXk+GmHklw9a/mgzqTtOA3YmdpM1MhQz+7bValgDY4z X-Received: by 2002:ac8:4519:: with SMTP id q25mr3419158qtn.13.1586607810837; Sat, 11 Apr 2020 05:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586607810; cv=none; d=google.com; s=arc-20160816; b=yvJnyzMK/CvA0W9sC1BZKTYa7Gt9XQ/A99kIc/M/yCdDaXNYwThIg9PiYOSGh92EjR kQPYF0ZT83w72wEIiAe+ZjTRrNi5iFuo9GiVK5+h9v8nE7scDqwCzdzV6FAMqjusizEV kAALPkUXaDvBZrpPOwEIwAAilWmzAsMnrNPiswGNX3Sop07ppB20gUhmOG1w10kf/HCH SV34D1JkDZBIjqWwYD/744aikCwi+/oKW8ijomR069s5PocvGrJtVZ65qjxTqfXGPrd4 zXWDV4GFBey73S+Ps1H7zjbOpEYNpsc5TdUBYluGrIK309DAcdzpIqBSUat3OfRp9ziG u4bw== 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=hfKhpaJwaVRS8uiqotrZloELVEfGBzfG/veKqhy72EI=; b=n82msepqfs2MC6okjGrHvSRvAn+ck6/6L5ua90TdyT/5nTxMgzYNlNwHpFOGIw1Ba0 I6GRXhMXOpn4D0mmy76KasNoV6XTgjk8my2UcXPRAPNQzE1pKibd37D/qMj2tuDeY9Yi jAwdEhQMhh7HA1dnYA/tI/L0jptLeuGs8M6ieHbiEqQj7XkBrQmmgp9N0ODZtxo3+/7U kNjdg2FpagWZ7oFzgUPQ4/aOXtnC9W2TU03/3ZyzwiaUl1AMVDVaLDnFYwTbzeeZ24Sb yY+oWxGMol7D86IejDskATJqBsRA+YLWKpD2PBeFyslKvn4/7OCMRZhID5ECJ5qK/Abj XGWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SQXZJcJr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n27si2856030qtb.257.2020.04.11.05.23.16; Sat, 11 Apr 2020 05:23:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SQXZJcJr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728943AbgDKMVS (ORCPT + 99 others); Sat, 11 Apr 2020 08:21:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:57402 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729141AbgDKMVN (ORCPT ); Sat, 11 Apr 2020 08:21:13 -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 D346D20644; Sat, 11 Apr 2020 12:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586607673; bh=Or4Wyj8G7lBylczIfcUvXgxxcqlhFGadGh2+Le/CxVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SQXZJcJrbNhEJikXNzhwI3rOp6ocVJW6jPhyJMjpY2ybMRN6ePHWwJ3iIfOIfnpp6 7g5RF4MGhFsgoCr2F5njEIs5aUwFOQnTSR6ay1ilCrbCv5i13VnHpiOtKYtLtj2NN0 vU06vwfW+dTIBvYJg+Ect5521tovY1B8fYjmyVjw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+f317896aae32eb281a58@syzkaller.appspotmail.com, Sascha Hauer , Hou Tao , Richard Weinberger Subject: [PATCH 5.6 29/38] ubi: fastmap: Free unused fastmap anchor peb during detach Date: Sat, 11 Apr 2020 14:10:06 +0200 Message-Id: <20200411115502.888317353@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200411115459.324496182@linuxfoundation.org> References: <20200411115459.324496182@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: Hou Tao commit c16f39d14a7e0ec59881fbdb22ae494907534384 upstream. When CONFIG_MTD_UBI_FASTMAP is enabled, fm_anchor will be assigned a free PEB during ubi_wl_init() or ubi_update_fastmap(). However if fastmap is not used or disabled on the MTD device, ubi_wl_entry related with the PEB will not be freed during detach. So Fix it by freeing the unused fastmap anchor during detach. Fixes: f9c34bb52997 ("ubi: Fix producing anchor PEBs") Reported-by: syzbot+f317896aae32eb281a58@syzkaller.appspotmail.com Reviewed-by: Sascha Hauer Signed-off-by: Hou Tao Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/ubi/fastmap-wl.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/drivers/mtd/ubi/fastmap-wl.c +++ b/drivers/mtd/ubi/fastmap-wl.c @@ -39,6 +39,13 @@ static struct ubi_wl_entry *find_anchor_ return victim; } +static inline void return_unused_peb(struct ubi_device *ubi, + struct ubi_wl_entry *e) +{ + wl_tree_add(e, &ubi->free); + ubi->free_count++; +} + /** * return_unused_pool_pebs - returns unused PEB to the free tree. * @ubi: UBI device description object @@ -52,8 +59,7 @@ static void return_unused_pool_pebs(stru for (i = pool->used; i < pool->size; i++) { e = ubi->lookuptbl[pool->pebs[i]]; - wl_tree_add(e, &ubi->free); - ubi->free_count++; + return_unused_peb(ubi, e); } } @@ -361,6 +367,11 @@ static void ubi_fastmap_close(struct ubi return_unused_pool_pebs(ubi, &ubi->fm_pool); return_unused_pool_pebs(ubi, &ubi->fm_wl_pool); + if (ubi->fm_anchor) { + return_unused_peb(ubi, ubi->fm_anchor); + ubi->fm_anchor = NULL; + } + if (ubi->fm) { for (i = 0; i < ubi->fm->used_blocks; i++) kfree(ubi->fm->e[i]);