Skip to contentSkip to conversation

wifi: mwifiex: Fix oob check condition in mwifiex_process_rx_packet

PATCH In review Pin-yen Lin 4 participants 8 messages Sep 8, 2023 – Sep 19, 2023 Marvell mwifiex wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 wifi: mwifiex: Fix oob check condition in mwifiex_process_rx_packet

Only skip the code path trying to access the rfc1042 headers when the buffer is too small, so the driver can still process packets without rfc1042 headers.

Fixes 119585281617 ("wifi: mwifiex: Fix OOB and integer underflow when rx packets")

---

Changes in v3:
- Really apply the sizeof call fix as it was missed in the previous patch

Changes in v2:
- Fix sizeof call (sizeof(rx_pkt_hdr) --> sizeof(*rx_pkt_hdr))

 drivers/net/wireless/marvell/mwifiex/sta_rx.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/net/wireless/marvell/mwifiex/sta_rx.c +9 -7
index 65420ad67416..257737137cd7 100644
@@ -86,7 +86,8 @@ int mwifiex_process_rx_packet(struct mwifiex_private *priv,
 	rx_pkt_len = le16_to_cpu(local_rx_pd->rx_pkt_length);
 	rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_off;
 
-	if (sizeof(*rx_pkt_hdr) + rx_pkt_off > skb->len) {
+	if (sizeof(rx_pkt_hdr->eth803_hdr) + sizeof(rfc1042_header) +
+	    rx_pkt_off > skb->len) {
 		mwifiex_dbg(priv->adapter, ERROR,
 			    "wrong rx packet offset: len=%d, rx_pkt_off=%d\n",
 			    skb->len, rx_pkt_off);
@@ -95,12 +96,13 @@ int mwifiex_process_rx_packet(struct mwifiex_private *priv,
 		return -1;
 	}
 
-	if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
-		     sizeof(bridge_tunnel_header))) ||
-	    (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
-		     sizeof(rfc1042_header)) &&
-	     ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
-	     ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) {
+	if (sizeof(*rx_pkt_hdr) + rx_pkt_off <= skb->len &&
+	    ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
+		      sizeof(bridge_tunnel_header))) ||
+	     (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
+		      sizeof(rfc1042_header)) &&
+	      ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
+	      ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX))) {
 		/*
 		 *  Replace the 803 header and rfc1042 header (llc/snap) with an
 		 *    EthernetII header, keep the src/dst and snap_type
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
maintainer
#1 lore raw
Quoted 6 lines · Pin-yen Lin

Only skip the code path trying to access the rfc1042 headers when the buffer is too small, so the driver can still process packets without rfc1042 headers.

Fixes 119585281617 ("wifi: mwifiex: Fix OOB and integer underflow when rx packets")

I'd appreciate another review/test from one of the others here (Matthew?), even though I know y'all are already working together.

Quoted 26 lines

---

Changes in v3:
- Really apply the sizeof call fix as it was missed in the previous patch

Changes in v2:
- Fix sizeof call (sizeof(rx_pkt_hdr) --> sizeof(*rx_pkt_hdr))

 drivers/net/wireless/marvell/mwifiex/sta_rx.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/net/wireless/marvell/mwifiex/sta_rx.c +2 -1
index 65420ad67416..257737137cd7 100644
@@ -86,7 +86,8 @@ int mwifiex_process_rx_packet(struct mwifiex_private *priv,
 	rx_pkt_len = le16_to_cpu(local_rx_pd->rx_pkt_length);
 	rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_off;
 
-	if (sizeof(*rx_pkt_hdr) + rx_pkt_off > skb->len) {
+	if (sizeof(rx_pkt_hdr->eth803_hdr) + sizeof(rfc1042_header) +
+	    rx_pkt_off > skb->len) {
 		mwifiex_dbg(priv->adapter, ERROR,
 			    "wrong rx packet offset: len=%d, rx_pkt_off=%d\n",
 			    skb->len, rx_pkt_off);

drivers/net/wireless/marvell/mwifiex/sta_rx.c int mwifiex_process_rx_packet(struct mwifiex_private *priv, · line 99

Quoted 10 lines
drivers/net/wireless/marvell/mwifiex/sta_rx.c +1 -6
@@ -95,12 +96,13 @@ int mwifiex_process_rx_packet(struct mwifiex_private *priv,
 		return -1;
 	}
 
-	if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
-		     sizeof(bridge_tunnel_header))) ||
-	    (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
-		     sizeof(rfc1042_header)) &&
-	     ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
-	     ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) {
+	if (sizeof(*rx_pkt_hdr) + rx_pkt_off <= skb->len &&

Are you sure you want this length check to fall back to the non-802.3 codepath? Isn't it an error to look like an 802.3 frame but to be too small? I'd think we want to drop such packets, not process them as-is.

If I'm correct, then this check should move inside the 'if' branch of this if/else.

Brian

Quoted 12 lines
drivers/net/wireless/marvell/mwifiex/sta_rx.c +6 -0
+	    ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
+		      sizeof(bridge_tunnel_header))) ||
+	     (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
+		      sizeof(rfc1042_header)) &&
+	      ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
+	      ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX))) {
 		/*
 		 *  Replace the 803 header and rfc1042 header (llc/snap) with an
 		 *    EthernetII header, keep the src/dst and snap_type
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
#2 lore raw

Hi Brian,

Thanks for the review.

Quoted 41 lines · Brian Norris
Quoted 6 lines · Pin-yen Lin

Only skip the code path trying to access the rfc1042 headers when the buffer is too small, so the driver can still process packets without rfc1042 headers.

Fixes 119585281617 ("wifi: mwifiex: Fix OOB and integer underflow when rx packets")

I'd appreciate another review/test from one of the others here (Matthew?), even though I know y'all are already working together.

Quoted 29 lines

---

Changes in v3:
- Really apply the sizeof call fix as it was missed in the previous patch

Changes in v2:
- Fix sizeof call (sizeof(rx_pkt_hdr) --> sizeof(*rx_pkt_hdr))

 drivers/net/wireless/marvell/mwifiex/sta_rx.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/net/wireless/marvell/mwifiex/sta_rx.c +2 -1
index 65420ad67416..257737137cd7 100644
@@ -86,7 +86,8 @@ int mwifiex_process_rx_packet(struct mwifiex_private *priv,
      rx_pkt_len = le16_to_cpu(local_rx_pd->rx_pkt_length);
      rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_off;
 
-     if (sizeof(*rx_pkt_hdr) + rx_pkt_off > skb->len) {
+     if (sizeof(rx_pkt_hdr->eth803_hdr) + sizeof(rfc1042_header) +
+         rx_pkt_off > skb->len) {
              mwifiex_dbg(priv->adapter, ERROR,
                          "wrong rx packet offset: len=%d, rx_pkt_off=%d\n",
                          skb->len, rx_pkt_off);
@@ -95,12 +96,13 @@ int mwifiex_process_rx_packet(struct mwifiex_private *priv,
              return -1;
      }
 
Quoted 11 lines

drivers/net/wireless/marvell/mwifiex/sta_rx.c int mwifiex_process_rx_packet(struct mwifiex_private *priv, · line 99

Quoted 7 lines
drivers/net/wireless/marvell/mwifiex/sta_rx.c +1 -6
-     if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
-                  sizeof(bridge_tunnel_header))) ||
-         (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
-                  sizeof(rfc1042_header)) &&
-          ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
-          ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) {
+     if (sizeof(*rx_pkt_hdr) + rx_pkt_off <= skb->len &&

Are you sure you want this length check to fall back to the non-802.3 codepath? Isn't it an error to look like an 802.3 frame but to be too small? I'd think we want to drop such packets, not process them as-is.

I did that because I saw other drivers (e.g., [1], [2]) use similar approaches, and I assumed that the rest of the pipeline will eventually drop it if the packet cannot be recognized. But, yes, we can just drop the packet here if it doesn't look good.

[1]: https://elixir.bootlin.com/linux/latest/source/drivers/net/wireless/intersil/hostap/hostap_80211_rx.c#L1035
[2]: https://elixir.bootlin.com/linux/latest/source/drivers/net/wireless/intel/ipw2x00/libipw_rx.c#L735

Quoted 3 lines

If I'm correct, then this check should move inside the 'if' branch of this if/else.

We can't simply move the check inside the if branch because the condition also checks rx_pkt_hdr->rfc1042_hdr.snap_type. Though, of course, it is doable by adding another if conditions.

Quoted 3 lines

Brian

Regards,
Pin-yen

Quoted 12 lines
Quoted 12 lines
drivers/net/wireless/marvell/mwifiex/sta_rx.c +6 -1
+         ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
+                   sizeof(bridge_tunnel_header))) ||
+          (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
+                   sizeof(rfc1042_header)) &&
+           ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
+           ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX))) {
              /*
               *  Replace the 803 header and rfc1042 header (llc/snap) with an
               *    EthernetII header, keep the src/dst and snap_type
--

2.42.0.283.g2d96d420d3-goog

maintainer Acked-by
#3 lore raw
Quoted 3 lines · Pin-yen Lin
Quoted 2 lines · Brian Norris

I'd appreciate another review/test from one of the others here (Matthew?), even though I know y'all are already working together.

I'd still appreciate some comment here.

Quoted 12 lines
Quoted 11 lines

drivers/net/wireless/marvell/mwifiex/sta_rx.c int mwifiex_process_rx_packet(struct mwifiex_private *priv, · line 99

Quoted 7 lines
drivers/net/wireless/marvell/mwifiex/sta_rx.c +1 -6
-     if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
-                  sizeof(bridge_tunnel_header))) ||
-         (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
-                  sizeof(rfc1042_header)) &&
-          ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
-          ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) {
+     if (sizeof(*rx_pkt_hdr) + rx_pkt_off <= skb->len &&

Are you sure you want this length check to fall back to the non-802.3 codepath? Isn't it an error to look like an 802.3 frame but to be too small? I'd think we want to drop such packets, not process them as-is.

Quoted 7 lines

I did that because I saw other drivers (e.g., [1], [2]) use similar approaches, and I assumed that the rest of the pipeline will eventually drop it if the packet cannot be recognized. But, yes, we can just drop the packet here if it doesn't look good.

[1]: https://elixir.bootlin.com/linux/latest/source/drivers/net/wireless/intersil/hostap/hostap_80211_rx.c#L1035
[2]: https://elixir.bootlin.com/linux/latest/source/drivers/net/wireless/intel/ipw2x00/libipw_rx.c#L735

Hmm, I suppose. I'm frankly not sure how exactly all upper layers handle this, but at least in a non-raw mode, we'll drop them. (We might be delivering awfully weird packets to tcpdump though, but this is already a weird situation, if it's such a weird-looking packet.)

Quoted 6 lines
Quoted 2 lines

If I'm correct, then this check should move inside the 'if' branch of this if/else.

We can't simply move the check inside the if branch because the condition also checks rx_pkt_hdr->rfc1042_hdr.snap_type. Though, of course, it is doable by adding another if conditions.

Right.

I guess this is probably OK as-is:

Reviewed-by
#4 lore raw

lgtm

Quoted 45 lines · Brian Norris
Quoted 3 lines · Pin-yen Lin
Quoted 2 lines · Brian Norris

I'd appreciate another review/test from one of the others here (Matthew?), even though I know y'all are already working together.

I'd still appreciate some comment here.

Quoted 12 lines
Quoted 11 lines

drivers/net/wireless/marvell/mwifiex/sta_rx.c int mwifiex_process_rx_packet(struct mwifiex_private *priv, · line 99

Quoted 7 lines
drivers/net/wireless/marvell/mwifiex/sta_rx.c +1 -6
-     if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
-                  sizeof(bridge_tunnel_header))) ||
-         (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
-                  sizeof(rfc1042_header)) &&
-          ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
-          ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) {
+     if (sizeof(*rx_pkt_hdr) + rx_pkt_off <= skb->len &&

Are you sure you want this length check to fall back to the non-802.3 codepath? Isn't it an error to look like an 802.3 frame but to be too small? I'd think we want to drop such packets, not process them as-is.

Quoted 7 lines

I did that because I saw other drivers (e.g., [1], [2]) use similar approaches, and I assumed that the rest of the pipeline will eventually drop it if the packet cannot be recognized. But, yes, we can just drop the packet here if it doesn't look good.

[1]: https://elixir.bootlin.com/linux/latest/source/drivers/net/wireless/intersil/hostap/hostap_80211_rx.c#L1035
[2]: https://elixir.bootlin.com/linux/latest/source/drivers/net/wireless/intel/ipw2x00/libipw_rx.c#L735

Hmm, I suppose. I'm frankly not sure how exactly all upper layers handle this, but at least in a non-raw mode, we'll drop them. (We might be delivering awfully weird packets to tcpdump though, but this is already a weird situation, if it's such a weird-looking packet.)

Quoted 6 lines
Quoted 2 lines

If I'm correct, then this check should move inside the 'if' branch of this if/else.

We can't simply move the check inside the if branch because the condition also checks rx_pkt_hdr->rfc1042_hdr.snap_type. Though, of course, it is doable by adding another if conditions.

Right.

I guess this is probably OK as-is:

#5 lore raw
Quoted 3 lines · Matthew Wang

lgtm

Please don't top post, it's just bad in so many levels. This has been discussed and explained in our docs so many times that I'm not going to repeat those anymore. If you are too busy to edit your quotes and reply properly then it's better not to reply at all.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#6 lore raw
In reply to Pin-yen Lin
Quoted 8 lines · Pin-yen Lin

Only skip the code path trying to access the rfc1042 headers when the buffer is too small, so the driver can still process packets without rfc1042 headers.

Fixes 119585281617 ("wifi: mwifiex: Fix OOB and integer underflow when rx packets")

Patch applied to wireless.git, thanks.

aef7a0300047 wifi: mwifiex: Fix oob check condition in mwifiex_process_rx_packet

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches