Commit f9fab3d9 authored by Maurizio Lombardi's avatar Maurizio Lombardi Committed by Martin K. Petersen

scsi: target: iscsi: rename some variables to avoid confusion.

This patch renames some variables in chap_server_compute_hash() to make it
harder to confuse the initiator's challenge with the target's challenge
when the mutual chap authentication is used.

Link: https://lore.kernel.org/r/20191017131037.9903-4-mlombard@redhat.comSigned-off-by: default avatarMaurizio Lombardi <mlombard@redhat.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 19f5f88e
...@@ -215,8 +215,8 @@ static int chap_server_compute_hash( ...@@ -215,8 +215,8 @@ static int chap_server_compute_hash(
unsigned long id; unsigned long id;
unsigned char id_as_uchar; unsigned char id_as_uchar;
unsigned char type; unsigned char type;
unsigned char identifier[10], *challenge = NULL; unsigned char identifier[10], *initiatorchg = NULL;
unsigned char *challenge_binhex = NULL; unsigned char *initiatorchg_binhex = NULL;
unsigned char *digest = NULL; unsigned char *digest = NULL;
unsigned char *response = NULL; unsigned char *response = NULL;
unsigned char *client_digest = NULL; unsigned char *client_digest = NULL;
...@@ -226,7 +226,7 @@ static int chap_server_compute_hash( ...@@ -226,7 +226,7 @@ static int chap_server_compute_hash(
struct iscsi_chap *chap = conn->auth_protocol; struct iscsi_chap *chap = conn->auth_protocol;
struct crypto_shash *tfm = NULL; struct crypto_shash *tfm = NULL;
struct shash_desc *desc = NULL; struct shash_desc *desc = NULL;
int auth_ret = -1, ret, challenge_len; int auth_ret = -1, ret, initiatorchg_len;
digest = kzalloc(chap->digest_size, GFP_KERNEL); digest = kzalloc(chap->digest_size, GFP_KERNEL);
if (!digest) { if (!digest) {
...@@ -256,15 +256,15 @@ static int chap_server_compute_hash( ...@@ -256,15 +256,15 @@ static int chap_server_compute_hash(
memset(chap_n, 0, MAX_CHAP_N_SIZE); memset(chap_n, 0, MAX_CHAP_N_SIZE);
memset(chap_r, 0, MAX_RESPONSE_LENGTH); memset(chap_r, 0, MAX_RESPONSE_LENGTH);
challenge = kzalloc(CHAP_CHALLENGE_STR_LEN, GFP_KERNEL); initiatorchg = kzalloc(CHAP_CHALLENGE_STR_LEN, GFP_KERNEL);
if (!challenge) { if (!initiatorchg) {
pr_err("Unable to allocate challenge buffer\n"); pr_err("Unable to allocate challenge buffer\n");
goto out; goto out;
} }
challenge_binhex = kzalloc(CHAP_CHALLENGE_STR_LEN, GFP_KERNEL); initiatorchg_binhex = kzalloc(CHAP_CHALLENGE_STR_LEN, GFP_KERNEL);
if (!challenge_binhex) { if (!initiatorchg_binhex) {
pr_err("Unable to allocate challenge_binhex buffer\n"); pr_err("Unable to allocate initiatorchg_binhex buffer\n");
goto out; goto out;
} }
/* /*
...@@ -399,7 +399,7 @@ static int chap_server_compute_hash( ...@@ -399,7 +399,7 @@ static int chap_server_compute_hash(
* Get CHAP_C. * Get CHAP_C.
*/ */
if (extract_param(nr_in_ptr, "CHAP_C", CHAP_CHALLENGE_STR_LEN, if (extract_param(nr_in_ptr, "CHAP_C", CHAP_CHALLENGE_STR_LEN,
challenge, &type) < 0) { initiatorchg, &type) < 0) {
pr_err("Could not find CHAP_C.\n"); pr_err("Could not find CHAP_C.\n");
goto out; goto out;
} }
...@@ -408,28 +408,28 @@ static int chap_server_compute_hash( ...@@ -408,28 +408,28 @@ static int chap_server_compute_hash(
pr_err("Could not find CHAP_C.\n"); pr_err("Could not find CHAP_C.\n");
goto out; goto out;
} }
challenge_len = DIV_ROUND_UP(strlen(challenge), 2); initiatorchg_len = DIV_ROUND_UP(strlen(initiatorchg), 2);
if (!challenge_len) { if (!initiatorchg_len) {
pr_err("Unable to convert incoming challenge\n"); pr_err("Unable to convert incoming challenge\n");
goto out; goto out;
} }
if (challenge_len > 1024) { if (initiatorchg_len > 1024) {
pr_err("CHAP_C exceeds maximum binary size of 1024 bytes\n"); pr_err("CHAP_C exceeds maximum binary size of 1024 bytes\n");
goto out; goto out;
} }
if (hex2bin(challenge_binhex, challenge, challenge_len) < 0) { if (hex2bin(initiatorchg_binhex, initiatorchg, initiatorchg_len) < 0) {
pr_err("Malformed CHAP_C\n"); pr_err("Malformed CHAP_C\n");
goto out; goto out;
} }
pr_debug("[server] Got CHAP_C=%s\n", challenge); pr_debug("[server] Got CHAP_C=%s\n", initiatorchg);
/* /*
* During mutual authentication, the CHAP_C generated by the * During mutual authentication, the CHAP_C generated by the
* initiator must not match the original CHAP_C generated by * initiator must not match the original CHAP_C generated by
* the target. * the target.
*/ */
if (challenge_len == chap->challenge_len && if (initiatorchg_len == chap->challenge_len &&
!memcmp(challenge_binhex, chap->challenge, !memcmp(initiatorchg_binhex, chap->challenge,
challenge_len)) { initiatorchg_len)) {
pr_err("initiator CHAP_C matches target CHAP_C, failing" pr_err("initiator CHAP_C matches target CHAP_C, failing"
" login attempt\n"); " login attempt\n");
goto out; goto out;
...@@ -461,7 +461,7 @@ static int chap_server_compute_hash( ...@@ -461,7 +461,7 @@ static int chap_server_compute_hash(
/* /*
* Convert received challenge to binary hex. * Convert received challenge to binary hex.
*/ */
ret = crypto_shash_finup(desc, challenge_binhex, challenge_len, ret = crypto_shash_finup(desc, initiatorchg_binhex, initiatorchg_len,
digest); digest);
if (ret < 0) { if (ret < 0) {
pr_err("crypto_shash_finup() failed for ma challenge\n"); pr_err("crypto_shash_finup() failed for ma challenge\n");
...@@ -487,8 +487,8 @@ static int chap_server_compute_hash( ...@@ -487,8 +487,8 @@ static int chap_server_compute_hash(
kzfree(desc); kzfree(desc);
if (tfm) if (tfm)
crypto_free_shash(tfm); crypto_free_shash(tfm);
kfree(challenge); kfree(initiatorchg);
kfree(challenge_binhex); kfree(initiatorchg_binhex);
kfree(digest); kfree(digest);
kfree(response); kfree(response);
kfree(server_digest); kfree(server_digest);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment