[PATCH] nvme: Fix memory leak in nvme_init_ctrl error path
Chaitanya Kulkarni
chaitanyak at nvidia.com
Wed May 3 22:23:37 PDT 2023
On 5/3/23 08:09, Sagi Grimberg wrote:
> nvme_init_ctrl may fail before creating the misc device or after creating
> the misc device.
>
> If we fail before creating the misc device, we just need to deallocate what
> was allocated before and return (as usually done).
>
> If we fail after we create the misc device, we must put
> the final reference on the device in order to make sure that internal
> device resources are cleaned up.
>
> The device release also triggers nvme_free_ctrl method so we need to make
> sure to identify that we failed during the initialization itself and skip
> cleaning because nvme_init_ctrl error path cleaned up on its own (we do
> that by marking the ctrl->instance to UNINITIALIZED).
>
> We also drop the explicit dev_name deallocation because it is freed in
> the device release sequence.
>
> This addresses a memory leak triggered by blktests nvme/044 which happens
> to fail exactly after misc device initialization:
> --
> unreferenced object 0xffff95678a54cd00 (size 256):
> comm "nvme", pid 1941, jiffies 4294761594 (age 10.010s)
> hex dump (first 32 bytes):
> 00 00 00 00 00 00 00 00 08 cd 54 8a 67 95 ff ff ..........T.g...
> 08 cd 54 8a 67 95 ff ff e0 b5 7b 8b ff ff ff ff ..T.g.....{.....
> backtrace:
> [<ffffffff8b349205>] kmalloc_trace+0x25/0x90
> [<ffffffff8b7c0463>] device_add+0x303/0x690
> [<ffffffff8b4103c4>] cdev_device_add+0x44/0x90
> [<ffffffffc0de1c42>] 0xffffffffc0de1c42
> [<ffffffffc0d788b3>] 0xffffffffc0d788b3
> [<ffffffffc0d8c66d>] 0xffffffffc0d8c66d
> [<ffffffffc0d8c831>] 0xffffffffc0d8c831
> [<ffffffff8b40a8b2>] vfs_write+0xc2/0x3c0
> [<ffffffff8b40aeff>] ksys_write+0x5f/0xe0
> [<ffffffff8bc0eb58>] do_syscall_64+0x38/0x90
> [<ffffffff8be000aa>] entry_SYSCALL_64_after_hwframe+0x72/0xdc
> --
>
> Reported-by: Irvin Cote <irvincoteg at gmail.com>
> Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
> ---
>
I try to apply this patch on linux-nvme nvme-6.4 it is not applying,
which tree I should use for this to test it ?
nvme (nvme-6.4) # git apply init-ctrl-fix.patch
error: patch failed: drivers/nvme/host/core.c:5137
error: drivers/nvme/host/core.c: patch does not apply
-ck
More information about the Linux-nvme
mailing list