Skip to content

Commit 4835a5e

Browse files
jmberg-intelsmb49
authored andcommitted
wifi: cfg80211: check A-MSDU format more carefully
BugLink: https://bugs.launchpad.net/bugs/2065899 [ Upstream commit 9ad7974856926129f190ffbe3beea78460b3b7cc ] If it looks like there's another subframe in the A-MSDU but the header isn't fully there, we can end up reading data out of bounds, only to discard later. Make this a bit more careful and check if the subframe header can even be present. Reported-by: syzbot+d050d437fe47d479d210@syzkaller.appspotmail.com Link: https://msgid.link/20240226203405.a731e2c95e38.I82ce7d8c0cc8970ce29d0a39fdc07f1ffc425be4@changeid Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
1 parent 66eefda commit 4835a5e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

net/wireless/util.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,23 +791,26 @@ ieee80211_amsdu_subframe_length(void *field, u8 mesh_flags, u8 hdr_type)
791791

792792
bool ieee80211_is_valid_amsdu(struct sk_buff *skb, u8 mesh_hdr)
793793
{
794-
int offset = 0, remaining, subframe_len, padding;
794+
int offset = 0, subframe_len, padding;
795795

796796
for (offset = 0; offset < skb->len; offset += subframe_len + padding) {
797+
int remaining = skb->len - offset;
797798
struct {
798799
__be16 len;
799800
u8 mesh_flags;
800801
} hdr;
801802
u16 len;
802803

804+
if (sizeof(hdr) > remaining)
805+
return false;
806+
803807
if (skb_copy_bits(skb, offset + 2 * ETH_ALEN, &hdr, sizeof(hdr)) < 0)
804808
return false;
805809

806810
len = ieee80211_amsdu_subframe_length(&hdr.len, hdr.mesh_flags,
807811
mesh_hdr);
808812
subframe_len = sizeof(struct ethhdr) + len;
809813
padding = (4 - subframe_len) & 0x3;
810-
remaining = skb->len - offset;
811814

812815
if (subframe_len > remaining)
813816
return false;
@@ -825,7 +828,7 @@ void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
825828
{
826829
unsigned int hlen = ALIGN(extra_headroom, 4);
827830
struct sk_buff *frame = NULL;
828-
int offset = 0, remaining;
831+
int offset = 0;
829832
struct {
830833
struct ethhdr eth;
831834
uint8_t flags;
@@ -839,10 +842,14 @@ void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
839842
copy_len = sizeof(hdr);
840843

841844
while (!last) {
845+
int remaining = skb->len - offset;
842846
unsigned int subframe_len;
843847
int len, mesh_len = 0;
844848
u8 padding;
845849

850+
if (copy_len > remaining)
851+
goto purge;
852+
846853
skb_copy_bits(skb, offset, &hdr, copy_len);
847854
if (iftype == NL80211_IFTYPE_MESH_POINT)
848855
mesh_len = __ieee80211_get_mesh_hdrlen(hdr.flags);
@@ -852,7 +859,6 @@ void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
852859
padding = (4 - subframe_len) & 0x3;
853860

854861
/* the last MSDU has no padding */
855-
remaining = skb->len - offset;
856862
if (subframe_len > remaining)
857863
goto purge;
858864
/* mitigate A-MSDU aggregation injection attacks */

0 commit comments

Comments
 (0)