mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Fourier <fourier.thomas@gmail.com>
Cc: Thomas Fourier <fourier.thomas@gmail.com>,
	Maxim Levitsky <maximlevitsky@gmail.com>,
	Alex Dubov <oakad@yahoo.com>, Ulf Hansson <ulfh@kernel.org>,
	Yifei Gao <gyf161023@gmail.com>,
	Hemanth Selam <hemanth.selam@gmail.com>,
	Maoyi Xie <maoyixie.tju@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mmc@vger.kernel.org (open list:SONY MEMORYSTICK SUBSYSTEM),
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] memstick: ms_block: fix double free in msb_ftl_initialize() error path
Date: Wed,  4 Nov 2026 10:17:25 +0100	[thread overview]
Message-ID: <20261104091731.16500-3-fourier.thomas@gmail.com> (raw)

When one of the allocations in msb_ftl_initialize() fails, the function
frees msb->used_blocks_bitmap, msb->erased_blocks_bitmap and
msb->lba_to_pba_table but leaves the pointers set. The caller
msb_init_card() fails and both of its callers (msb_probe() and
msb_resume()) call msb_data_clear(), which frees the same three pointers
again.

Do not free them in msb_ftl_initialize().

This bug was found statically and is theoretical.

Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks")
---
 drivers/memstick/core/ms_block.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index cd4ff1b79a6d..26a04cecd94b 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -1351,12 +1351,8 @@ static int msb_ftl_initialize(struct msb_data *msb)
 			      GFP_KERNEL);
 
 	if (!msb->used_blocks_bitmap || !msb->lba_to_pba_table ||
-						!msb->erased_blocks_bitmap) {
-		bitmap_free(msb->used_blocks_bitmap);
-		bitmap_free(msb->erased_blocks_bitmap);
-		kfree(msb->lba_to_pba_table);
+						!msb->erased_blocks_bitmap)
 		return -ENOMEM;
-	}
 
 	for (i = 0; i < msb->zone_count; i++)
 		msb->free_block_count[i] = MS_BLOCKS_IN_ZONE;
-- 
2.53.0


                 reply	other threads:[~2026-11-04  9:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261104091731.16500-3-fourier.thomas@gmail.com \
    --to=fourier.thomas@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=gyf161023@gmail.com \
    --cc=hemanth.selam@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=maoyixie.tju@gmail.com \
    --cc=maximlevitsky@gmail.com \
    --cc=oakad@yahoo.com \
    --cc=ulfh@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®