Skip to content

Commit 85428be

Browse files
igawChristoph Hellwig
authored andcommitted
nvmet: seset ns->file when open fails
Reset the ns->file value to NULL also in the error case in nvmet_file_ns_enable(). The ns->file variable points either to file object or contains the error code after the filp_open() call. This can lead to following problem: When the user first setups an invalid file backend and tries to enable the ns, it will fail. Then the user switches over to a bdev backend and enables successfully the ns. The first received I/O will crash the system because the IO backend is chosen based on the ns->file value: static u16 nvmet_parse_io_cmd(struct nvmet_req *req) { [...] if (req->ns->file) return nvmet_file_parse_io_cmd(req); return nvmet_bdev_parse_io_cmd(req); } Reported-by: Enzo Matsumiya <[email protected]> Signed-off-by: Daniel Wagner <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 7a4ffd2 commit 85428be

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/nvme/target/io-cmd-file.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
4949

5050
ns->file = filp_open(ns->device_path, flags, 0);
5151
if (IS_ERR(ns->file)) {
52-
pr_err("failed to open file %s: (%ld)\n",
53-
ns->device_path, PTR_ERR(ns->file));
54-
return PTR_ERR(ns->file);
52+
ret = PTR_ERR(ns->file);
53+
pr_err("failed to open file %s: (%d)\n",
54+
ns->device_path, ret);
55+
ns->file = NULL;
56+
return ret;
5557
}
5658

5759
ret = nvmet_file_ns_revalidate(ns);

0 commit comments

Comments
 (0)