Skip to content

Commit

Permalink
iscsi-target: chap auth shouldn't match username with trailing garbage
Browse files Browse the repository at this point in the history
In iSCSI negotiations with initiator CHAP enabled, usernames with
trailing garbage are permitted, because the string comparison only
checks the strlen of the configured username.

e.g. "usernameXXXXX" will be permitted to match "username".

Just check one more byte so the trailing null char is also matched.

Signed-off-by: Eric Seppanen <eric@purestorage.com>
Cc: <stable@vger.kernel.org> #3.1+
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
  • Loading branch information
ericatpure authored and Nicholas Bellinger committed Nov 21, 2013
1 parent 369653e commit 86784c6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/target/iscsi/iscsi_target_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ static int chap_server_compute_md5(
unsigned char client_digest[MD5_SIGNATURE_SIZE];
unsigned char server_digest[MD5_SIGNATURE_SIZE];
unsigned char chap_n[MAX_CHAP_N_SIZE], chap_r[MAX_RESPONSE_LENGTH];
size_t compare_len;
struct iscsi_chap *chap = conn->auth_protocol;
struct crypto_hash *tfm;
struct hash_desc desc;
Expand Down Expand Up @@ -184,7 +185,9 @@ static int chap_server_compute_md5(
goto out;
}

if (memcmp(chap_n, auth->userid, strlen(auth->userid)) != 0) {
/* Include the terminating NULL in the compare */
compare_len = strlen(auth->userid) + 1;
if (strncmp(chap_n, auth->userid, compare_len) != 0) {
pr_err("CHAP_N values do not match!\n");
goto out;
}
Expand Down

0 comments on commit 86784c6

Please sign in to comment.