Skip to contentSkip to conversation

staging: rtl8192u: Avoid field-overflowing memcpy()

PATCH New Kees Cook 1 participant 1 message Aug 6, 2021 Staging

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 staging: rtl8192u: Avoid field-overflowing memcpy()

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.

Split the 3 addr memcpy() into 3 memcpy() calls so the compiler doesn't think an overflowing memcpy() happens against the addr1 field (the neighbors are intended to be copied as well).

ieee80211_read_qos_param_element() copies a struct ieee80211_info_element into a struct ieee80211_qos_information_element, but is actually wanting to copy into the larger struct ieee80211_qos_parameter_info (the contents of ac_params_record[] is later examined). Refactor the routine to perform centralized checks, and copy the entire contents directly (since the id and len members match the elementID and length members):

struct ieee80211_info_element {
        u8 id;
        u8 len;
        u8 data[];
} __packed;
struct ieee80211_qos_information_element {
        u8 elementID;
        u8 length;
        u8 qui[QOS_OUI_LEN];
        u8 qui_type;
        u8 qui_subtype;
        u8 version;
        u8 ac_info;
} __packed;
struct ieee80211_qos_parameter_info {
        struct ieee80211_qos_information_element info_element;
        u8 reserved;
        struct ieee80211_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
} __packed;

Additionally replace old-style zero-element arrays with flexible arrays.

Cc Greg Kroah-Hartman <[email protected]>
Cc Pascal Terjan <[email protected]>
Cc Christophe JAILLET <[email protected]>
---
 .../staging/rtl8192u/ieee80211/ieee80211.h    |  4 +-
 .../rtl8192u/ieee80211/ieee80211_crypt_ccmp.c |  4 +-
 .../staging/rtl8192u/ieee80211/ieee80211_rx.c | 49 ++++++-------------
 3 files changed, 19 insertions(+), 38 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211.h +2 -2
index 7903c777a417..15207dc1f5c5 100644
@@ -303,7 +303,7 @@ struct ieee_param {
 		struct {
 			u32 len;
 			u8 reserved[32];
-			u8 data[0];
+			u8 data[];
 		} wpa_ie;
 		struct{
 			int command;
@@ -316,7 +316,7 @@ struct ieee_param {
 			u8 idx;
 			u8 seq[8]; /* sequence counter (set: RX, get: TX) */
 			u16 key_len;
-			u8 key[0];
+			u8 key[];
 		} crypt;
 	} u;
 };
drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c +3 -1
index c241cf484023..ccff385cf1f8 100644
@@ -141,7 +141,9 @@ static int ccmp_init_iv_and_aad(struct rtl_80211_hdr_4addr *hdr,
 	pos = (u8 *)hdr;
 	aad[0] = pos[0] & 0x8f;
 	aad[1] = pos[1] & 0xc7;
-	memcpy(aad + 2, hdr->addr1, 3 * ETH_ALEN);
+	memcpy(&aad[2], &hdr->addr1, ETH_ALEN);
+	memcpy(&aad[8], &hdr->addr2, ETH_ALEN);
+	memcpy(&aad[14], &hdr->addr3, ETH_ALEN);
 	pos = (u8 *)&hdr->seq_ctl;
 	aad[20] = pos[0] & 0x0f;
 	aad[21] = 0; /* all bits masked */
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +14 -35

74 lines not on this page · raw message

Signature · 1 line
2.30.2