From patchwork Wed Jan 2 13:12:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10746329 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 6CC1191E for ; Wed, 2 Jan 2019 13:13:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DDA827528 for ; Wed, 2 Jan 2019 13:13:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F74D28450; Wed, 2 Jan 2019 13:13:56 +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 E506F27528 for ; Wed, 2 Jan 2019 13:13:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729895AbfABNNz (ORCPT ); Wed, 2 Jan 2019 08:13:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53192 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726939AbfABNNz (ORCPT ); Wed, 2 Jan 2019 08:13:55 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 910EC550CF; Wed, 2 Jan 2019 13:13:55 +0000 (UTC) Received: from localhost (ovpn-12-97.pek2.redhat.com [10.72.12.97]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E56B25D75C; Wed, 2 Jan 2019 13:13:54 +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 21:12:59 +0800 Message-Id: <20190102131318.5765-4-honli@redhat.com> In-Reply-To: <20190102131318.5765-1-honli@redhat.com> References: <20190102131318.5765-1-honli@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 02 Jan 2019 13:13:55 +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)); } }