Skip to contentSkip to conversation

nvme: fix memory leak in quirks_param_set()

PATCH Applied Maurizio Lombardi 4 participants 4 messages Feb 11 – Feb 12 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: fix memory leak in quirks_param_set()

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")
---
 drivers/nvme/host/pci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvme/host/pci.c +1 -0
index a6cf0897a0f2..3e1c6adf2cf0 100644
@@ -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;
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Maurizio Lombardi
Quoted 5 lines · Maurizio Lombardi

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.

Quoted 8 lines

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")

Looks good.

maintainer Applied
#3 lore raw
In reply to Maurizio Lombardi
Quoted 10 lines · Maurizio Lombardi

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.