Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp1291148rdb; Mon, 21 Aug 2023 03:28:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUrcSHDLZHF8rJxDghYjMxxZEGx36RtP44kHW+FI4HC4bNCjm+sBCxIcdeF2hyOGTNMXRy X-Received: by 2002:a05:6a00:188c:b0:68a:52ec:3d36 with SMTP id x12-20020a056a00188c00b0068a52ec3d36mr1756927pfh.31.1692613727177; Mon, 21 Aug 2023 03:28:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692613727; cv=none; d=google.com; s=arc-20160816; b=qRbpa0smGxiaLCCaWOGBi1JJHNEqdrICoXpXykh++uPWYsHP4VWRwxnJ1cf8rMX6pA 9/LoVGTOfh3nzPqDgztddb88vcjQRXtxMxVd4j3N+Alv6vxrv0dAvx2pfGfaZ8phsYH6 29bZ83OyXDLwmPcEZsh6xlOHf9pjMZy4VMT6vmg3vhVazXp+BZA49kXbmYhk2FB7Px8f CYyKrCoWCIf3iSqKdIyV1ZjIUGIzwSsxd1jzf9hjxthlWHPZOTxEavt52wYH5U6T7mRw oRzKpwRybuFKEJ8aATIb2WZzvcyjKp5Z2YEfLKFkrp7oJk11TdjQvJ3x3RD2E8iP+/C7 xzgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=2x2zt9/7UaZROyVbAdxZRFBHbBAaPC1tt19teD/1xsM=; fh=3Iz75Ad+pO3VSEwWJb2CVbszN2Of6jXfKJJ6jeXPcY4=; b=obH4Gk1ZbTvpPmR/8oTrYlIt/OOpx21rpK6eRkO8q1OdHxanIrN8r1i6s6/J7alUSF jvMVxV4beQlSTPEaE1nCCET4ydFLKodkXexl19JWovmq/VL43Tfdb3M2gCYlAjN5tAbt wqB2ltomtJtTyf4Xi8LibuE1rWdhw9qVFyYkrW4YThFTjuUxfSBbyTZwcRoXfvIbeMp4 j83BNlilb9URvj0QkZDKY1m1z+PQAAI2o4MjO3Zz4ytEt5K0xQg66J0EOCBEYVzfjdSA PNjYXhhUjXxmwsqbgeb/Oj+9WuScD7M4HS04GcGWu31V+FlBwOfyQVh9vdmgBocLV+ea Kn8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h63-20020a638342000000b0056b1f8adaefsi3183024pge.461.2023.08.21.03.28.34; Mon, 21 Aug 2023 03:28:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232257AbjHUB1o (ORCPT + 99 others); Sun, 20 Aug 2023 21:27:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbjHUB1n (ORCPT ); Sun, 20 Aug 2023 21:27:43 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 768779D; Sun, 20 Aug 2023 18:27:41 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4RTZbW2s3Wz4f3p1H; Mon, 21 Aug 2023 09:27:35 +0800 (CST) Received: from ubuntu20.huawei.com (unknown [10.67.174.33]) by APP4 (Coremail) with SMTP id gCh0CgCHXJ+AveJkpS7TBA--.56653S2; Mon, 21 Aug 2023 09:27:36 +0800 (CST) From: "GONG, Ruiqi" To: Chris Snook , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Sabrina Dubroca Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A . R . Silva" , gongruiqi1@huawei.com Subject: [PATCH RESEND net-next] alx: fix OOB-read compiler warning Date: Mon, 21 Aug 2023 09:32:18 +0800 Message-Id: <20230821013218.1614265-1-gongruiqi@huaweicloud.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgCHXJ+AveJkpS7TBA--.56653S2 X-Coremail-Antispam: 1UD129KBjvJXoWxJr1kJr1DGr45KrW3GrWrGrg_yoW8Aw4xpF WDGayDCa48urnrZa1UXay8Zry5ZanIq3yjkFyxA3yrZF1UtrZ8CF17Kryjkr1UJ3y09r1F qr1DAF9rJFZ8ZaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk2b4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxAIw28I cxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2 IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI 42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42 IY6xAIw20EY4v20xvaj40_WFyUJVCq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E 87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUrR6zUUUUU X-CM-SenderInfo: pjrqw2pxltxq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "GONG, Ruiqi" The following message shows up when compiling with W=1: In function ‘fortify_memcpy_chk’, inlined from ‘alx_get_ethtool_stats’ at drivers/net/ethernet/atheros/alx/ethtool.c:297:2: ./include/linux/fortify-string.h:592:4: error: call to ‘__read_overflow2_field’ declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Werror=attribute-warning] 592 | __read_overflow2_field(q_size_field, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In order to get alx stats altogether, alx_get_ethtool_stats() reads beyond hw->stats.rx_ok. Fix this warning by directly copying hw->stats, and refactor the unnecessarily complicated BUILD_BUG_ON btw. Signed-off-by: GONG, Ruiqi --- RESEND: forget to cc netdev mail list drivers/net/ethernet/atheros/alx/ethtool.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/atheros/alx/ethtool.c b/drivers/net/ethernet/atheros/alx/ethtool.c index b716adacd815..7f6b69a52367 100644 --- a/drivers/net/ethernet/atheros/alx/ethtool.c +++ b/drivers/net/ethernet/atheros/alx/ethtool.c @@ -292,9 +292,8 @@ static void alx_get_ethtool_stats(struct net_device *netdev, spin_lock(&alx->stats_lock); alx_update_hw_stats(hw); - BUILD_BUG_ON(sizeof(hw->stats) - offsetof(struct alx_hw_stats, rx_ok) < - ALX_NUM_STATS * sizeof(u64)); - memcpy(data, &hw->stats.rx_ok, ALX_NUM_STATS * sizeof(u64)); + BUILD_BUG_ON(sizeof(hw->stats) != ALX_NUM_STATS * sizeof(u64)); + memcpy(data, &hw->stats, sizeof(hw->stats)); spin_unlock(&alx->stats_lock); } -- 2.25.1