From patchwork Tue Feb 6 13:12:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nilesh Javali X-Patchwork-Id: 10203075 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 6413C605BA for ; Tue, 6 Feb 2018 13:14:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B0F92888B for ; Tue, 6 Feb 2018 13:14:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F7F628B3C; Tue, 6 Feb 2018 13:14:42 +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 856BD28BEF for ; Tue, 6 Feb 2018 13:12:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753083AbeBFNMa (ORCPT ); Tue, 6 Feb 2018 08:12:30 -0500 Received: from mail-bn3nam01on0061.outbound.protection.outlook.com ([104.47.33.61]:3779 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753037AbeBFNM1 (ORCPT ); Tue, 6 Feb 2018 08:12:27 -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=9iCiQ9J8hbCPfAe1x1Xtsmd5qUOoXrd1AukW6kczCWg=; b=lHRDeJ+Fox2KazZrXgUcxaPgW6CR1WTDUlWx+VQPwQW3wXsdHqn2OCzpzf/u4RKrCLLL+4xnFlwe+QtRfvZpHyKqo72xkAK1G/M1mvjFZkNy2P0Ylhcp1t58TPUglPNZ/fQ0T2HOWOJTUcaRQBS0JteFlBfwGaA2CKQGjiQuWyA= Received: from DM5PR07CA0045.namprd07.prod.outlook.com (10.168.109.31) by BN3PR07MB2513.namprd07.prod.outlook.com (10.167.4.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Tue, 6 Feb 2018 13:12:25 +0000 Received: from BL2FFO11FD045.protection.gbl (2a01:111:f400:7c09::158) by DM5PR07CA0045.outlook.office365.com (2603:10b6:3:16::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.464.11 via Frontend Transport; Tue, 6 Feb 2018 13:12:25 +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 BL2FFO11FD045.mail.protection.outlook.com (10.173.161.207) 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; Tue, 6 Feb 2018 13:12:25 +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; Tue, 6 Feb 2018 05:12:20 -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 w16DCJqT018223; Tue, 6 Feb 2018 05:12:19 -0800 Received: (from root@localhost) by dut1171.mv.qlogic.com (8.14.7/8.14.7/Submit) id w16DCJBu018222; Tue, 6 Feb 2018 05:12:19 -0800 From: Nilesh Javali To: , , CC: , Subject: [PATCH V2 1/2] qedi: Fix truncation of CHAP name and secret Date: Tue, 6 Feb 2018 05:12:18 -0800 Message-ID: <20180206131219.18184-2-nilesh.javali@cavium.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20180206131219.18184-1-nilesh.javali@cavium.com> References: <20180206131219.18184-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)(376002)(346002)(39380400002)(39860400002)(2980300002)(1109001)(1110001)(339900001)(199004)(189003)(356003)(80596001)(8676002)(50226002)(69596002)(47776003)(305945005)(81156014)(2950100002)(8936002)(5660300001)(81166006)(36756003)(105606002)(107886003)(86362001)(50466002)(48376002)(4326008)(85426001)(575784001)(2906002)(2201001)(72206003)(478600001)(87636003)(51416003)(76176011)(316002)(186003)(106466001)(54906003)(110136005)(1076002)(42186006)(336011)(16586007)(26005)(219293001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR07MB2513; H:CAEXCH02.caveonetworks.com; FPR:; SPF:Fail; PTR:50-232-66-26-static.hfc.comcastbusiness.net; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD045; 1:5xp7K1Vqekk94uDSrPEqfkMvaiSQlWykhQwnHXcOFIdxnIb2quWJocxNA3uv2nf7Qp5yPPUKXtt6cdOFh0wZMNPjktAtW1gZPX5/PhPGpnO5/fbExUsX7SjZ//CwgAcd X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 185a6889-92ed-429a-64d5-08d56d634437 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060); SRVR:BN3PR07MB2513; X-Microsoft-Exchange-Diagnostics: 1; BN3PR07MB2513; 3:BFrHM0vPszG0W0aceFBv4Msccb79XDBSfU7uWfqd+6959WtE26LIcfL7SGCWWOZphCOc48RysNXF/OjEKAdi4TqpQnIn9nBROza45LMuDyxny/m/QDR+KNsT3xd+vNTOA8h418d1fCWjPE0JXBcF7rs1Lll6Q8yipYkStrjHYxMTCRBHIF1A7jGCsqqFrW83JqEh2ieCm8kunISPIgUcpfoam1oqfaWc6WXk5XXTcFEYrVPyVJ5+GljmpCyqWySfzO67DRoQbfXHipTe/Y7YPS8gpwbcbUT25iW9jkoKNV1c1w9IofqwD1OG6RFLHvrppDCR3JUmET/579V0RHShFA==; 25:GUJ1CPUeJkLP5qter1A000w55QWRxvy9ZU7Zz6aLI/bClnm3V0/mfUPI/nx5+V2ayrTjQ7Oa5titnrQx/mOAE/eOA4dDN8IkHebWymUFnrcI5YaimOg0qTPjkccCzzyHREcFelJhxjAagtmPBQQiogU0dgHRjkQ6yWPy8bb+CJkvf0T9I6bXoOHIQVMy29VgwmyucGgJI8c1jYmG+h3aQwbc+JZvxinVMbturtRO7eE6vz7bmXQoR9LuRLQP8LOb1zZ+dX7sRJp3dY6xTb2B88MouHS9FlYk5Wl/MN0xgUpBcoKqwDDV19jotsU3P23nL0XEHiGrk8e9jf3Xe8GZBg==; 31:q1UP5d22ldwcROchUD3ZuV1nJNtUUg5K6ly5IB7CFQALj4LruJA3DBcnR84Ql/VsRmdXc74l515LsNRlLFKB9l8RinIj9GP+F8hmjAt0BOEaKoofLpjtBvL+g85zY0vizwS1rjxypu3WjjvH7H09AbBNSOrXZKRiUurCJ8AgE3qAaF9MhkQHmIkG5adwsuPgMH1Xzc3EAUBHiEjOx+wYxcJC0KeuXpeIf6sdhYbLG18= X-MS-TrafficTypeDiagnostic: BN3PR07MB2513: X-Microsoft-Exchange-Diagnostics: 1; BN3PR07MB2513; 20:s1lKUFUIsQoXpr9vPeXBAXfM2jvQUf0z6fSL7bZtFvYLqzKZAv3k0L997iLwAt++W4zIrHLa1zIuHIeO+Rdk5qFOxUcgayENWBqo2hFOe5+vjS6DuKB/XofxDx4guVWYJvn0JaouigJ8imKY8rl5un33WPsKqPm2g3q+2AoaMmIXM/Wv+ErFeNbIoFD/0E58N3ONKJObpaIW0qUSF7uTssjSEZl2pEMRThOpvQbuPUr7YVxLWGKAnTDwhhFLzlBQ9aixxm2LF3C6rZb7M5bxIvcq/nchaojyoaA2QMwEMcShMKFCsbcyeD8qcsokcalDNkQjdacL/uZx0BxvFWuRZutCidtyfzHMBsN3xs/lgsXWRO1bdfP2W/SZIjigUlv1boVeW9TnVB6M6maz6StyUWDQqjPxAeufEf+driZ1sl3sJQDzHGQTwA0RvKxEVk3Wtp/8cEiEpl61rNeKIDvO1WJPkLGltejO39+bKauphnLNcyClUovOG6Q8536+sRbF; 4:Ag0FmZWMTyJaDAgZ7bQ9U04DurNTz7kvQ4lZLG8hpBjkc/oueM9maIGmZM5edHl4FOL6zjpk35fzcbLtzBkZK2LyPgrzLmovpGI8Frhl0OWV8AYfpD5f2W+7u83xsF+/otzG1plqk74AZl4Yo4B5WxvK6SN0ZEm+8A5+CT+ovtXRVs2jDNhT3Qqx32T6+QSw9KdOEu7UIORy73xvFuWPAJ9F5nHFaVAXXnhd4ffAyAZbylN7Iregj4sHzKjl2F/bDZKjOxblsxZwobtM1zlkrQ== 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)(3002001)(3231101)(2400082)(944501161)(93006095)(93001095)(10201501046)(6041288)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:BN3PR07MB2513; BCL:0; PCL:0; RULEID:; SRVR:BN3PR07MB2513; X-Forefront-PRVS: 0575F81B58 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR07MB2513; 23:HTA6IaFHIE/4OMYhlUzMCONy9OhLq1koqGtts8I+x?= =?us-ascii?Q?cnw/gOik/8PcIy/KTcxqKCW4ZKRzeOPKfD7WEup1EUnS+Dw4dYJykIOhHiH3?= =?us-ascii?Q?+Hzn/WJ0eS7Xqf6hZjmnn1sODBXGQAQ5BDh8ZaWDWTJ2eDMYO1q4vZAmfR38?= =?us-ascii?Q?GsKaNS5yz1tynQA16TLgvdv0iufADrXapFXrzeryonFoxbB/VzurNfKXO0Fw?= =?us-ascii?Q?k+abQtrFc65gFiSQOfsVvcLTpTGMB3ODQFrQiO6Y8klFmcRsxg8sRhsRGaXN?= =?us-ascii?Q?/QOeZliN8r4AH4ZnDIGX8Eap25feZeD5bVsTk+FeT2y65QBWsp4OUWY1vcEK?= =?us-ascii?Q?vnuDo3/aqq3hU+lbeqBYtCzerafI9LHnEvpQN7KG+PxiMha+Kk4CeSL6MbIn?= =?us-ascii?Q?m7Pp2xbz7syKVfir9Vv0mHv1r768Z4c+Z6Q+4EOzeB3vpyFuPpfIaxXP3THg?= =?us-ascii?Q?NokrI0d2bxFcvwLS7sFSS73deogbgWNpYlm1uW44celXSAzI0sOV0wCGRPBx?= =?us-ascii?Q?zliyLNog8AAw97jwqO06qDXkL2Og0rR9LRLzXkWg7CdqptU46GN35t6ui4ah?= =?us-ascii?Q?pEBE1neHSnZU9dGATEXLU3CFHxwK/lyhhgfPAEytxrBog7LAdymA1hyh8532?= =?us-ascii?Q?QlbYMuQwAj0fd74LuOWshZ5FMokTOBn5oZhJw9mU8FkMxpBLG5KqfILmhfl5?= =?us-ascii?Q?JvMcQM6gWDNnmaoLuc5BnTUIqWHcyrpYQzAPvTpTzxDDR4JGRllbyr8ABjOS?= =?us-ascii?Q?DWQroG3T5/5AdSW7/V+Seoy1ORkQzgU/H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6mLd5HbU/N5OYI1f7cIk5MXXwIo5/YAehB0bmc323L1nMXJG7f9pcpFLgUNMoXw1dEP3cuM4w0ZrT8+3hQ0Dl1HMMkSNCo4=; 7:k6CR6JJ5yWW3Lt+nGa3eZcI3KifNoCH8sxS8peocT8ZG79rTqxf2QNO0rxYQnhHRjpLNbOrDCQcsKfnTFUlcn8cMXxfZIPZQ718CXZbgZIKGQfym/b5sF5Si3ACyy9FhY/jzZrejyqlI3VTc7Dg/+82PIaj710S7j5g0AGrV9J3ZBUEvULS8CyCOE/y5fqlHuPyMonUwl0uyqpRtPaXtGxDVP/Lr1u1/wUqdRLNbliW8biN7KkFHkHN9IXc/EMlQ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 13:12:25.3032 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 185a6889-92ed-429a-64d5-08d56d634437 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: BN3PR07MB2513 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. Copy the data upto the element size or to the first NUL in the byte-stream and then append a NUL. Signed-off-by: Andrew Vasquez Signed-off-by: Nilesh Javali --- drivers/scsi/qedi/qedi_main.c | 45 +++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c index 8808f0d..f3dd438 100644 --- a/drivers/scsi/qedi/qedi_main.c +++ b/drivers/scsi/qedi/qedi_main.c @@ -1705,6 +1705,27 @@ void qedi_reset_host_mtu(struct qedi_ctx *qedi, u16 mtu) qedi_ops->ll2->start(qedi->cdev, ¶ms); } +static ssize_t +qedi_show_copy_data(char *buf, size_t size, u8 *data) +{ + size_t i; + + if (!data) + return sprintf(buf, "\n"); + + /* + * Data not guaranteed to be NUL terminated. Copy until NUL found or + * complete copy done. + */ + for (i = 0; i < size && data[i]; i++) + buf[i] = data[i]; + + /* Data copy complete, append NEWLINE and NUL terminator. */ + buf[i] = '\n'; + buf[i + 1] = '\0'; + return strlen(buf); +} + /** * qedi_get_nvram_block: - Scan through the iSCSI NVRAM block (while accounting * for gaps) for the matching absolute-pf-id of the QEDI device. @@ -1842,8 +1863,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 = qedi_show_copy_data(str, NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, + initiator->initiator_name.byte); break; default: rc = 0; @@ -1910,8 +1931,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 = qedi_show_copy_data(str, 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 +1953,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 = qedi_show_copy_data(str, 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 = qedi_show_copy_data(str, NVM_ISCSI_CFG_CHAP_PWD_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 = qedi_show_copy_data(str, 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 = qedi_show_copy_data(str, NVM_ISCSI_CFG_CHAP_PWD_MAX_LEN, + mchap_secret); break; case ISCSI_BOOT_TGT_FLAGS: rc = snprintf(str, 3, "%hhd\n", SYSFS_FLAG_FW_SEL_BOOT);