mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yingjie Wang <x-professor@outlook.com>
To: Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Benjamin Marzinski <bmarzins@redhat.com>
Cc: "dm-devel@lists.linux.dev" <dm-devel@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Damien Le Moal <dlemoal@kernel.org>,
	Hannes Reinecke <hare@suse.de>, Dan Carpenter <error27@gmail.com>,
	Yingjie Wang <x-professor@outlook.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails
Date: Mon, 30 Nov 2026 16:17:00 +0000	[thread overview]
Message-ID: <20261130161700.3536656-1-x-professor@outlook.com> (raw)
In-Reply-To: <20261130161425.3535695-1-x-professor@outlook.com>

dmz_get_sb() does not leave a block to free when it fails.  If the read
fails, it frees the block and sets sb->mblk to NULL.  If the allocation
fails, it does not touch sb->mblk, which is either NULL or, after the
first iteration of the loop, points to the block that was freed by the
previous one.

dmz_load_sb() nevertheless calls dmz_free_mblock() in this case.  A
read error on the first block of a zoned device therefore results in a
NULL pointer dereference:

  (zoned1): Read tertiary super block failed
  KASAN: null-ptr-deref in range [0x0000000000000040-0x0000000000000047]

An allocation failure can result in a double free, as reported by
Smatch.

Remove the bogus dmz_free_mblock() call.

Fixes: 5d2c74f3ddc0 ("dm zoned: allocate temporary superblock for tertiary devices")
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/dm-devel/ahrruAVoUpDmh6Cf@stanley.mountain/
Suggested-by: Dan Carpenter <error27@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
 drivers/md/dm-zoned-metadata.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index f7aa04954d2f..1168537bb70d 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -1327,7 +1327,6 @@ static int dmz_load_sb(struct dmz_metadata *zmd)
 			if (ret) {
 				dmz_dev_err(sb->dev,
 					    "Read tertiary super block failed");
-				dmz_free_mblock(zmd, sb->mblk);
 				goto out_kfree;
 			}
 			ret = dmz_check_sb(zmd, sb, true);

  reply	other threads:[~2026-11-30 16:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:14 [PATCH 0/3] dm zoned: fix metadata recovery and a tertiary superblock crash Yingjie Wang
2026-11-30 16:17 ` Yingjie Wang [this message]
2026-11-30 16:17 ` [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set Yingjie Wang
2026-11-30 16:17 ` [PATCH 3/3] dm zoned: fix the search for the secondary superblock Yingjie Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130161700.3536656-1-x-professor@outlook.com \
    --to=x-professor@outlook.com \
    --cc=agk@redhat.com \
    --cc=bmarzins@redhat.com \
    --cc=dlemoal@kernel.org \
    --cc=dm-devel@lists.linux.dev \
    --cc=error27@gmail.com \
    --cc=hare@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®