From patchwork Wed Jan 2 12:36:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10746313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E22E17D2 for ; Wed, 2 Jan 2019 12:42:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EC592875F for ; Wed, 2 Jan 2019 12:42:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 334EB28802; Wed, 2 Jan 2019 12:42:55 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 CACED2875F for ; Wed, 2 Jan 2019 12:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729850AbfABMmy (ORCPT ); Wed, 2 Jan 2019 07:42:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46384 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729848AbfABMmy (ORCPT ); Wed, 2 Jan 2019 07:42:54 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D5EA80F88; Wed, 2 Jan 2019 12:42:54 +0000 (UTC) Received: from localhost (ovpn-12-39.pek2.redhat.com [10.72.12.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78BD4608E0; Wed, 2 Jan 2019 12:42:52 +0000 (UTC) From: Honggang Li To: hal@dev.mellanox.co.il Cc: linux-rdma@vger.kernel.org, Honggang Li Subject: [ibsim patch 04/23] sim_net.c: avoid copy garbage Date: Wed, 2 Jan 2019 20:36:08 +0800 Message-Id: <20190102123627.18629-4-honli@redhat.com> In-Reply-To: <20190102123627.18629-1-honli@redhat.com> References: <20190102123627.18629-1-honli@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 02 Jan 2019 12:42:54 +0000 (UTC) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The sizeof(port->vlarb_high) is 128. sizeof(default_vlarb_high) is 30. memcpy(port->vlarb_high, default_vlarb_high, sizeof(port->vlarb_high)) will fill [31, 128] bytes of port->vlarb_high with garbage after default_vlarb_high. ------------------------------------------------------------------------- make[1]: Entering directory '/home/honli/rpmbuild/BUILD/ibsim-0.7/ibsim' cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Wall -g -Werror -Wno-deprecated-declarations -fpic -I. -I../include -I/usr/include -c -o sim_net.o sim_net.c In file included from /usr/include/string.h:494, from sim_net.c:38: In function 'memcpy', inlined from 'init_ports' at sim_net.c:648:3: /usr/include/bits/string_fortified.h:34:10: error: '__builtin_memcpy' forming offset [31, 128] is out of the bounds [0, 30] of object 'default_vlarb_high' with type 'const struct vlarb[15]' [-Werror=array-bounds] return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sim_net.c: In function 'init_ports': sim_net.c:171:27: note: 'default_vlarb_high' declared here static const struct vlarb default_vlarb_high[] = { ^~~~~~~~~~~~~~~~~~ In file included from /usr/include/string.h:494, from sim_net.c:38: In function 'memcpy', inlined from 'init_ports' at sim_net.c:650:3: /usr/include/bits/string_fortified.h:34:10: error: '__builtin_memcpy' forming offset [31, 128] is out of the bounds [0, 30] of object 'default_vlarb_low' with type 'const struct vlarb[15]' [-Werror=array-bounds] return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sim_net.c: In function 'init_ports': sim_net.c:176:27: note: 'default_vlarb_low' declared here static const struct vlarb default_vlarb_low[] = { ^~~~~~~~~~~~~~~~~ In file included from /usr/include/string.h:494, from sim_net.c:38: Signed-off-by: Honggang Li --- ibsim/sim_net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ibsim/sim_net.c b/ibsim/sim_net.c index a963ff6d6589..a62d39d39174 100644 --- a/ibsim/sim_net.c +++ b/ibsim/sim_net.c @@ -646,9 +646,9 @@ static void init_ports(Node * node, int type, int maxports) memcpy(port->sl2vl + 8 * j, default_sl2vl, 8); memcpy(port->vlarb_high, default_vlarb_high, - sizeof(port->vlarb_high)); + sizeof(default_vlarb_high)); memcpy(port->vlarb_low, default_vlarb_low, - sizeof(port->vlarb_low)); + sizeof(default_vlarb_low)); } }