From patchwork Tue Dec 12 21:43:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10108293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 93F04602B3 for ; Tue, 12 Dec 2017 21:45:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8389F2971B for ; Tue, 12 Dec 2017 21:45:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74BCC29727; Tue, 12 Dec 2017 21:45:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 196C02971B for ; Tue, 12 Dec 2017 21:45:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752591AbdLLVpI (ORCPT ); Tue, 12 Dec 2017 16:45:08 -0500 Received: from mout.web.de ([212.227.15.3]:61831 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752582AbdLLVpG (ORCPT ); Tue, 12 Dec 2017 16:45:06 -0500 Received: from [192.168.1.3] ([77.181.137.123]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Lk8Ow-1f0xBe1df8-00cDBM; Tue, 12 Dec 2017 22:44:04 +0100 Subject: [PATCH 2/8] target/iscsi: Move resetting of seven variables in chap_server_compute_md5() From: SF Markus Elfring To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, Al Viro , Arun Easi , Bart Van Assche , Dan Carpenter , David Disseldorp , Hannes Reinecke , Ingo Molnar , "Jason A. Donenfeld" , Jiang Yi , Kees Cook , "Nicholas A. Bellinger" , Russell King , Tang Wenji , Theodore Ts'o , Varun Prakash Cc: LKML , kernel-janitors@vger.kernel.org References: <6163538d-a406-2f60-11a2-88b4694e9975@users.sourceforge.net> Message-ID: <8566665c-8d90-ed92-2781-c4b2dde2a95d@users.sourceforge.net> Date: Tue, 12 Dec 2017 22:43:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <6163538d-a406-2f60-11a2-88b4694e9975@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:DFaK1mQOQVvodjAEMEqrw4WGVrM4MqFDIhPZZKo/SbDIG6Ww/9o 6PN1f4G1b78+Kk+kV5MyFXutJhq+0pU+0evARio+7CD9u87ad6xt3Pi2iNWE+L2hElQgbZk QoHP/fdxffajoUSX+0ssvF70h1vtcjGdMDnoqJQp+mkvl4ZDCZY0KZgrzr0CeIBfv02KP6L 9Ohd4gNBMh5kLMe+X5Smg== X-UI-Out-Filterresults: notjunk:1; V01:K0:7AVJ0mHCF3o=:nwx5T3VBvyXrBrFpEvkNov gKyPxGyFOOz4Zxk89u7MamhuF5JRQ75YRBmHChwCn6/1H8Ij+dzoX22kMLPDe5UGoAusGvUws VcG9cG6VDErgF0KnhOeTl8/7/q7ya75mSPm6Qi2PrYmyK+HfBHnnF1z/qgFl+volantn/kce1 dZwKlFIfhD6rbucevhOyx0OoNvJ0T4zISvm3rRDbvzzUDe+CmpJ6YiCOF98+m6xwwfPqDJO4F v8h+/JyRZCD43izpdkz83jUFfxjwSUeRDxc0tYtxjYU5Kct16jd8EWPUn5aRB9dm7aHMs+xSw zUDOEe0IV59PAl+6LKA5rNzMp81s8iwB4EFsgNjwde3RBTi08ji7wsnx1tDtzzLMn73/pjH1D bt7X+gyxKEniZZuIkRLXY5S6FdrLwk4APCbDwA3Px74jnB3tj7+m5NxxnXHCDEhIpMHH6HQtO JPbkC2jCKurXQwlCYqLn+2Ez/HI4PxFh6feHUXBeVybLAmtEILN2MBUs0p9zFgfQJPA8CTvTK FmKWkjBYL5lJYzemqowOP2plVE/LbERuqd/INOFNs1/q605b1RIALm2Vic6HA7dDJVWgBNdkx rha0m1KB07FipuqKO9Ktjy60jUuFCIvFnXhD1Z2UvRABjTeUAI5GJm1w41/lUHSGOzGR/j/oK oZeDeJNjXn8Nb1BQ5fwO1NmzwzvaoK+Z+18wO1/BSfHe8Lakn/0wlEA1sBw8QhSzsT81ex+VF Dh8yeyags/LKMQO1he5E5oM8Jiy9l5BSvcZuFfhUPauh2x9gpwTp/lXHIdxCwaLWmJ3nGLhND StSR4GRwk76HpPvA3DPh52R42TFtEYvNmKpYxEFvGQQQVCpsk0= Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Tue, 12 Dec 2017 19:43:47 +0100 Move the resetting of these array variables so that this operation will be performed only if memory allocations succeeded before in this function. Signed-off-by: Markus Elfring --- drivers/target/iscsi/iscsi_target_auth.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target_auth.c b/drivers/target/iscsi/iscsi_target_auth.c index 94b011fe74e8..d837fcbdbaf2 100644 --- a/drivers/target/iscsi/iscsi_target_auth.c +++ b/drivers/target/iscsi/iscsi_target_auth.c @@ -197,14 +197,6 @@ static int chap_server_compute_md5( struct shash_desc *desc; int auth_ret = -1, ret, challenge_len; - memset(identifier, 0, 10); - memset(chap_n, 0, MAX_CHAP_N_SIZE); - memset(chap_r, 0, MAX_RESPONSE_LENGTH); - memset(digest, 0, MD5_SIGNATURE_SIZE); - memset(response, 0, MD5_SIGNATURE_SIZE * 2 + 2); - memset(client_digest, 0, MD5_SIGNATURE_SIZE); - memset(server_digest, 0, MD5_SIGNATURE_SIZE); - challenge = kzalloc(CHAP_CHALLENGE_STR_LEN, GFP_KERNEL); if (!challenge) { pr_err("Unable to allocate challenge buffer\n"); @@ -216,6 +208,9 @@ static int chap_server_compute_md5( pr_err("Unable to allocate challenge_binhex buffer\n"); goto free_challenge; } + + memset(chap_n, 0, MAX_CHAP_N_SIZE); + /* * Extract CHAP_N. */ @@ -236,6 +231,8 @@ static int chap_server_compute_md5( goto free_challenge_binhex; } pr_debug("[server] Got CHAP_N=%s\n", chap_n); + memset(chap_r, 0, MAX_RESPONSE_LENGTH); + /* * Extract CHAP_R. */ @@ -250,6 +247,7 @@ static int chap_server_compute_md5( } pr_debug("[server] Got CHAP_R=%s\n", chap_r); + memset(client_digest, 0, MD5_SIGNATURE_SIZE); chap_string_to_hex(client_digest, chap_r, strlen(chap_r)); tfm = crypto_alloc_shash("md5", 0, 0); @@ -286,6 +284,7 @@ static int chap_server_compute_md5( goto free_desc; } + memset(server_digest, 0, MD5_SIGNATURE_SIZE); ret = crypto_shash_finup(desc, chap->challenge, CHAP_CHALLENGE_LENGTH, server_digest); if (ret < 0) { @@ -293,6 +292,7 @@ static int chap_server_compute_md5( goto free_desc; } + memset(response, 0, MD5_SIGNATURE_SIZE * 2 + 2); chap_binaryhex_to_asciihex(response, server_digest, MD5_SIGNATURE_SIZE); pr_debug("[server] MD5 Server Digest: %s\n", response); @@ -310,6 +310,9 @@ static int chap_server_compute_md5( auth_ret = 0; goto free_desc; } + + memset(identifier, 0, ARRAY_SIZE(identifier)); + /* * Get CHAP_I. */ @@ -393,6 +396,9 @@ static int chap_server_compute_md5( " password_mutual\n"); goto free_desc; } + + memset(digest, 0, MD5_SIGNATURE_SIZE); + /* * Convert received challenge to binary hex. */