From patchwork Thu Nov 18 20:34:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12627667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC809C433EF for ; Thu, 18 Nov 2021 20:34:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF30D61361 for ; Thu, 18 Nov 2021 20:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232890AbhKRUh7 (ORCPT ); Thu, 18 Nov 2021 15:37:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231747AbhKRUh7 (ORCPT ); Thu, 18 Nov 2021 15:37:59 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1780C06173E for ; Thu, 18 Nov 2021 12:34:58 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id o6-20020a17090a0a0600b001a64b9a11aeso6799032pjo.3 for ; Thu, 18 Nov 2021 12:34:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wy7ZFa/vlTHtgg8uQMNJ843aX+ZbzQs1i4QUu9cpwyY=; b=FKfwi2Ivo4NmiyvT2tVWOs7r58MIEvYZEOXuGViUBcXpN74o9eypyVH5z0BQzIYu+J KloQOQ8pw0FeXpN//jAS2okJxT+w+secrDywySrARz+LKLkZKVndv8dBGYuHUY4iELVu EJ2J0sva9U2uDRIY/pa3eDVEzuW4FLwCOBc9o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wy7ZFa/vlTHtgg8uQMNJ843aX+ZbzQs1i4QUu9cpwyY=; b=CFyk4CnTVH9/qvcaF/ISWBenYiW8ZFxEctHIw42YOCREjw695m7/S6qWVpyKL/yX4G bQ2K2qVmoAapZIy1Q5XbUhw4WJdi000K1hsOx6iwNPkw+PIJTDA3tAdIxjMsa0g5UQED 6m8gaDyGmzdZQGh5x+x1IYSjzvt6KPwFXIzggsHk0Xdu0vsSFR0/t7ySy2cREu4hYJbR zidNy9GRynrabVfCAYpqrKZmxawharUN9sYQhBhrl6bwF5aJ2zzrdMP+ctYyqrYrHBnn 5G+/xPj5CN+9tplBCwwJbJZDEH51aSIqe1lQsIx9aHiU0vvTrUXZjGGsGZ1qqn3LwsNq fY0w== X-Gm-Message-State: AOAM532U7QAEKgtO3a+c92gZi6m2DVRDkc7U6hC2LK6DDCl2V/HOtx1/ HPc4qq8y+Vmp5TIfoSYwt01zpA== X-Google-Smtp-Source: ABdhPJwv6uDXoEhxsSqoGjLKfrb3/6Kd7ESUUDv7joUBA+7yE9nJXirBGTl+M3FfitWyi/vo0xFwBw== X-Received: by 2002:a17:902:74cb:b0:143:6fe9:ca4 with SMTP id f11-20020a17090274cb00b001436fe90ca4mr70980340plt.2.1637267698249; Thu, 18 Nov 2021 12:34:58 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q9sm489033pfj.88.2021.11.18.12.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 12:34:58 -0800 (PST) From: Kees Cook To: "David S. Miller" Cc: Kees Cook , Jakub Kicinski , Ido Schimmel , YueHaibing , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] ethtool: stats: Use struct_group() to clear all stats at once Date: Thu, 18 Nov 2021 12:34:56 -0800 Message-Id: <20211118203456.1288056-1-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1822; h=from:subject; bh=nf2hDwlk0YBMeQam31KvtF6X3nn/T4T4psodjHluwA0=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhlrjv4ay2vSP0iUDUl/jIVt/Blah8KWXvHVH7Wzv7 NYIRQBeJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYZa47wAKCRCJcvTf3G3AJvBJD/ 9Na9qQTVUsisud4heS8I6/Jho/ZfNvhU2k2tn9Jv8ASHEdfY+9rKBmAX0tJUczauv+kWXiRwOxOx1j cyjX0xISkco0aZfG4vj9XQIBc9CPxkBDj0aBaz78+IHKOWr59+S2V0QmYL04Ycdak/MayJzGvfL/ms BBSYWc++4lXP0WYaJNF9zs4hYQvVxJi85u3Z241lUdvn8UPyRvjxOMzMw35oZCGza98pHctIJ+zobA 7BuEbCEL6kjwD9s4XETlcN2NoABT+e4W6HNrNBi/QuOwjP/0KNVbljl43XnBqwqfeBeItZPJOs2X3m Jidx5KHe54mlK+PcMFnJtcRBfnJu14HAX9nymfBRP2Z1vqwECWXdGkHOPfVsIhxjHonSfgVDB4RlaM 1LYUcHgCmJY+biBO46pJTSRx9vt6J5ZTCWlWhlIubJSuakDoRCEhEON+8iaFeWJybYZNJQ+I/JBsRI eVwXeWvkcvE8wFRTtugO1pST327roZ7fIGFcbk9SW2udTvFSoFQgaNnlx3OmSKeKN01a0cAPz7VF6/ h+9yaYmVn29wO+1VqwUS9QH0Km77doUOTyCQr1SRxSVhxE37TLIEdBCBVYxPKtat++V3Ea7YNVOQRf 8oTFbBdf9aBk/R4uU1KGLqFfSVHLFQbQ3CaEc9do1jYpilSFqay8yZQsLa+w== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memset(), avoid intentionally writing across neighboring fields. Add struct_group() to mark region of struct stats_reply_data that should be initialized, which can now be done in a single memset() call. Signed-off-by: Kees Cook --- net/ethtool/stats.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/net/ethtool/stats.c b/net/ethtool/stats.c index ec07f5765e03..a20e0a24ff61 100644 --- a/net/ethtool/stats.c +++ b/net/ethtool/stats.c @@ -14,10 +14,12 @@ struct stats_req_info { struct stats_reply_data { struct ethnl_reply_data base; - struct ethtool_eth_phy_stats phy_stats; - struct ethtool_eth_mac_stats mac_stats; - struct ethtool_eth_ctrl_stats ctrl_stats; - struct ethtool_rmon_stats rmon_stats; + struct_group(stats, + struct ethtool_eth_phy_stats phy_stats; + struct ethtool_eth_mac_stats mac_stats; + struct ethtool_eth_ctrl_stats ctrl_stats; + struct ethtool_rmon_stats rmon_stats; + ); const struct ethtool_rmon_hist_range *rmon_ranges; }; @@ -117,10 +119,7 @@ static int stats_prepare_data(const struct ethnl_req_info *req_base, /* Mark all stats as unset (see ETHTOOL_STAT_NOT_SET) to prevent them * from being reported to user space in case driver did not set them. */ - memset(&data->phy_stats, 0xff, sizeof(data->phy_stats)); - memset(&data->mac_stats, 0xff, sizeof(data->mac_stats)); - memset(&data->ctrl_stats, 0xff, sizeof(data->ctrl_stats)); - memset(&data->rmon_stats, 0xff, sizeof(data->rmon_stats)); + memset(&data->stats, 0xff, sizeof(data->stats)); if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask) && dev->ethtool_ops->get_eth_phy_stats)