From patchwork Thu Nov 18 18:41:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12627531 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 03362C433F5 for ; Thu, 18 Nov 2021 18:42:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFE0D61A6C for ; Thu, 18 Nov 2021 18:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233773AbhKRSpC (ORCPT ); Thu, 18 Nov 2021 13:45:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233793AbhKRSpB (ORCPT ); Thu, 18 Nov 2021 13:45:01 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BA82C061748 for ; Thu, 18 Nov 2021 10:42:01 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id k4so6007492plx.8 for ; Thu, 18 Nov 2021 10:42:01 -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=jLdAi6o6FBcZW9AN3DbgERTMdYP9HSq61k/WVHULtZ4=; b=HjqZmQiiYsr/8BUOTbI928lO46ic6kIm32IjDf6Bc1wuayWIoN2rbhlHN829hZmiJ/ +VUewKoaSojWWeZDtFmzNp07Rj6mUs6Vjs+m23WQUVUJtT3pJbVL04coaRAzkaH7Uo1H AAdOhVAyFkby/VFSyceW5Mr2QWjoNxfYrkvz0= 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=jLdAi6o6FBcZW9AN3DbgERTMdYP9HSq61k/WVHULtZ4=; b=zms5WVNzHf1Cp7tOtJ2SvvV90MkAs6iBfLzlbhDmVmkw4v/okit7cDht8c0Aa2pUv5 Kg6ahey7u8tGPZdukvrkEieUqpqEnAnHnnw9ngKdxc/Ph1LPfrI2RjtC7OFbDZk0oNeC Peo22TUFYVlIKj1GhDA31bg0aqBrKR83FLMerXw+V/jWpKz2WsJMdXPtCRJTj6jEE+bV GIbhiUEnfvQ9WjHgoKGgCKSqKLPEZXD+JgJLhvreCEjATjbNzSjnU+uRFuXZte3+wE3e 6+GJ26q7Y5/iHMMvgxvVCamqoBjmR57qltPVdPZoi/YxI10cUurB4/484z7EdkzowgMY Yrpw== X-Gm-Message-State: AOAM530W+yAKaV7SOB92069AvdTz8+ThyMgyutFqDnJKLsGSnKewGayu waYaH5bKCbxLbsdANZhUhgb9+g== X-Google-Smtp-Source: ABdhPJxvM5tp/bqVNdujo6JpHnhy1nqPfO+rTGMecu/gtHNCVNQTvIfUyjDlEFl+GDuJL3r/69bLcw== X-Received: by 2002:a17:902:b084:b0:141:f5f8:1c5a with SMTP id p4-20020a170902b08400b00141f5f81c5amr69242025plr.40.1637260920804; Thu, 18 Nov 2021 10:42:00 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d12sm294720pgf.19.2021.11.18.10.42.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 10:42:00 -0800 (PST) From: Kees Cook To: Jouni Malinen Cc: Kees Cook , Kalle Valo , "David S. Miller" , Jakub Kicinski , Lee Jones , Allen Pais , Romain Perier , Arnd Bergmann , Vaibhav Gupta , Cong Wang , Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] intersil: Use struct_group() for memcpy() region Date: Thu, 18 Nov 2021 10:41:58 -0800 Message-Id: <20211118184158.1284180-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=2591; h=from:subject; bh=miSF2gf2abPEVRMOENvim46Cpo5/erdvCVGiWTz8mCE=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhlp5271Q5EEUtYsTlxk8CWtzRcew2cnKosVYlA18w zQyXh5+JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYZaedgAKCRCJcvTf3G3AJtXTD/ 9KDpSczNe/aQ9RlJXgLXq8c+5TRiFs53bgu6Tj77JxLcIF5XLJ8pj4G0JkijTKSp7JhquxsIxDmxg/ JqCcqOfwNLU1JBOPLrRh3pudVu6GD8NWaR4dswiUQM0jIYZf5zkQiRb+0EoLb/p2Sq3NfhatQpmZKy Ghjdl4h+w+NRG9CIfecorIwMzhJpVuTzwjhLxw9Jzt2XKDlHf2gsIaKAmD3jRtvianZzIVp1jnj5m7 lQhhokkUVw+dVXnmUF9GfR3XyiG36vUafZluUDnkqGH14sLR2Y5bf6V3/QZoHSLReanEfVH/D+ccr/ ruH7U210HM7lJGwwYnPFaCZI63U7CDPcub5RFLPk++PUB5zCM/+8cu3bKsOZmMGqZiAWJ1dZlzs1/L 8AJdlBe7uhaPssgCweyWFBphhJIoPR95dZL2fz6h8MM34xL0ADn2KMO9jcx1xf77Madizf2X0fnnVc mYDOm3ksMBPd8Hb6sH+BOjkrvY942xUfHNfkyYNgKqBS9di01+vlXSWBHxi6ZVEdxlMsiW9tD4KoZ7 7dOtU3FAypadGBaAdl5k5X9sdT4I+KRQB14l0357zQMo4G4Pz+7lLAqTA34Lg676UZaXrdJmZrtvLU gccTcoRe+K2Uv6tfp0w9wEoNdWZH5jKHHGvl9epcwc7qB72D4pp98OQcgiMg== 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 memcpy(), memmove(), and memset(), avoid intentionally writing across neighboring fields. Use struct_group() in struct hfa384x_tx_frame around members frame_control, duration_id, addr1, addr2, addr3, and seq_ctrl, so they can be referenced together. This will allow memcpy() and sizeof() to more easily reason about sizes, improve readability, and avoid future warnings about writing beyond the end of frame_control. "pahole" shows no size nor member offset changes to struct hfa384x_tx_frame. "objdump -d" shows no object code changes. Signed-off-by: Kees Cook --- drivers/net/wireless/intersil/hostap/hostap_hw.c | 5 +++-- drivers/net/wireless/intersil/hostap/hostap_wlan.h | 14 ++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/intersil/hostap/hostap_hw.c b/drivers/net/wireless/intersil/hostap/hostap_hw.c index e459e7192ae9..8b7374023659 100644 --- a/drivers/net/wireless/intersil/hostap/hostap_hw.c +++ b/drivers/net/wireless/intersil/hostap/hostap_hw.c @@ -1815,8 +1815,9 @@ static int prism2_tx_80211(struct sk_buff *skb, struct net_device *dev) memset(&txdesc, 0, sizeof(txdesc)); /* skb->data starts with txdesc->frame_control */ - hdr_len = 24; - skb_copy_from_linear_data(skb, &txdesc.frame_control, hdr_len); + hdr_len = sizeof(txdesc.frame); + BUILD_BUG_ON(hdr_len != 24); + skb_copy_from_linear_data(skb, &txdesc.frame, hdr_len); if (ieee80211_is_data(txdesc.frame_control) && ieee80211_has_a4(txdesc.frame_control) && skb->len >= 30) { diff --git a/drivers/net/wireless/intersil/hostap/hostap_wlan.h b/drivers/net/wireless/intersil/hostap/hostap_wlan.h index dd2603d9b5d3..174735a137c5 100644 --- a/drivers/net/wireless/intersil/hostap/hostap_wlan.h +++ b/drivers/net/wireless/intersil/hostap/hostap_wlan.h @@ -115,12 +115,14 @@ struct hfa384x_tx_frame { __le16 tx_control; /* HFA384X_TX_CTRL_ flags */ /* 802.11 */ - __le16 frame_control; /* parts not used */ - __le16 duration_id; - u8 addr1[ETH_ALEN]; - u8 addr2[ETH_ALEN]; /* filled by firmware */ - u8 addr3[ETH_ALEN]; - __le16 seq_ctrl; /* filled by firmware */ + struct_group(frame, + __le16 frame_control; /* parts not used */ + __le16 duration_id; + u8 addr1[ETH_ALEN]; + u8 addr2[ETH_ALEN]; /* filled by firmware */ + u8 addr3[ETH_ALEN]; + __le16 seq_ctrl; /* filled by firmware */ + ); u8 addr4[ETH_ALEN]; __le16 data_len;