From patchwork Fri Aug 5 06:48:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitra P B X-Patchwork-Id: 9264829 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 951776089F for ; Fri, 5 Aug 2016 06:48:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 851CE28236 for ; Fri, 5 Aug 2016 06:48:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 797BE28422; Fri, 5 Aug 2016 06:48:27 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 EA01F28422 for ; Fri, 5 Aug 2016 06:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759472AbcHEGsL (ORCPT ); Fri, 5 Aug 2016 02:48:11 -0400 Received: from mail-qk0-f180.google.com ([209.85.220.180]:34397 "EHLO mail-qk0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759460AbcHEGsI (ORCPT ); Fri, 5 Aug 2016 02:48:08 -0400 Received: by mail-qk0-f180.google.com with SMTP id p186so129246663qkd.1 for ; Thu, 04 Aug 2016 23:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:references:in-reply-to:mime-version:thread-index:date :message-id:subject:to:cc; bh=T+UFtfHp9ovlIWuW0XhEBmxYayz+QfPRY11CmzCgNgU=; b=b9tKIx9B6AY+5tPNtIL2R9rJzkkJTTRWRRyp6zj0wgz9DJoL0BsZGQ16py0k1tn/+8 d8m4Qq3uXa6BfTwG56slAu5Ek1ZXwmGfaZxJAPTg23+WUWqBUJiCLx5VyUvf+OUOzL0S xPgswEgqa3JnJa7EvucaIzRFmyeosV32PyyDk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:cc; bh=T+UFtfHp9ovlIWuW0XhEBmxYayz+QfPRY11CmzCgNgU=; b=Gu8ufThgVOLbNynBebs1+YsY3c4UNXYehTg3ajFqXFcsBC6H6GviXGsmAYhrroX+Jr CQInuNd0hFy43NpRMF66Mdw4HgRMx7DEy7Gw5lBjzNjwAR98ftgYH9NFV9m3P9mLswG/ 7yFdnILacKaK1iJStjx1NKQyHEJYeMNSrk7H7vjMKNn9UdwaTRelcGvbSZwi2d3miXDN CFMK1JoAxHkx3fhieBLVHJgt3QsTL1Jmi2JRwZphjpEhskqXBDubC4xcEyQn58uZubDr hxEjsL/DFodU61kTbizu9MYtZGYY9tDj5DFK/nyHgdXTNlbsJvrioK5QQL0KcB5MgcfC RuYw== X-Gm-Message-State: AEkoouvTG9W2c9cUfHf7abOH4OSpBGmGUu0Vdsy41HDGWxh7/7dz5mEtUEN/T+Z9je3MwCuUXQsbQpR+BdiQz69I X-Received: by 10.55.189.65 with SMTP id n62mr11419134qkf.129.1470379687243; Thu, 04 Aug 2016 23:48:07 -0700 (PDT) From: Chaitra Basappa References: <8b53a29b3ec90c9a7030e8fa3e1555ad5802dce9.1469680625.git.calvinowens@fb.com> In-Reply-To: <8b53a29b3ec90c9a7030e8fa3e1555ad5802dce9.1469680625.git.calvinowens@fb.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQMSpE6a4MSmMGjN6hEaRsRIg/kJ/524gdUQ Date: Fri, 5 Aug 2016 12:18:05 +0530 Message-ID: <866595a5d5bb579de68d0c3f06bdc43c@mail.gmail.com> Subject: RE: [PATCH] mpt3sas: Ensure the connector_name string is NUL-terminated To: Calvin Owens , Sathya Prakash Veerichetty , Suganath Prabu Subramani , "James E.J. Bottomley" , "Martin K. Petersen" Cc: PDL-MPT-FUSIONLINUX , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com 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 Hi, Please consider this patch as Acked-by: Chaitra P B Thanks, Chaitra -----Original Message----- From: Calvin Owens [mailto:calvinowens@fb.com] Sent: Thursday, July 28, 2016 10:16 AM To: Sathya Prakash; Chaitra P B; Suganath Prabu Subramani; James E.J. Bottomley; Martin K. Petersen Cc: MPT-FusionLinux.pdl@broadcom.com; linux-scsi@vger.kernel.org; linux-kernel@vger.kernel.org; kernel-team@fb.com; Calvin Owens Subject: [PATCH] mpt3sas: Ensure the connector_name string is NUL-terminated We blindly trust the hardware to give us NUL-terminated strings, which is a bad idea because it doesn't always do that. For example: [ 481.184784] mpt3sas_cm0: enclosure level(0x0000), connector name( \x3) In this case, connector_name is four spaces. We got lucky here because the 2nd byte beyond our character array happens to be a NUL. Fix this by explicitly writing '\0' to the end of the string to ensure we don't run off the edge of the world in printk(). Signed-off-by: Calvin Owens --- drivers/scsi/mpt3sas/mpt3sas_base.h | 2 +- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) sas_device->connector_name[0] = '\0'; @@ -5508,8 +5509,9 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { sas_device->enclosure_level = le16_to_cpu(sas_device_pg0.EnclosureLevel); - memcpy(&sas_device->connector_name[0], - &sas_device_pg0.ConnectorName[0], 4); + memcpy(sas_device->connector_name, + sas_device_pg0.ConnectorName, 4); + sas_device->connector_name[4] = '\0'; } else { sas_device->enclosure_level = 0; sas_device->connector_name[0] = '\0'; -- 2.8.0.rc2 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h index 892c9be..eb7f5b0 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.h +++ b/drivers/scsi/mpt3sas/mpt3sas_base.h @@ -478,7 +478,7 @@ struct _sas_device { u8 pfa_led_on; u8 pend_sas_rphy_add; u8 enclosure_level; - u8 connector_name[4]; + u8 connector_name[5]; struct kref refcount; }; diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index cd91a68..acabe48 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -5380,8 +5380,9 @@ _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { sas_device->enclosure_level = le16_to_cpu(sas_device_pg0.EnclosureLevel); - memcpy(&sas_device->connector_name[0], - &sas_device_pg0.ConnectorName[0], 4); + memcpy(sas_device->connector_name, + sas_device_pg0.ConnectorName, 4); + sas_device->connector_name[4] = '\0'; } else { sas_device->enclosure_level = 0;