From patchwork Mon Oct 28 12:38:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maurizio Lombardi X-Patchwork-Id: 11215321 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93D0913B1 for ; Mon, 28 Oct 2019 12:38:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 723D3208C0 for ; Mon, 28 Oct 2019 12:38:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XLHni5J7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389141AbfJ1Mil (ORCPT ); Mon, 28 Oct 2019 08:38:41 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:41201 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727024AbfJ1Mil (ORCPT ); Mon, 28 Oct 2019 08:38:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572266319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uTXmcDggs9arSmYol0p3kqWQyviimG5Qsl31yFm8+WA=; b=XLHni5J7FFXj//65J+XGaRQXDhaJeSLRot4tNfHYS9+66UJSMcf1wiA6OQ2LOhOihnWpEF T3qM3lKo/diAk4GBH3QG/TzS1hBHg+UemPBVXsueisOT9bQRHhw4DNAs3hLTiWxo2L3sQP 40rbVYiOPiNZXxXu3EFfn/gyuepiriA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-198-04R8wVCSPb6LUdIR-LVYHg-1; Mon, 28 Oct 2019 08:38:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CBCF180491C; Mon, 28 Oct 2019 12:38:36 +0000 (UTC) Received: from manaslu.redhat.com (ovpn-204-92.brq.redhat.com [10.40.204.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F26D600C9; Mon, 28 Oct 2019 12:38:33 +0000 (UTC) From: Maurizio Lombardi To: cleech@redhat.com Cc: mchristi@redhat.com, target-devel@vger.kernel.org, hch@infradead.org, martin.petersen@oracle.com Subject: [PATCH V3 3/3] target-iscsi: rename some variables to avoid confusion. Date: Mon, 28 Oct 2019 13:38:22 +0100 Message-Id: <20191028123822.5864-4-mlombard@redhat.com> In-Reply-To: <20191028123822.5864-1-mlombard@redhat.com> References: <20191028123822.5864-1-mlombard@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 04R8wVCSPb6LUdIR-LVYHg-1 X-Mimecast-Spam-Score: 0 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org This patch renames some variables in chap_server_compute_hash() to avoid confusing the initiator's challenge with the target's challenge when the mutual chap authentication is used. Signed-off-by: Maurizio Lombardi --- drivers/target/iscsi/iscsi_target_auth.c | 43 ++++++++++++------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target_auth.c b/drivers/target/iscsi/iscsi_target_auth.c index f3973ab19da2..09c6bde0a978 100644 --- a/drivers/target/iscsi/iscsi_target_auth.c +++ b/drivers/target/iscsi/iscsi_target_auth.c @@ -215,8 +215,8 @@ static int chap_server_compute_hash( unsigned long id; unsigned char id_as_uchar; unsigned char type; - unsigned char identifier[10], *challenge = NULL; - unsigned char *challenge_binhex = NULL; + unsigned char identifier[10], *client_challenge = NULL; + unsigned char *client_challenge_binhex = NULL; unsigned char *digest = NULL; unsigned char *response = NULL; unsigned char *client_digest = NULL; @@ -226,7 +226,7 @@ static int chap_server_compute_hash( struct iscsi_chap *chap = conn->auth_protocol; struct crypto_shash *tfm = NULL; struct shash_desc *desc = NULL; - int auth_ret = -1, ret, challenge_len; + int auth_ret = -1, ret, client_challenge_len; digest = kzalloc(chap->digest_size, GFP_KERNEL); if (!digest) { @@ -256,15 +256,15 @@ static int chap_server_compute_hash( memset(chap_n, 0, MAX_CHAP_N_SIZE); memset(chap_r, 0, MAX_RESPONSE_LENGTH); - challenge = kzalloc(CHAP_CHALLENGE_STR_LEN, GFP_KERNEL); - if (!challenge) { + client_challenge = kzalloc(CHAP_CHALLENGE_STR_LEN, GFP_KERNEL); + if (!client_challenge) { pr_err("Unable to allocate challenge buffer\n"); goto out; } - challenge_binhex = kzalloc(CHAP_CHALLENGE_STR_LEN, GFP_KERNEL); - if (!challenge_binhex) { - pr_err("Unable to allocate challenge_binhex buffer\n"); + client_challenge_binhex = kzalloc(CHAP_CHALLENGE_STR_LEN, GFP_KERNEL); + if (!client_challenge_binhex) { + pr_err("Unable to allocate client_challenge_binhex buffer\n"); goto out; } /* @@ -399,7 +399,7 @@ static int chap_server_compute_hash( * Get CHAP_C. */ if (extract_param(nr_in_ptr, "CHAP_C", CHAP_CHALLENGE_STR_LEN, - challenge, &type) < 0) { + client_challenge, &type) < 0) { pr_err("Could not find CHAP_C.\n"); goto out; } @@ -408,28 +408,29 @@ static int chap_server_compute_hash( pr_err("Could not find CHAP_C.\n"); goto out; } - challenge_len = DIV_ROUND_UP(strlen(challenge), 2); - if (!challenge_len) { + client_challenge_len = DIV_ROUND_UP(strlen(client_challenge), 2); + if (!client_challenge_len) { pr_err("Unable to convert incoming challenge\n"); goto out; } - if (challenge_len > 1024) { + if (client_challenge_len > 1024) { pr_err("CHAP_C exceeds maximum binary size of 1024 bytes\n"); goto out; } - if (hex2bin(challenge_binhex, challenge, challenge_len) < 0) { + if (hex2bin(client_challenge_binhex, client_challenge, + client_challenge_len) < 0) { pr_err("Malformed CHAP_C\n"); goto out; } - pr_debug("[server] Got CHAP_C=%s\n", challenge); + pr_debug("[server] Got CHAP_C=%s\n", client_challenge); /* * During mutual authentication, the CHAP_C generated by the * initiator must not match the original CHAP_C generated by * the target. */ - if (challenge_len == chap->challenge_len && - !memcmp(challenge_binhex, chap->challenge, - challenge_len)) { + if (client_challenge_len == chap->challenge_len && + !memcmp(client_challenge_binhex, + chap->challenge, client_challenge_len)) { pr_err("initiator CHAP_C matches target CHAP_C, failing" " login attempt\n"); goto out; @@ -461,8 +462,8 @@ static int chap_server_compute_hash( /* * Convert received challenge to binary hex. */ - ret = crypto_shash_finup(desc, challenge_binhex, challenge_len, - digest); + ret = crypto_shash_finup(desc, client_challenge_binhex, + client_challenge_len, digest); if (ret < 0) { pr_err("crypto_shash_finup() failed for ma challenge\n"); goto out; @@ -487,8 +488,8 @@ static int chap_server_compute_hash( kzfree(desc); if (tfm) crypto_free_shash(tfm); - kfree(challenge); - kfree(challenge_binhex); + kfree(client_challenge); + kfree(client_challenge_binhex); kfree(digest); kfree(response); kfree(server_digest);