wifi: wilc1000: validate length of IEEE80211_P2P_ATTR_OPER_CHANNEL attribute
authorPhil Turnbull <philipturnbull@github.com>
Wed, 23 Nov 2022 15:35:41 +0000 (10:35 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 Dec 2022 16:41:11 +0000 (17:41 +0100)
commit 051ae669e4505abbe05165bebf6be7922de11f41 upstream.

Validate that the IEEE80211_P2P_ATTR_OPER_CHANNEL attribute contains
enough space for a 'struct struct wilc_attr_oper_ch'. If the attribute is
too small then it triggers an out-of-bounds write later in the function.

Signed-off-by: Phil Turnbull <philipturnbull@github.com>
Tested-by: Ajay Kathat <ajay.kathat@microchip.com>
Acked-by: Ajay Kathat <ajay.kathat@microchip.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20221123153543.8568-3-philipturnbull@github.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/wireless/microchip/wilc1000/cfg80211.c

index 87c14969c75facc03d706f1f79e4606c8ccb3555..dbfb33224d9e9275345621d2525fe5b230500f17 100644 (file)
@@ -939,14 +939,24 @@ static inline void wilc_wfi_cfg_parse_ch_attr(u8 *buf, u32 len, u8 sta_ch)
                return;
 
        while (index + sizeof(*e) <= len) {
+               u16 attr_size;
+
                e = (struct wilc_attr_entry *)&buf[index];
+               attr_size = le16_to_cpu(e->attr_len);
+
+               if (index + sizeof(*e) + attr_size > len)
+                       return;
+
                if (e->attr_type == IEEE80211_P2P_ATTR_CHANNEL_LIST)
                        ch_list_idx = index;
-               else if (e->attr_type == IEEE80211_P2P_ATTR_OPER_CHANNEL)
+               else if (e->attr_type == IEEE80211_P2P_ATTR_OPER_CHANNEL &&
+                        attr_size == (sizeof(struct wilc_attr_oper_ch) - sizeof(*e)))
                        op_ch_idx = index;
+
                if (ch_list_idx && op_ch_idx)
                        break;
-               index += le16_to_cpu(e->attr_len) + sizeof(*e);
+
+               index += sizeof(*e) + attr_size;
        }
 
        if (ch_list_idx) {