target: iscsi: iscsi_target_tpg: Fix a possible null-pointer dereference in iscsit_tpg_add_network_portal()
Subsystems (2)
PATCH 1/1 target: iscsi: iscsi_target_tpg: Fix a possible null-pointer dereference in iscsit_tpg_add_network_portal()
In iscsit_tpg_add_network_portal(), there is an if statement on line 496 to check whether tpg->tpg_tiqn is NULL:
if (tpg->tpg_tiqn)
When tpg->tpg_tiqn is NULL, it is used on line 508:
pr_debug(..., tpg->tpg_tiqn->tiqn, ...);
Thus, a possible null-pointer dereference may occur.
To fix this bug, tpg->tpg_tiqn is checked before being used.
This bug is found by a static analysis tool STCheck written by us.
--- drivers/target/iscsi/iscsi_target_tpg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/target/iscsi/iscsi_target_tpg.c +5 -3
@@ -505,9 +505,11 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal(spin_unlock (&tpg_np_parent->tpg_np_parent_lock); } -pr_debug ("CORE[%s] - Added Network Portal: %pISpc,%hu on %s\n" , - tpg->tpg_tiqn->tiqn, &np->np_sockaddr, tpg->tpgt, - np->np_transport->name); +if (tpg->tpg_tiqn) { +pr_debug ("CORE[%s] - Added Network Portal: %pISpc,%hu on %s\n" , + tpg->tpg_tiqn->tiqn, &np->np_sockaddr, tpg->tpgt, + np->np_transport->name); + }return tpg_np; }
Signature · 1 line
2.17.0
James Bottomley
maintainerQuoted 5 lines · Jia-Ju Bai
In
iscsit_tpg_add_network_portal(), there is an if statement on line 496
to check whethertpg->tpg_tiqnis NULL:if (tpg->tpg_tiqn)
Quoted 8 lines
When
tpg->tpg_tiqnis NULL, it is used on line 508:pr_debug(..., tpg->tpg_tiqn->tiqn, ...);Thus, a possible null-pointer dereference may occur.
To fix this bug,
tpg->tpg_tiqnis checked before being used.This bug is found by a static analysis tool STCheck written by us.
I don't really think this is helpful. The first question is, is the implied might be NULL check correct? The tpg_tiqn is always set by a non-dummy driver and I think network configuration is only done for the non dummy driver, so I suspect the NULL check is wrong. Secondly even if the NULL check were correct, I think there's still a need for some debugging output, so the proposed patch also looks wrong.
James