* [PATCH] nvme: fix memory leak in quirks_param_set()
@ 2026-02-11 16:30 Maurizio Lombardi
2026-02-11 16:41 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Maurizio Lombardi @ 2026-02-11 16:30 UTC (permalink / raw)
To: kbusch; +Cc: hch, linux-nvme, dwagner, mlombard
When loading the nvme module, if the 'quirks' parameter is specified
via both the kernel command line (e.g., nvme.quirks=...) and the
modprobe command line (e.g., modprobe nvme quirks=...), the
quirks_param_set() callback is invoked twice.
Currently, in the double-invocation scenario, the second call
overwrites the nvme_pci_quirk_list pointer, causing the memory
allocated in the first call to leak.
Fix this by freeing the existing list before assigning the new one.
Fixes: b4247c8317c5 ("nvme: add support for dynamic quirk configuration via module parameter")
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
drivers/nvme/host/pci.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index a6cf0897a0f2..3e1c6adf2cf0 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -219,6 +219,7 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)
i++;
}
+ kfree(nvme_pci_quirk_list);
nvme_pci_quirk_count = count;
nvme_pci_quirk_list = qlist;
goto out_free_val;
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] nvme: fix memory leak in quirks_param_set()
2026-02-11 16:30 [PATCH] nvme: fix memory leak in quirks_param_set() Maurizio Lombardi
@ 2026-02-11 16:41 ` Christoph Hellwig
2026-02-11 17:01 ` Daniel Wagner
2026-02-12 2:35 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-02-11 16:41 UTC (permalink / raw)
To: Maurizio Lombardi; +Cc: kbusch, hch, linux-nvme, dwagner, mlombard
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nvme: fix memory leak in quirks_param_set()
2026-02-11 16:30 [PATCH] nvme: fix memory leak in quirks_param_set() Maurizio Lombardi
2026-02-11 16:41 ` Christoph Hellwig
@ 2026-02-11 17:01 ` Daniel Wagner
2026-02-12 2:35 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Wagner @ 2026-02-11 17:01 UTC (permalink / raw)
To: Maurizio Lombardi; +Cc: kbusch, hch, linux-nvme, mlombard
On Wed, Feb 11, 2026 at 05:30:28PM +0100, Maurizio Lombardi wrote:
> When loading the nvme module, if the 'quirks' parameter is specified
> via both the kernel command line (e.g., nvme.quirks=...) and the
> modprobe command line (e.g., modprobe nvme quirks=...), the
> quirks_param_set() callback is invoked twice.
>
> Currently, in the double-invocation scenario, the second call
> overwrites the nvme_pci_quirk_list pointer, causing the memory
> allocated in the first call to leak.
>
> Fix this by freeing the existing list before assigning the new one.
>
> Fixes: b4247c8317c5 ("nvme: add support for dynamic quirk configuration via module parameter")
> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
Looks good.
Reviewed-by: Daniel Wagner <dwagner@suse.de>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] nvme: fix memory leak in quirks_param_set()
2026-02-11 16:30 [PATCH] nvme: fix memory leak in quirks_param_set() Maurizio Lombardi
2026-02-11 16:41 ` Christoph Hellwig
2026-02-11 17:01 ` Daniel Wagner
@ 2026-02-12 2:35 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2026-02-12 2:35 UTC (permalink / raw)
To: Maurizio Lombardi; +Cc: hch, linux-nvme, dwagner, mlombard
On Wed, Feb 11, 2026 at 05:30:28PM +0100, Maurizio Lombardi wrote:
> When loading the nvme module, if the 'quirks' parameter is specified
> via both the kernel command line (e.g., nvme.quirks=...) and the
> modprobe command line (e.g., modprobe nvme quirks=...), the
> quirks_param_set() callback is invoked twice.
>
> Currently, in the double-invocation scenario, the second call
> overwrites the nvme_pci_quirk_list pointer, causing the memory
> allocated in the first call to leak.
>
> Fix this by freeing the existing list before assigning the new one.
Thanks applied to nvme-7.0.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-12 2:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-11 16:30 [PATCH] nvme: fix memory leak in quirks_param_set() Maurizio Lombardi
2026-02-11 16:41 ` Christoph Hellwig
2026-02-11 17:01 ` Daniel Wagner
2026-02-12 2:35 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox