Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3911686imm; Mon, 8 Oct 2018 11:33:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV637qljfKx98DnUgP/c0kwhf6q7USOrP51DFidpnkSXuKv+THvfAsZ7Bg7SIVC8Se9B3Tf/1 X-Received: by 2002:a62:178f:: with SMTP id 137-v6mr25646966pfx.215.1539023631946; Mon, 08 Oct 2018 11:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539023631; cv=none; d=google.com; s=arc-20160816; b=Jv3ScGIN8GbzdETk62yEEEvT45QYvfZJRtDclNhvfhBWkJyPAHHjDEVeqe/x0XWC+/ 4EV4k/mB49bPFwTV0Wrj/YA/tsX94YT1EHPpMFkCjChjOw6agwZqA1ovmm70ZzS+UDFi h/tf/TZdmdygJmG7U3Wmn7xzvoy1g7dQ+TSLucmmk+04bjU5+FFOmHNqUC4p+qZ/ahil /RDoHUl/bbBurIMxK7iU1cEZYNDVrGGJDchLvmDTvMwcJgNmT28rtV1nkNQN4mHJK07X R7QDs2uHBodv1yapfQn5VXh2keijderSE7j4iZu0Opq4jA8dbeEKcb2vW5XRYt+duPQ8 Ua2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8zojnJnXi+ETgIWc/1y3nT6bfg+jiyqrVnefOuVz5Ds=; b=B3nTmhongwL8iMTsV06S5mbulGkNAqnV85ynyharrDdmjA16y75UP7WA9VT/0wiVo0 S6mJeI0g2EE4wMVDJ4d+4PKY1pW6fjOa4bKA/IeITZkSj6SkDaTTcGpC04YFctnLLZX8 1J+p8eyEgttkHBUuSshp9dhGQ4QfX+Zd2NO0DG58PDjYoTpl/wp2H6g+I3fCi8XtboSU YXFjb53XZFr+wzDBSZeOPRpb+VCpxbI8cY+uxaQ+jfeBK+3mUXKtVK9n6iTFPNwGXtpI Ilf8/9X96As3V8yvC/mZvLozT7FHVg/nzzBKr9nlX5W3S4GNbEHIz3Ykp/ww+/HxIGyP rmMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="LkYHZh/K"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j12-v6si20673386pfd.222.2018.10.08.11.33.36; Mon, 08 Oct 2018 11:33:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="LkYHZh/K"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726958AbeJIBqR (ORCPT + 99 others); Mon, 8 Oct 2018 21:46:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:56274 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726391AbeJIBqQ (ORCPT ); Mon, 8 Oct 2018 21:46:16 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CE48F2089D; Mon, 8 Oct 2018 18:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539023593; bh=cl8RiUQedHL2BAs1X3hB58R2WG3AiN9SxRrZ8gU3HQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LkYHZh/KVxzXhiGxB1ThvNr7oKhHmSL2T8ZRBDgx9M4RLU2LfYpbdQNaqsIQt4PYY ncINje0/Ny3cWGiNqtVqfo9eixGqGw/Y+MHzZiG77uW8eaXSrSO2JDFjbzyiVj9a5O K8Czam/n1naxOm2xt38Lb1oVOTUuhRbeNSdP4jAA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Tyrel Datwyler , Breno Leitao , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.4 019/113] scsi: ibmvscsi: Improve strings handling Date: Mon, 8 Oct 2018 20:30:20 +0200 Message-Id: <20181008175531.783917170@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175530.864641368@linuxfoundation.org> References: <20181008175530.864641368@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Breno Leitao [ Upstream commit 1262dc09dc9ae7bf4ad00b6a2c5ed6a6936bcd10 ] Currently an open firmware property is copied into partition_name variable without keeping a room for \0. Later one, this variable (partition_name), which is 97 bytes long, is strncpyed into ibmvcsci_host_data->madapter_info->partition_name, which is 96 bytes long, possibly truncating it 'again' and removing the \0. This patch simply decreases the partition name to 96 and just copy using strlcpy() which guarantees that the string is \0 terminated. I think there is no issue if this there is a truncation in this very first copy, i.e, when the open firmware property is read and copied into the driver for the very first time; This issue also causes the following warning on GCC 8: drivers/scsi/ibmvscsi/ibmvscsi.c:281:2: warning: strncpy output may be truncated copying 96 bytes from a string of length 96 [-Wstringop-truncation] ... inlined from ibmvscsi_probe at drivers/scsi/ibmvscsi/ibmvscsi.c:2221:7: drivers/scsi/ibmvscsi/ibmvscsi.c:265:3: warning: strncpy specified bound 97 equals destination size [-Wstringop-truncation] CC: Bart Van Assche CC: Tyrel Datwyler Signed-off-by: Breno Leitao Acked-by: Tyrel Datwyler Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/ibmvscsi/ibmvscsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/scsi/ibmvscsi/ibmvscsi.c +++ b/drivers/scsi/ibmvscsi/ibmvscsi.c @@ -93,7 +93,7 @@ static int max_requests = IBMVSCSI_MAX_R static int max_events = IBMVSCSI_MAX_REQUESTS_DEFAULT + 2; static int fast_fail = 1; static int client_reserve = 1; -static char partition_name[97] = "UNKNOWN"; +static char partition_name[96] = "UNKNOWN"; static unsigned int partition_number = -1; static struct scsi_transport_template *ibmvscsi_transport_template; @@ -261,7 +261,7 @@ static void gather_partition_info(void) ppartition_name = of_get_property(rootdn, "ibm,partition-name", NULL); if (ppartition_name) - strncpy(partition_name, ppartition_name, + strlcpy(partition_name, ppartition_name, sizeof(partition_name)); p_number_ptr = of_get_property(rootdn, "ibm,partition-no", NULL); if (p_number_ptr)