From patchwork Wed Feb 7 16:12:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nilesh Javali X-Patchwork-Id: 10205565 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 3F45260247 for ; Wed, 7 Feb 2018 16:12:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FE6628F82 for ; Wed, 7 Feb 2018 16:12:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23AB228FB3; Wed, 7 Feb 2018 16:12:49 +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,DKIM_SIGNED, DKIM_VALID,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 5781E28F82 for ; Wed, 7 Feb 2018 16:12:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754551AbeBGQMp (ORCPT ); Wed, 7 Feb 2018 11:12:45 -0500 Received: from mail-sn1nam01on0062.outbound.protection.outlook.com ([104.47.32.62]:57922 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754166AbeBGQMn (ORCPT ); Wed, 7 Feb 2018 11:12:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=LEVKb3/+izL5ImCa+1TKarYzAol+BIodJwcazQ/IJaU=; b=h6SR3FdmvIari9itNFKi6wTSN5lkmMTr9Sc3icQ69fKOAUY5MqmGsDZn6pMpuNghB4Ydzz+pO5JtMN0JBf+87a+TG2ozfRWGj0HGLY3YOv5XcJSiClAoAYUWLb3M6DTSykLYXrnpzC6uEMa6ME6BQX4c6A9qyl0KXYtUcwzMXSQ= Received: from CO2PR07CA0080.namprd07.prod.outlook.com (2603:10b6:100::48) by CY4PR0701MB3812.namprd07.prod.outlook.com (2603:10b6:910:94::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Wed, 7 Feb 2018 16:12:41 +0000 Received: from BL2FFO11OLC006.protection.gbl (2a01:111:f400:7c09::157) by CO2PR07CA0080.outlook.office365.com (2603:10b6:100::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.485.10 via Frontend Transport; Wed, 7 Feb 2018 16:12:41 +0000 Authentication-Results: spf=fail (sender IP is 50.232.66.26) smtp.mailfrom=cavium.com; vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=cavium.com; Received-SPF: Fail (protection.outlook.com: domain of cavium.com does not designate 50.232.66.26 as permitted sender) receiver=protection.outlook.com; client-ip=50.232.66.26; helo=CAEXCH02.caveonetworks.com; Received: from CAEXCH02.caveonetworks.com (50.232.66.26) by BL2FFO11OLC006.mail.protection.outlook.com (10.173.160.95) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.20.464.8 via Frontend Transport; Wed, 7 Feb 2018 16:12:41 +0000 Received: from dut1171.mv.qlogic.com (172.29.51.171) by CAEXCH02.caveonetworks.com (10.17.4.29) with Microsoft SMTP Server id 14.2.347.0; Wed, 7 Feb 2018 08:12:37 -0800 Received: from dut1171.mv.qlogic.com (localhost [127.0.0.1]) by dut1171.mv.qlogic.com (8.14.7/8.14.7) with ESMTP id w17GCbxi013014; Wed, 7 Feb 2018 08:12:37 -0800 Received: (from root@localhost) by dut1171.mv.qlogic.com (8.14.7/8.14.7/Submit) id w17GCblo013013; Wed, 7 Feb 2018 08:12:37 -0800 From: Nilesh Javali To: , , CC: , Subject: [PATCH v3 1/2] qedi: Fix truncation of CHAP name and secret Date: Wed, 7 Feb 2018 08:12:35 -0800 Message-ID: <20180207161236.12975-2-nilesh.javali@cavium.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20180207161236.12975-1-nilesh.javali@cavium.com> References: <20180207161236.12975-1-nilesh.javali@cavium.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:50.232.66.26; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(396003)(346002)(39380400002)(376002)(39860400002)(2980300002)(1109001)(1110001)(339900001)(189003)(199004)(2906002)(50226002)(356003)(336011)(36756003)(51416003)(26005)(4326008)(5660300001)(575784001)(2950100002)(305945005)(81166006)(2201001)(81156014)(85426001)(8676002)(72206003)(478600001)(86362001)(54906003)(47776003)(76176011)(105606002)(8936002)(69596002)(16586007)(80596001)(42186006)(107886003)(316002)(48376002)(186003)(1076002)(50466002)(110136005)(106466001)(87636003)(219293001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR0701MB3812; H:CAEXCH02.caveonetworks.com; FPR:; SPF:Fail; PTR:50-232-66-26-static.hfc.comcastbusiness.net; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC006; 1:NG6CgX0FtQAhU1zjHLCqWJQYXq9RXCtcEivgq6YoeufnO9ue1p6yr+xy8mPe376wlJYxSuY3yRsucqvSHLfNIClGcw41kBRe6poGXGEGzjKRcLemozeZFdMn6vy1Y27L X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1966b226-e240-4870-fe61-08d56e459d63 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060); SRVR:CY4PR0701MB3812; X-Microsoft-Exchange-Diagnostics: 1; CY4PR0701MB3812; 3:7SQIDfhdyKkTfZKq1k8vsGTTB6dS4r9vh3PVG0H3d0D5xpuX73noKIDqMi26+jOI4lxEshJjwm9+2D7cZzCkVGoqNnjubL0nuj4kSvytF3IwXwY1vzg9tJfIbKyT8s0IMz9+Dlo9Mx130719hjzrKmED/Fn7tgpoijx+MerDqJiNscS+r20AbLeKafhduCcbr6ejXqwf5rFgmyGDsl/aE0IcsW3fThk7zt4HfYl1+3i2puBXzSD7WP3faiZxKfMUy/EPLEKnGbER5ngVQulIctqz31jzozAdmD+RBYcQ12DAgccDJNOvi1XlE/Tb1X1B1Bo/4WMry1fZJ9iXfyHQyMwy9UY/bQ23MoFDnpy4YAw=; 25:GKeUgmoY1vtSsR+DxBbdME7dvW2hwqvHIW0pMu8LxWxC0qE7a+K80tNUUdbtKlkr1ik8d85D08dVI0cMOz3K3nOe4wp0/T2WIlGO5EYrokDOHDm5kNYf3R07Me5gIzL504gyp0Dzdpr6uvaUGEBIVwdnSRIWbN8UovTv0P/KsGgmNTpFLWqHK2a7tvEgZGlLhLw+0P/3n3U8Aqe+WFdhF1L+yx43ltdydhI3EDdweYbN4SofA0skHKEZY+ttwG0y4qBLEqJPhPvPOasmJ8iYb3V/yygolAgHqHOgxHAjV3a2hM+42kx4o5xUXDlZctGOG9V8NMC/nN3+6nkKa3TDMA== X-MS-TrafficTypeDiagnostic: CY4PR0701MB3812: X-Microsoft-Exchange-Diagnostics: 1; CY4PR0701MB3812; 31:9Xtmhrv6ygCbciABq6OHyQkKcHWdYotfTodprOPhNeq5AhWvnPcCXy6i+12MIQk5XAct49z2L8sxc3a0K1Db81y2myPLZebUBlWC9Hwy/+hunY318ASFRXJj8FpesME76/hVgmDRjiAE8TJAqd35+hVbhAkUErp/oD/MOe5hRYruBVe1BJF13VFRJUmyjp/KL3BXhRk3sxF1f9mAh5Sy57PUN+j5uhAkCafEnBaK2lM=; 20:1bjcyS6729sz2hyxWQcCD+q9yGkXawrumZwswlHzEjF+Sm2x7bTmk/j2ESKTvGtTmaN/XmTEkPOgopZ8Uiz7XU2B3FG2v7TmTOq/O7vPEwTEDFyuqMxi/lutMsmsE9do/9WdCdz16WWKAD/LtNVhR4QYYzp/pX9H9lGGh/SMvo0U62FxEzhUA51lWMGQVwzwuU4NNp9NIRpqxTPtFk/B+IPr5RPrh9vv/aKUaf/mfwQB+vfujd5kWXjWXaMI1NLasCBd4lO2COa2A7tXhPccfgLVqSahjepjPB4hse5zQkUsl+MTahqCjVgPP8Lc8aSHHCZydW9IJ9tiYZPFqXAVbI7w6a+U5XGp5pI3Ib+T3Y8qk2nK1Rs4FaXhbJ53rHEKh5LyKiMzxGdaasrmnLsriUul2AYTP2IwunuCib8GxXmuAHpSwzhlcZtsXwcHwz4pHDUCpWz7+MNkxDEOuQQUV7CLLjaJGtAP481eiaSMck8c1oBbpcl8VEjZMXL9d2cl X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231101)(2400082)(944501161)(10201501046)(6041288)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:CY4PR0701MB3812; BCL:0; PCL:0; RULEID:; SRVR:CY4PR0701MB3812; X-Microsoft-Exchange-Diagnostics: 1; CY4PR0701MB3812; 4:YEWArfP1Yr1f+DjV07ykBFgjzAmYZacKlJ6Hi5Kiyg+4lmmecoH54ki4t9vjfzRxC82F7hRtJCrA/GSCdSU7vQl03TgDaOKgYztsLeRro2YQLexedmHYoeJkCvz0qoQkBnxMCVeq4eMJrf4x9hPl/qitkyBduNGPbrtneg6Uckj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TeV9+kKuOvPumOjJaVX7t4EIrFUcqoKDgKoTmOolvwxB/QHu8ISnPjKI+MkGewIQfPHWRm0sYBR6cZrJtqR6XE=; 24:GpWsh9EneMr3a6cFFQszu/1ANaNQ5WKYLvSLv1EoU7hp4tQRUm8cpZJFozsvKbDi1hUlUfJN/Ih228SOdzUugPUQYK23HjN03c9+iIcVhA4=; 7:lepqSG5kzvUAd/av3l+/eUglMCr3a3d8jGcG5iUfxDxSitUuTbehJKXUfyGAQeiqcPkZa3dPtRaonq4CcRrfNwoS8BWaiuOGI0ErKgCI68vmnuq0qFVbJyPfW0ZgQBobac8U2TD4jKTxctrYHWsPp5YFZMq8wJXZYFiaeyVTxg4bp93CeCR/UEFsUw2k/heEnBSwfeoRlth1+fqDrgPemWK3A8JgIjHBTB3RKCxLmqgdrQumPgguESFGZnDzfhXw SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2018 16:12:41.1736 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1966b226-e240-4870-fe61-08d56e459d63 X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=711e4ccf-2e9b-4bcf-a551-4094005b6194; Ip=[50.232.66.26]; Helo=[CAEXCH02.caveonetworks.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR0701MB3812 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andrew Vasquez The data in NVRAM is not guaranteed to be NUL terminated. Since snprintf expects byte-stream to accommodate null byte, the CHAP secret is truncated. Use sprintf instead of snprintf to fix the truncation of CHAP name and secret. Signed-off-by: Andrew Vasquez Signed-off-by: Nilesh Javali Reviewed-by: Bart Van Assche Signed-off-by: Chris Leech Signed-off-by: Lee Duncan --- drivers/scsi/qedi/qedi_main.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c index 8808f0d..deaed93 100644 --- a/drivers/scsi/qedi/qedi_main.c +++ b/drivers/scsi/qedi/qedi_main.c @@ -1842,8 +1842,8 @@ static ssize_t qedi_show_boot_ini_info(void *data, int type, char *buf) switch (type) { case ISCSI_BOOT_INI_INITIATOR_NAME: - rc = snprintf(str, NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, "%s\n", - initiator->initiator_name.byte); + rc = sprintf(str, "%.*s\n", NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, + initiator->initiator_name.byte); break; default: rc = 0; @@ -1910,8 +1910,8 @@ static umode_t qedi_ini_get_attr_visibility(void *data, int type) switch (type) { case ISCSI_BOOT_TGT_NAME: - rc = snprintf(str, NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, "%s\n", - block->target[idx].target_name.byte); + rc = sprintf(str, "%.*s\n", NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, + block->target[idx].target_name.byte); break; case ISCSI_BOOT_TGT_IP_ADDR: if (ipv6_en) @@ -1932,20 +1932,20 @@ static umode_t qedi_ini_get_attr_visibility(void *data, int type) block->target[idx].lun.value[0]); break; case ISCSI_BOOT_TGT_CHAP_NAME: - rc = snprintf(str, NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, "%s\n", - chap_name); + rc = sprintf(str, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, + chap_name); break; case ISCSI_BOOT_TGT_CHAP_SECRET: - rc = snprintf(str, NVM_ISCSI_CFG_CHAP_PWD_MAX_LEN, "%s\n", - chap_secret); + rc = sprintf(str, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, + chap_secret); break; case ISCSI_BOOT_TGT_REV_CHAP_NAME: - rc = snprintf(str, NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, "%s\n", - mchap_name); + rc = sprintf(str, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, + mchap_name); break; case ISCSI_BOOT_TGT_REV_CHAP_SECRET: - rc = snprintf(str, NVM_ISCSI_CFG_CHAP_PWD_MAX_LEN, "%s\n", - mchap_secret); + rc = sprintf(str, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, + mchap_secret); break; case ISCSI_BOOT_TGT_FLAGS: rc = snprintf(str, 3, "%hhd\n", SYSFS_FLAG_FW_SEL_BOOT);