@@ -39,10 +39,26 @@ struct ieee80211_radiotap_header {
*/
__le16 it_len;
- /**
- * @it_present: (first) present word
- */
- __le32 it_present;
+ union {
+ /**
+ * @it_present: (first) present word
+ */
+ __le32 it_present;
+
+ struct {
+ /* The compiler makes it difficult to overlap
+ * a flex-array with an existing singleton,
+ * so we're forced to add an empty named
+ * variable here.
+ */
+ struct { } __unused;
+
+ /**
+ * @bitmap: all presence bitmaps
+ */
+ __le32 bitmap[];
+ };
+ };
} __packed;
/* version is always 0 */
@@ -328,7 +328,7 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
rthdr = skb_push(skb, rtap_len);
memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
- it_present = &rthdr->it_present;
+ it_present = rthdr->bitmap;
/* radiotap header, set always present flags */
rthdr->it_len = cpu_to_le16(rtap_len);
@@ -115,10 +115,9 @@ int ieee80211_radiotap_iterator_init(
iterator->_max_length = get_unaligned_le16(&radiotap_header->it_len);
iterator->_arg_index = 0;
iterator->_bitmap_shifter = get_unaligned_le32(&radiotap_header->it_present);
- iterator->_arg = (uint8_t *)radiotap_header + sizeof(*radiotap_header);
+ iterator->_arg = (uint8_t *)&radiotap_header->bitmap[1];
iterator->_reset_on_ext = 0;
- iterator->_next_bitmap = &radiotap_header->it_present;
- iterator->_next_bitmap++;
+ iterator->_next_bitmap = &radiotap_header->bitmap[1];
iterator->_vns = vns;
iterator->current_namespace = &radiotap_ns;
iterator->is_radiotap_ns = 1;
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. The it_present member of struct ieee80211_radiotap_header is treated as a flexible array (multiple u32s can be conditionally present). In order for memcpy() to reason (or really, not reason) about the size of operations against this struct, use of bytes beyond it_present need to be treated as part of the flexible array. Add a union/struct to contain the new "bitmap" member, for use with trailing presence bitmaps and arguments. Additionally improve readability in the iterator code which walks through the bitmaps and arguments. Signed-off-by: Kees Cook <keescook@chromium.org> --- include/net/ieee80211_radiotap.h | 24 ++++++++++++++++++++---- net/mac80211/rx.c | 2 +- net/wireless/radiotap.c | 5 ++--- 3 files changed, 23 insertions(+), 8 deletions(-)