Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp347275ybi; Fri, 7 Jun 2019 09:01:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+L9pwku6yOmq3xWVw08p4TwtXsKxM4ZNWvjhKyq9qjznsNzMdJLLVXAj7gO1olv3iwyMh X-Received: by 2002:a17:90a:8c87:: with SMTP id b7mr3962037pjo.139.1559923287657; Fri, 07 Jun 2019 09:01:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559923287; cv=none; d=google.com; s=arc-20160816; b=FtIKKZozX7M5BZh4P/Cfu5fT+C4nA8QV/4SrwVMny/NwY3Iu2LbzP5f1/AQPNLeHI8 CLh/t9J59/CW8hSByz/xArHyGFLrh7uyTpC3O5mMgAGCXHcqRT/eQMSrx8wCD1NV7mHX N60ZRWgXB1YKKWkD/JbNMg/HkUbfTkV1wiJdxRqvfVwQeOXBOFSslvT90wuPm+Lavkv2 fPuHibQNNAIEluiwZZT3Oex3h7FRGaEk6kT9og+JOI8vQiSH2mKXJ9T6t0x9HKO3zsgF d9CnU6VwqZ2l8lMhgOkSp+UShICj5raKd43JOlE8V0WDwA+eebkdpnYz6fcw0KuM4nl+ eywg== 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=/4060FAYf8ivMnt8CI1GXngx3Lv+L619bqhq3uuPBOc=; b=Bta3wMFRj9FW4o9JGIbAp44aMeV8Zmm/ozpUGMpsa4lvg+WIUfBYsYYukEszo5AsNf MwfMFozhJM394aWQJiu+0bWPVHaM9L8nb97nIUZDn22ezz3n67+Pz0h1T0YZXHPDIE3t JbVLQZY7k4GeVgNTmbU4Tctn3Rxvbmykwud3K4CV5SD5zoT/esz5qGNNbLLQLFNVMdel TNUU6PaDafXa2EqcZpNgVZU7BTSZ+7QG+GCJsdgcfjDV5rxIG2rAtDTY8a4xZQRtfAls 9fS9tWIvqKtBvmNduqIdqEHYuXlA5XuuyEBoQn7yP3o2Qh82xpot7iRH4/8481DPO4bL xa5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=E8R2aFB9; 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 x4si2090610pgr.249.2019.06.07.09.01.09; Fri, 07 Jun 2019 09:01:27 -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=E8R2aFB9; 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 S1730480AbfFGPmK (ORCPT + 99 others); Fri, 7 Jun 2019 11:42:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:52320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730416AbfFGPmA (ORCPT ); Fri, 7 Jun 2019 11:42:00 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 BBEDE2133D; Fri, 7 Jun 2019 15:41:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559922120; bh=cgBfD8u9cSMxS93P8T3sKF2WamQHBf60rbEgKWXCVzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E8R2aFB9ZbladUw3/PrD1/O/+6ANOKzRpqZS0i/7r382ruTdQDrz+0Lr0UAxeImJR pAyC9/Mga1hhe7kTL0Csa3Dk6kC9/G8CsDpNylzo26ey2NcZdd79zzt5KbojGTPHDE JXqHlayBf3pldbL7+Lf5YuTWZOAcm7Mp/Gb7rO1k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Packham , "David S. Miller" Subject: [PATCH 4.14 08/69] tipc: Avoid copying bytes beyond the supplied data Date: Fri, 7 Jun 2019 17:38:49 +0200 Message-Id: <20190607153849.294133655@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190607153848.271562617@linuxfoundation.org> References: <20190607153848.271562617@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Chris Packham TLV_SET is called with a data pointer and a len parameter that tells us how many bytes are pointed to by data. When invoking memcpy() we need to careful to only copy len bytes. Previously we would copy TLV_LENGTH(len) bytes which would copy an extra 4 bytes past the end of the data pointer which newer GCC versions complain about. In file included from test.c:17: In function 'TLV_SET', inlined from 'test' at test.c:186:5: /usr/include/linux/tipc_config.h:317:3: warning: 'memcpy' forming offset [33, 36] is out of the bounds [0, 32] of object 'bearer_name' with type 'char[32]' [-Warray-bounds] memcpy(TLV_DATA(tlv_ptr), data, tlv_len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test.c: In function 'test': test.c::161:10: note: 'bearer_name' declared here char bearer_name[TIPC_MAX_BEARER_NAME]; ^~~~~~~~~~~ We still want to ensure any padding bytes at the end are initialised, do this with a explicit memset() rather than copy bytes past the end of data. Apply the same logic to TCM_SET. Signed-off-by: Chris Packham Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/uapi/linux/tipc_config.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/include/uapi/linux/tipc_config.h +++ b/include/uapi/linux/tipc_config.h @@ -302,8 +302,10 @@ static inline int TLV_SET(void *tlv, __u tlv_ptr = (struct tlv_desc *)tlv; tlv_ptr->tlv_type = htons(type); tlv_ptr->tlv_len = htons(tlv_len); - if (len && data) - memcpy(TLV_DATA(tlv_ptr), data, tlv_len); + if (len && data) { + memcpy(TLV_DATA(tlv_ptr), data, len); + memset(TLV_DATA(tlv_ptr) + len, 0, TLV_SPACE(len) - tlv_len); + } return TLV_SPACE(len); } @@ -400,8 +402,10 @@ static inline int TCM_SET(void *msg, __u tcm_hdr->tcm_len = htonl(msg_len); tcm_hdr->tcm_type = htons(cmd); tcm_hdr->tcm_flags = htons(flags); - if (data_len && data) + if (data_len && data) { memcpy(TCM_DATA(msg), data, data_len); + memset(TCM_DATA(msg) + data_len, 0, TCM_SPACE(data_len) - msg_len); + } return TCM_SPACE(data_len); }