From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A67E838AC72; Sat, 12 Sep 2026 19:51:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242675; cv=none; b=qh0OVpv6Qv0SJ5I8OJqolZguQW9l6Az5eDbwng69EH+B5rLhHo0hb3ga7jd6FwbIy6EM22qVIwzQE2PJCN1ehSngqhLpWsOk4nX+i6xDkLl2lM+twRyluAkBnwjRyfVMq9U5/9tmKa7UXD5+Gjj9UhTEC2EkaOq5Ql5CS/mF24Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242675; c=relaxed/simple; bh=mPfK9nWXCEhVyNq+T2oblnXeNMRMDzTdlSUTkLPa/eM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BS0a7OkVvbSj1lXZxJskINAE/HstQ6PL8RSqoLfJEqmzJmuKLKOCEPK8Hs+GvAVCTcrRSp0brJKuabmfxAY4SvdPFskPEoYS188SHLRrnS0WiUNM2YHIdcsZZyJoiDn0o2XprJ+aKF8qUNH5pRehp+GC52yLCvb4QDbPvKYr/Iw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=SXKYa7/j; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="SXKYa7/j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CC141F000FF; Sat, 12 Sep 2026 19:51:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789242674; bh=kd1fzU1qayPIJ4B7u1uKaD9EC6iq5iTWMq2xvcAVh54=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SXKYa7/j8D/6g5hy8aCeuwCCpGVHMmeY7Pf0PgQ2/Jqhfk3TDeHyyvEuCJimShH7N A3hCMNNNnLlRXt+1zyWvP5Ew94gwLXeVFIPRmNbJm0My9QSX3857u7N0YknH9/GQm0 COBNZi/tam0JsMn+zuHxX+btgEmVuS3C+f3R3diM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ruoyu Wang , Miquel Raynal , Sasha Levin Subject: [PATCH 5.10 470/798] mtd: mtdswap: Avoid freeing registered blktrans device twice Date: Sat, 12 Sep 2026 09:01:38 +0200 Message-ID: <20260912065527.918756930@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065516.948645775@linuxfoundation.org> References: <20260912065516.948645775@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ruoyu Wang [ Upstream commit 779aa4c66a96bf43d2d62982ea1a9096a9128d87 ] In mtdswap_add_mtd(), debugfs setup failure after successful blktrans registration can free mbd_dev twice. add_mtd_blktrans_dev() initializes the blktrans device reference and publishes the disk. Once that succeeds, del_mtd_blktrans_dev() tears the disk down and drops the blktrans reference; when that reference reaches zero, blktrans_dev_release() frees the mtd_blktrans_dev. The debugfs failure path called del_mtd_blktrans_dev(mbd_dev), then fell through the common cleanup label and called kfree(mbd_dev) again. Clear the local pointer after deregistration so the common cleanup can still release the mtdswap state without freeing the blktrans object twice. This issue was found by a static analysis checker and confirmed by manual source review. Fixes: e8e3edb95ce6 ("mtd: create per-device and module-scope debugfs entries") Signed-off-by: Ruoyu Wang Signed-off-by: Miquel Raynal Signed-off-by: Sasha Levin --- drivers/mtd/mtdswap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index bd4ac12099624..5819918035682 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -1454,6 +1454,7 @@ static void mtdswap_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) debugfs_failed: del_mtd_blktrans_dev(mbd_dev); + mbd_dev = NULL; cleanup: mtdswap_cleanup(d); -- 2.53.0