OSDN Git Service

libertas_tf: Use struct_group() for memcpy() region
authorKees Cook <keescook@chromium.org>
Thu, 18 Nov 2021 18:41:21 +0000 (10:41 -0800)
committerKalle Valo <kvalo@codeaurora.org>
Mon, 29 Nov 2021 10:44:55 +0000 (12:44 +0200)
In preparation for FORTIFY_SOURCE performing compile-time and run-time
field array bounds checking for memcpy(), memmove(), and memset(),
avoid intentionally writing across neighboring fields.

Use struct_group() in struct txpd around members tx_dest_addr_high
and tx_dest_addr_low 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 tx_dest_addr_high.

"pahole" shows no size nor member offset changes to struct txpd.
"objdump -d" shows no object code changes.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20211118184121.1283821-1-keescook@chromium.org
drivers/net/wireless/marvell/libertas_tf/libertas_tf.h
drivers/net/wireless/marvell/libertas_tf/main.c

index 5d72654..b2af2dd 100644 (file)
@@ -268,10 +268,12 @@ struct txpd {
        __le32 tx_packet_location;
        /* Tx packet length */
        __le16 tx_packet_length;
-       /* First 2 byte of destination MAC address */
-       u8 tx_dest_addr_high[2];
-       /* Last 4 byte of destination MAC address */
-       u8 tx_dest_addr_low[4];
+       struct_group(tx_dest_addr,
+               /* First 2 byte of destination MAC address */
+               u8 tx_dest_addr_high[2];
+               /* Last 4 byte of destination MAC address */
+               u8 tx_dest_addr_low[4];
+       );
        /* Pkt Priority */
        u8 priority;
        /* Pkt Trasnit Power control */
index 7149221..02a1e1f 100644 (file)
@@ -232,7 +232,8 @@ static void lbtf_tx_work(struct work_struct *work)
                             ieee80211_get_tx_rate(priv->hw, info)->hw_value);
 
        /* copy destination address from 802.11 header */
-       memcpy(txpd->tx_dest_addr_high, skb->data + sizeof(struct txpd) + 4,
+       BUILD_BUG_ON(sizeof(txpd->tx_dest_addr) != ETH_ALEN);
+       memcpy(&txpd->tx_dest_addr, skb->data + sizeof(struct txpd) + 4,
                ETH_ALEN);
        txpd->tx_packet_length = cpu_to_le16(len);
        txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));