From patchwork Fri Nov 19 00:46:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12628031 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 C023BC433FE for ; Fri, 19 Nov 2021 00:46:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98DAD61ABA for ; Fri, 19 Nov 2021 00:46:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233720AbhKSAt4 (ORCPT ); Thu, 18 Nov 2021 19:49:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233678AbhKSAty (ORCPT ); Thu, 18 Nov 2021 19:49:54 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6168C06174A for ; Thu, 18 Nov 2021 16:46:53 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id v23so6579191pjr.5 for ; Thu, 18 Nov 2021 16:46:53 -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=ZT1iG7+0+T8P3rfUSOYrrKI2G5W7nv68HnCCWdsEXCw=; b=HobjTeddfRRQcGJk+XkhzsQSfS58o+IU5voWeA3xC5zvznT5suEw9/WjTWzrrTkIlK HISMB2VIJNAz6HIoMUjGQImgyb1ywoBmRMWbkfi/PzgH2962mnDehKbUdlTCwSX/gqWz /84oh2aY9PIRzfgHNPP0/m3wRDtCJOmltGs14= 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=ZT1iG7+0+T8P3rfUSOYrrKI2G5W7nv68HnCCWdsEXCw=; b=zZw6F0j/gNJttS0UjIr+GlKdXu3M5pc9LuWqhyJl//tweRqu8Q7bdnqLW3UX/wYA4M f1Pdf5PBIaysmwxOxtQuuQYsmZVziec9neVhynNSZKWc8HLGuv8cKSoxxNsIFrwRDaJy VRsdU5nxHJjoBA2YMZwFLJ+42EM9YVzcKaP0NloSuzKOUbF50j09pMUzofQ3XF3iURiS vX7XEt7bwHGkcLsP13YxQj4U4n0Xs4vrL5oojvtaQesSdtz2kyEldchw0DvKRT7Wx/65 yFvzDepjLVCqKfv/B9jN8yhMusXRsfVwAN7FNnQah5lvn00UUXA3tZuWgdlN9xXBVUJe S5IA== X-Gm-Message-State: AOAM533fA9phRiiNfJJkop6UQRmKHSI0YhY397ynYa1OJ0jeeheIG+ia zhnwkF0FzB17AvKkMVNNAjgvlg== X-Google-Smtp-Source: ABdhPJyv639lg1pLRyYgeRdj3wF+Hn0NzW8M+lZTk58Npccq7L+pczv//omx8Da7ngXlDyZTotZpow== X-Received: by 2002:a17:90b:128e:: with SMTP id fw14mr135653pjb.173.1637282813204; Thu, 18 Nov 2021 16:46:53 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id mg12sm9236477pjb.10.2021.11.18.16.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 16:46:52 -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 v2] intersil: Use struct_group() for memcpy() region Date: Thu, 18 Nov 2021 16:46:46 -0800 Message-Id: <20211119004646.2347920-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=2635; h=from:subject; bh=YsQ+ZCDrVqrDtxvnMcMU6Cxw83EB3GFNn/tVgcCBKYc=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhlvP2ybmT5SP1sgJUGnCcAz8QQT3eUQgvyBjXCASQ cKJDqb+JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYZbz9gAKCRCJcvTf3G3AJiBYEA CwW65xXbKOStSluO7TqWoGVpcEZWUZB/l3IgGB5mD2EiwmapB2/xSO9Y8MLErgpFQjbZ5Il67td3yt 3/ysqTqflgTgYkfcAEOhVCglDluzqNBFuNTx+5f44BKcGtlgktJp8d/DyGtApELGq0sP9rDAPG+dps wGND8d0PHG3kyUzixHIuEM/pWrD5dstrsGxwEpPtg0fuv/Vwas+LeVzmsrNfZRiDQ7W3URhnfstPFC qHpIp8ES7JqETe8lj6tagAjdUfZqbX4Joni/ckCjGWBdq9sKxGK7silkOJXoQxFrDxzqCEAUVy8clU ei+E3A+O+B6PUWE4/X9e4htX7WxzhYEjvs5OMLT+I3PMv94bRRmZYyshHBqZRQLhtMvT3sWlhpuJ46 QZ/ywFVc5Tdz2alOZG4H+yhghMDPPX+71+OYQJX82mHrq++w6l23C6YfzrOPHt9gQlefpja4NPfCkO YKrUJesfbyjnvlt8pT2iiGXC7SUK1Sl9+iOCOsHVID94RDP6F09vwCCK47Evr8zfXNz2sYyLuYBdVF aWhg6VsBNrD22ETGVp2Tn6TrfWlWuByuH6vLQ7z2E2vjjDLZPixgPuXvlyrq5PsbmSUQlIfMq/c9lL yP84cPQ2j0tLWQ2TbxmGeLlr8dQtS/M2YHWjEWpTekpU+spz+pG4Xbzxl/fQ== 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 --- v1->v2: rename "frame" to "header" --- 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..b74f4cb5d6d3 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.header); + BUILD_BUG_ON(hdr_len != 24); + skb_copy_from_linear_data(skb, &txdesc.header, 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..c25cd21d18bd 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(header, + __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;