Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3923460imm; Mon, 8 Oct 2018 11:45:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV60C8irZkU/GJt0LNybk9NBqbpS/R4xzMoLtLnbkCrQzl9t0X+x/T625jmwC67acVi07B6Oq X-Received: by 2002:a62:e091:: with SMTP id d17-v6mr26039842pfm.214.1539024325188; Mon, 08 Oct 2018 11:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024325; cv=none; d=google.com; s=arc-20160816; b=ZaVQqEojJbR6me/wq6SMxxe2pj6wx9NlNqFMsGGRGHMswsPuph7MA84Dhhc9Sok6Me NeBv+M8Wn6Tb39QBStj2bqi8CWRDt7ppst3ZpATYAfiBUSSzpNlENsWqduDICHlEUIWI Lp9MJ7lRdUGtHfuKWtjBvcqduZbXHDKkX0zmSgocvzJLrGCcWYcUXb2lxiN6TqQ7A03y E2W7qTZHMM/IrL4uK0zDDlo40HBgHfGsuSz9OXJJvS7vkwL9iywB7u4ncOv0g9lZfLUD Pvmewqayz2mHhVFQw8tY1VLo4cAok7OFqyWfEUuNvHGa7MXCz+FDutD2e4XXYh5fulGT ajgg== 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=S9amS/YdSn1wG3Th44hSAYAK0zBcadU6z2me6aNH+Ek=; b=HqDTOSNHeEnIA1gGM7X06Do9byTBluy6WHg/gugerqK7Ke7uoW/SKQjMEzbuAY0Yc8 oAPA9d/8wTCePe6cW8OHqc8vukrYT4w3S1Brv/Mz2C0+vVmiceKa5CzcGWpnyk8X0oNE P6rC2spjZGOREzT0Ls2iSuZBuyxjHKaDlmr7JdfFP+2jsQps+FLhIb5Y/dJGipPTN7Bs 7wxYiFaXO7umaTr8f6gyFt1e/5+gI/KJFQ27JIyGtdiLAsVlYc1zD3SPDO4gGSXEZW2t orP8mdRRIllzE7/dZAgyhfdwsFWZZHJYJQcyj3eC1M4dyFx/KOJ3aNYs7MGJ5L+IsibM abwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SJRoZxyc; 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 a10-v6si17550942pgk.365.2018.10.08.11.45.10; Mon, 08 Oct 2018 11:45:25 -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=SJRoZxyc; 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 S1730554AbeJIB4r (ORCPT + 99 others); Mon, 8 Oct 2018 21:56:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:44598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730165AbeJIB4r (ORCPT ); Mon, 8 Oct 2018 21:56:47 -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 86031214C2; Mon, 8 Oct 2018 18:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024222; bh=N2w4ABvkO++hvMN2G68Dkt6hAWw5Ksr+hgROQtbwjBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SJRoZxycshGsot+ERkuNbBhA3A8QI/2HzVtqnmdeceIczFGjVBS0a9j45LkSSTlSb b+eIDsKPakBobpuhnuX79nUiezZ2JSvqOAZk3AzEQR0eTmBFPJG+LHZge06nkatlbZ 1u6hSJ+hFivqSMgYO1xXND4T5GlcwgJvELv+2mo4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephen Rothwell , Steve French , Sasha Levin Subject: [PATCH 4.14 62/94] fs/cifs: suppress a string overflow warning Date: Mon, 8 Oct 2018 20:31:43 +0200 Message-Id: <20181008175609.361522977@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175605.067676667@linuxfoundation.org> References: <20181008175605.067676667@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stephen Rothwell [ Upstream commit bcfb84a996f6fa90b5e6e2954b2accb7a4711097 ] A powerpc build of cifs with gcc v8.2.0 produces this warning: fs/cifs/cifssmb.c: In function ‘CIFSSMBNegotiate’: fs/cifs/cifssmb.c:605:3: warning: ‘strncpy’ writing 16 bytes into a region of size 1 overflows the destination [-Wstringop-overflow=] strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Since we are already doing a strlen() on the source, change the strncpy to a memcpy(). Signed-off-by: Stephen Rothwell Signed-off-by: Steve French Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/cifs/cifssmb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -589,10 +589,15 @@ CIFSSMBNegotiate(const unsigned int xid, } count = 0; + /* + * We know that all the name entries in the protocols array + * are short (< 16 bytes anyway) and are NUL terminated. + */ for (i = 0; i < CIFS_NUM_PROT; i++) { - strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); - count += strlen(protocols[i].name) + 1; - /* null at end of source and target buffers anyway */ + size_t len = strlen(protocols[i].name) + 1; + + memcpy(pSMB->DialectsArray+count, protocols[i].name, len); + count += len; } inc_rfc1001_len(pSMB, count); pSMB->ByteCount = cpu_to_le16(count);