a408c3d802b9862a00115a103940b5b5c35c352e
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / subsys / 308-mac80211-fix-radiotap-header-generation.patch
1 From: Johannes Berg <johannes.berg@intel.com>
2 Date: Tue, 9 Nov 2021 10:02:04 +0100
3 Subject: [PATCH] mac80211: fix radiotap header generation
4
5 In commit 8c89f7b3d3f2 ("mac80211: Use flex-array for radiotap header
6 bitmap") we accidentally pointed the position to the wrong place, so
7 we overwrite a present bitmap, and thus cause all kinds of trouble.
8
9 To see the issue, note that the previous code read:
10
11 pos = (void *)(it_present + 1);
12
13 The requirement now is that we need to calculate pos via it_optional,
14 to not trigger the compiler hardening checks, as:
15
16 pos = (void *)&rthdr->it_optional[...];
17
18 Rewriting the original expression, we get (obviously, since that just
19 adds "+ x - x" terms):
20
21 pos = (void *)(it_present + 1 + rthdr->it_optional - rthdr->it_optional)
22
23 and moving the "+ rthdr->it_optional" outside to be used as an array:
24
25 pos = (void *)&rthdr->it_optional[it_present + 1 - rthdr->it_optional];
26
27 The original is off by one, fix it.
28
29 Cc: stable@vger.kernel.org
30 Fixes: 8c89f7b3d3f2 ("mac80211: Use flex-array for radiotap header bitmap")
31 Reported-by: Sid Hayn <sidhayn@gmail.com>
32 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
33 Tested-by: Sid Hayn <sidhayn@gmail.com>
34 Reviewed-by: Kees Cook <keescook@chromium.org>
35 Link: https://lore.kernel.org/r/20211109100203.c61007433ed6.I1dade57aba7de9c4f48d68249adbae62636fd98c@changeid
36 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
37 ---
38
39 --- a/net/mac80211/rx.c
40 +++ b/net/mac80211/rx.c
41 @@ -364,7 +364,7 @@ ieee80211_add_rx_radiotap_header(struct
42 * the compiler to think we have walked past the end of the
43 * struct member.
44 */
45 - pos = (void *)&rthdr->it_optional[it_present - rthdr->it_optional];
46 + pos = (void *)&rthdr->it_optional[it_present + 1 - rthdr->it_optional];
47
48 /* the order of the following fields is important */
49