Re: [PATCH] memstick: ms_block: Fix potential block buffer leak
From: Ulf Hansson
Date: Fri Nov 27 2026 - 09:44:21 EST
On Wed, Nov 4, 2026 at 3:33 AM Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx> wrote:
>
> msb_init_card() allocates a block buffer, but msb_data_clear() does
> not free it. The buffer is leaked on probe failure, removal and
> when discarding the temporary card state used during resume.
>
> Free it with the other allocations in msb_data_clear().
>
> This issue was found by our static analysis tool under development.
>
> Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks")
> Signed-off-by: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
Applied for fixes and by adding a stable tag, thanks!
Kind regards
Uffe
> ---
> Build-tested the changed object with x86_64 GCC W=1, using defconfig
> with the driver dependencies enabled. No hardware/kernel runtime test or full linked-kernel
> build.
> OpenAI Codex assisted with source review, patch implementation and
> commit-message drafting. The submitter has reviewed the changes.
>
> drivers/memstick/core/ms_block.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
> index cd4ff1b79a6d..d62350f9ef5b 100644
> --- a/drivers/memstick/core/ms_block.c
> +++ b/drivers/memstick/core/ms_block.c
> @@ -1953,6 +1953,7 @@ static void msb_data_clear(struct msb_data *msb)
> bitmap_free(msb->erased_blocks_bitmap);
> kfree(msb->lba_to_pba_table);
> kfree(msb->cache);
> + kfree(msb->block_buffer);
> msb->card = NULL;
> }
>
>
> base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d