Commit

e15b81f602edbdee39c335546f25486a1747f3f0

scsi: target: iscsi: Fix race in discovery auth updates

Separate configfs opens can concurrently update the discovery AuthMethod
parameter. Both callers may free the same value in
iscsi_update_param_value(), causing a double-free.

Protect the lookup and replacement with the discovery TPG access lock,
as used by the other TPG configfs parameter updates.

Fixes: e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
Signed-off-by: Linfeng Sun <linfeng.sun.dev@gmail.com>
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Link: https://patch.msgid.link/20260811124843.6817-1-linfeng.sun.dev@gmail.com
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>

Linfeng Sun <linfeng.sun.dev@gmail.com> · 2026-08-11 12:48 UTC · committed by Martin K. Petersen (Oracle)

Browse files
1 file changed, +19 −7
modified drivers/target/iscsi/iscsi_target_configfs.c
@@ -1306,17 +1306,24 @@ static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1306 1306 return -EINVAL;
1307 1307 }
1308 1308
1309 + if (iscsit_get_tpg(discovery_tpg) < 0)
1310 + return -EINVAL;
1311 +
1309 1312 param = iscsi_find_param_from_key(AUTHMETHOD,
1310 1313 discovery_tpg->param_list);
1311 - if (!param)
1312 - return -EINVAL;
1314 + if (!param) {
1315 + err = -EINVAL;
1316 + goto out;
1317 + }
1313 1318
1314 1319 if (op) {
1315 1320 /*
1316 1321 * Reset the AuthMethod key to CHAP.
1317 1322 */
1318 - if (iscsi_update_param_value(param, CHAP) < 0)
1319 - return -EINVAL;
1323 + if (iscsi_update_param_value(param, CHAP) < 0) {
1324 + err = -EINVAL;
1325 + goto out;
1326 + }
1320 1327
1321 1328 discovery_tpg->tpg_attrib.authentication = 1;
1322 1329 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
@@ -1327,8 +1334,10 @@ static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1327 1334 /*
1328 1335 * Reset the AuthMethod key to CHAP,None
1329 1336 */
1330 - if (iscsi_update_param_value(param, "CHAP,None") < 0)
1331 - return -EINVAL;
1337 + if (iscsi_update_param_value(param, "CHAP,None") < 0) {
1338 + err = -EINVAL;
1339 + goto out;
1340 + }
1332 1341
1333 1342 discovery_tpg->tpg_attrib.authentication = 0;
1334 1343 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
@@ -1337,7 +1346,10 @@ static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1337 1346 " Discovery TPG\n");
1338 1347 }
1339 1348
1340 - return count;
1349 + err = count;
1350 + out:
1351 + iscsit_put_tpg(discovery_tpg);
1352 + return err;
1341 1353 }
1342 1354
1343 1355 CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);