Skip to content

Commit 8d0d244

Browse files
kawasakikeithbusch
authored andcommitted
nvme: host: fix double-free of struct nvme_id_ns in ns_update_nuse()
When nvme_identify_ns() fails, it frees the pointer to the struct nvme_id_ns before it returns. However, ns_update_nuse() calls kfree() for the pointer even when nvme_identify_ns() fails. This results in KASAN double-free, which was observed with blktests nvme/045 with proposed patches [1] on the kernel v6.8-rc7. Fix the double-free by skipping kfree() when nvme_identify_ns() fails. Link: https://lore.kernel.org/linux-block/[email protected]/ [1] Fixes: a1a825a ("nvme: add csi, ms and nuse to sysfs") Signed-off-by: Shin'ichiro Kawasaki <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Daniel Wagner <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 800bb2b commit 8d0d244

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

drivers/nvme/host/sysfs.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,11 @@ static int ns_update_nuse(struct nvme_ns *ns)
221221

222222
ret = nvme_identify_ns(ns->ctrl, ns->head->ns_id, &id);
223223
if (ret)
224-
goto out_free_id;
224+
return ret;
225225

226226
ns->head->nuse = le64_to_cpu(id->nuse);
227-
228-
out_free_id:
229227
kfree(id);
230-
231-
return ret;
228+
return 0;
232229
}
233230

234231
static ssize_t nuse_show(struct device *dev, struct device_attribute *attr,

0 commit comments

Comments
 (0)