diff options
author | Joern Engel <joern@logfs.org> | 2014-09-02 17:49:56 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2014-09-17 17:16:54 -0400 |
commit | 8d2135592d2ab5c8d7764a4f534afac64e563691 (patch) | |
tree | 77607882ed9f636491a8b9617849c660c11b8c9a /drivers/target | |
parent | fdc84d11a278d468052afc8e17523545fafe6c5f (diff) |
target: Fix possible memory leak in aptpl_metadata parsing
Each case of match_strdup could leak memory if the same argument was
present before. I am not too concerned, as it would require a
non-sensical combination like "target_lun=foo target_lun=bar", done
with root privileges and even then leak just a few bytes per instance.
But arg_p is different, as it will always leak memory. Let's plug that
one. And while at it, replace some &args[0] with args.
Found by coverity.
Signed-off-by: Joern Engel <joern@logfs.org>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r-- | drivers/target/target_core_configfs.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index bf55c5a04cfa..291dc711fbc3 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c | |||
@@ -1263,7 +1263,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( | |||
1263 | { | 1263 | { |
1264 | unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL; | 1264 | unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL; |
1265 | unsigned char *t_fabric = NULL, *t_port = NULL; | 1265 | unsigned char *t_fabric = NULL, *t_port = NULL; |
1266 | char *orig, *ptr, *arg_p, *opts; | 1266 | char *orig, *ptr, *opts; |
1267 | substring_t args[MAX_OPT_ARGS]; | 1267 | substring_t args[MAX_OPT_ARGS]; |
1268 | unsigned long long tmp_ll; | 1268 | unsigned long long tmp_ll; |
1269 | u64 sa_res_key = 0; | 1269 | u64 sa_res_key = 0; |
@@ -1295,14 +1295,14 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( | |||
1295 | token = match_token(ptr, tokens, args); | 1295 | token = match_token(ptr, tokens, args); |
1296 | switch (token) { | 1296 | switch (token) { |
1297 | case Opt_initiator_fabric: | 1297 | case Opt_initiator_fabric: |
1298 | i_fabric = match_strdup(&args[0]); | 1298 | i_fabric = match_strdup(args); |
1299 | if (!i_fabric) { | 1299 | if (!i_fabric) { |
1300 | ret = -ENOMEM; | 1300 | ret = -ENOMEM; |
1301 | goto out; | 1301 | goto out; |
1302 | } | 1302 | } |
1303 | break; | 1303 | break; |
1304 | case Opt_initiator_node: | 1304 | case Opt_initiator_node: |
1305 | i_port = match_strdup(&args[0]); | 1305 | i_port = match_strdup(args); |
1306 | if (!i_port) { | 1306 | if (!i_port) { |
1307 | ret = -ENOMEM; | 1307 | ret = -ENOMEM; |
1308 | goto out; | 1308 | goto out; |
@@ -1316,7 +1316,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( | |||
1316 | } | 1316 | } |
1317 | break; | 1317 | break; |
1318 | case Opt_initiator_sid: | 1318 | case Opt_initiator_sid: |
1319 | isid = match_strdup(&args[0]); | 1319 | isid = match_strdup(args); |
1320 | if (!isid) { | 1320 | if (!isid) { |
1321 | ret = -ENOMEM; | 1321 | ret = -ENOMEM; |
1322 | goto out; | 1322 | goto out; |
@@ -1330,15 +1330,9 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( | |||
1330 | } | 1330 | } |
1331 | break; | 1331 | break; |
1332 | case Opt_sa_res_key: | 1332 | case Opt_sa_res_key: |
1333 | arg_p = match_strdup(&args[0]); | 1333 | ret = kstrtoull(args->from, 0, &tmp_ll); |
1334 | if (!arg_p) { | ||
1335 | ret = -ENOMEM; | ||
1336 | goto out; | ||
1337 | } | ||
1338 | ret = kstrtoull(arg_p, 0, &tmp_ll); | ||
1339 | if (ret < 0) { | 1334 | if (ret < 0) { |
1340 | pr_err("kstrtoull() failed for" | 1335 | pr_err("kstrtoull() failed for sa_res_key=\n"); |
1341 | " sa_res_key=\n"); | ||
1342 | goto out; | 1336 | goto out; |
1343 | } | 1337 | } |
1344 | sa_res_key = (u64)tmp_ll; | 1338 | sa_res_key = (u64)tmp_ll; |
@@ -1370,14 +1364,14 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( | |||
1370 | * PR APTPL Metadata for Target Port | 1364 | * PR APTPL Metadata for Target Port |
1371 | */ | 1365 | */ |
1372 | case Opt_target_fabric: | 1366 | case Opt_target_fabric: |
1373 | t_fabric = match_strdup(&args[0]); | 1367 | t_fabric = match_strdup(args); |
1374 | if (!t_fabric) { | 1368 | if (!t_fabric) { |
1375 | ret = -ENOMEM; | 1369 | ret = -ENOMEM; |
1376 | goto out; | 1370 | goto out; |
1377 | } | 1371 | } |
1378 | break; | 1372 | break; |
1379 | case Opt_target_node: | 1373 | case Opt_target_node: |
1380 | t_port = match_strdup(&args[0]); | 1374 | t_port = match_strdup(args); |
1381 | if (!t_port) { | 1375 | if (!t_port) { |
1382 | ret = -ENOMEM; | 1376 | ret = -ENOMEM; |
1383 | goto out; | 1377 | goto out; |