Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3931684imm; Mon, 8 Oct 2018 11:54:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV60WFfnqY9wv7M40qB58y1xkOMwi80djCQTeaRDx8eEjnnUlzaAMUFZYtFwgtBgX4AECH2ZO X-Received: by 2002:a65:6458:: with SMTP id s24-v6mr12992746pgv.29.1539024843157; Mon, 08 Oct 2018 11:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024843; cv=none; d=google.com; s=arc-20160816; b=hvF6WccDudxz7UHb+c7+5ZT8UD2NLuCAbeLIwYhUuTop3wJkWILMN6D70B500QECw9 jLDJp4UEpUHHftQLrSimIpBUy/5Ltx6+prFdCTJsiDsQbKsZC4gG5m799JXrK2J1q457 WhQU7bjgZRpWM8WnQopthh8qh/8v7i7ufsT7An7KyDv20HP5tvnTLdKAbKpBkqKLr9N2 zQykuyo9r2tn2yc/rQLQv0CsPr6htofEoDg0dy/xjf+XfjTJnCZ/J9ZDp4HrYjhinG4W 13fVG3MwZ5woSNwOkuL5On9mIBrZLjyE2Ng2rimSmMJ9S/z9y2pgh2dQl13zFIvn3NPf OMuA== 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=52aAUPCZUDcVTBt6KuQaVM0fIV/zQAzSuRvLG7h8RGs=; b=b9beJEMLTNKmQG5Nfs4LS9lbeCKCAsnfpAQXikmByUZRwVIEsghs1wEZnrlSPQqFqe UtQ/rIF3daQQanvbAdlFJ+cbD2uXu3nFMnVcepIVJu1sjp9jc4rrw5sPoDc12EcIYn6x i3G+9Jm8Ac12xkazOmyetmKmTCSP6uKtpE8ub8TV5bWdpEtXd5zvMHNIvZDOgXxYXx4H Nne6AeLY9i+yni+uLAbhpFMP8BSrsA1BMpDSELR54qcL13Lu8HPopVYGwAd+kn/8YqsN kb+qWfDkzlitQO4mfVuSu/+qld3HX1FTQ/f10Rx/N74yTKSI4+ckATHDMFVUliozGDz9 tbvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AVphk7hI; 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 a13-v6si17790171pgi.474.2018.10.08.11.53.48; Mon, 08 Oct 2018 11:54:03 -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=AVphk7hI; 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 S1732543AbeJICFh (ORCPT + 99 others); Mon, 8 Oct 2018 22:05:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:55746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727260AbeJICFg (ORCPT ); Mon, 8 Oct 2018 22:05:36 -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 55F0720645; Mon, 8 Oct 2018 18:52:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024749; bh=T3JeWp3NUeqHzIotOivlbhvJGwycygn/vNdwIYu804A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AVphk7hIxAmr5sqW1kzU3o7ZIWe3a6PXhY1Yoo9bGsVw1Fi9lC8GmGk0CWDv/pA3w dBpph3WLnRaFLeNgMu7KTa8alYFdeBElClTF9GBakiHoSLZCBDhfZ544LZ7FJuMQt7 5WruqARnVLJLcvWt/gR0YnuNbDdYdCPz6RK2ec8o= 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.18 117/168] fs/cifs: suppress a string overflow warning Date: Mon, 8 Oct 2018 20:31:37 +0200 Message-Id: <20181008175624.491312579@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@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.18-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 @@ -601,10 +601,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);