Skip to content

Commit e8dc100

Browse files
Martin Belangerigaw
authored andcommitted
libnvme: guard against NULL transport handle in discovery path
While stress testing with nvme-stas using repeated nvmet create/delete cycles, a segmentation fault was observed during teardown when running nvme connect-all. The crash occurs in nvme_get_log() due to a NULL hdl: nvme_get_log(hdl=0x0, ...) Root cause is that the return value of nvme_ctrl_get_transport_handle() is not validated before use. Under certain conditions, a race can occur where the udev-triggered [email protected] attempts to operate on a controller (e.g. nvme1) that has already been removed. Fix this by checking that the transport handle is non-NULL before issuing commands that depend on it. This prevents a potential SIGSEGV during discovery in transient device removal scenarios. Signed-off-by: Martin Belanger <[email protected]>
1 parent 28284c1 commit e8dc100

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

libnvme/src/nvme/fabrics.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,12 @@ static int nvme_discovery_log(const struct libnvme_get_discovery_args *args,
13091309
struct libnvme_transport_handle *hdl = libnvme_ctrl_get_transport_handle(args->c);
13101310
struct libnvme_passthru_cmd cmd;
13111311

1312+
if (!hdl) {
1313+
libnvme_msg(ctx, LOG_DEBUG,
1314+
"%s: no transport handle, skipping discovery\n", name);
1315+
return -ENOENT;
1316+
}
1317+
13121318
log = __libnvme_alloc(sizeof(*log));
13131319
if (!log) {
13141320
libnvme_msg(ctx, LOG_ERR,

0 commit comments

Comments
 (0)