net: qualcomm: rmnet: validate MAP frame length before ingress parsing
Subsystems (3)
PATCH v2 1/1 net: qualcomm: rmnet: validate MAP frame length before ingress parsing
When ingress deaggregation is disabled, rmnet_map_ingress_handler() passes the skb straight to __rmnet_map_ingress_handler(), skipping the length validation that rmnet_map_deaggregate() performs on the aggregated path. The parser then dereferences the MAP header and csum header/trailer based on the on-wire pkt_len without checking skb->len, so a short frame is read out of bounds:
BUG: KASAN: slab-out-of-bounds in rmnet_map_checksum_downlink_packet Read of size 1 at addr ffff88801118ed00 by task exploit/147 Call Trace: ... rmnet_map_checksum_downlink_packet (drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c:413) __rmnet_map_ingress_handler (drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:96) rmnet_rx_handler (drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:129) __netif_receive_skb_core.constprop.0 (net/core/dev.c:6089) netif_receive_skb (net/core/dev.c:6460) tun_get_user (drivers/net/tun.c:1955) tun_chr_write_iter (drivers/net/tun.c:2001) vfs_write (fs/read_write.c:688) ksys_write (fs/read_write.c:740) do_syscall_64 (arch/x86/entry/syscall_64.c:94) ...
Factor that validation out of rmnet_map_deaggregate() into rmnet_map_validate_packet_len() and run it on the no-aggregation path too. The MAP header is bounds-checked first, since this path can receive a frame shorter than the header.
---
v2: Validate on the no-aggregation path by reusing the deaggregation
length checks (factored into rmnet_map_validate_packet_len()) instead of adding separate pskb_may_pull() guards in __rmnet_map_ingress_handler().
.../ethernet/qualcomm/rmnet/rmnet_handlers.c | 5 +- .../net/ethernet/qualcomm/rmnet/rmnet_map.h | 1 + .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 72 ++++++++++--------- 3 files changed, 45 insertions(+), 33 deletions(-)
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +4 -1
@@ -126,7 +126,10 @@ rmnet_map_ingress_handler(struct sk_buff *skb,consume_skb (skb); }else { -__rmnet_map_ingress_handler (skb, port); +if (rmnet_map_validate_packet_len (skb, port)) +__rmnet_map_ingress_handler (skb, port); +else +kfree_skb (skb); } }
drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h +1 -0
@@ -59,5 +59,6 @@ void rmnet_map_tx_aggregate_init(struct rmnet_port *port);void rmnet_map_tx_aggregate_exit (struct rmnet_port *port);void rmnet_map_update_ul_agg_config (struct rmnet_port *port,u32 size,u32 count,u32 time); +u32 rmnet_map_validate_packet_len (struct sk_buff *skb,struct rmnet_port *port);#endif /* _RMNET_MAP_H_ */
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +40 -32
94 lines not on this page · raw message
Signature · 1 line
2.43.0
Thanks so much for your refactor. It's better! I took it for v2 with two small changes:
- Dropped the goto err1/err0; the helper has no cleanup, so it just returns 0 or packet_len directly. (err0 was the success path anyway.)
- The no-agg caller leaks the skb when validation fails, since __rmnet_map_ingress_handler() is the one that owns and frees it:
if (rmnet_map_validate_packet_len(skb, port))__rmnet_map_ingress_handler(skb, port);
elsekfree_skb(skb);
I also bounds-check the MAP header up front (skb->len < sizeof(*maph)), since the no-agg path can get a frame shorter than the header before maph->pkt_len is read.
v2 sent with you as Suggested-by. Tested with the original repro: OOB gone on the no-agg path, valid frames and the deagg path unaffected.
Xiang
Quoted 172 lines · Xiang Mei
When ingress deaggregation is disabled,
rmnet_map_ingress_handler()passes the skb straight to__rmnet_map_ingress_handler(), skipping the length validation thatrmnet_map_deaggregate()performs on the aggregated path. The parser then dereferences the MAP header and csum header/trailer based on the on-wirepkt_lenwithout checkingskb->len, so a short frame is read out of bounds:BUG: KASAN: slab-out-of-bounds in rmnet_map_checksum_downlink_packet Read of size 1 at addr ffff88801118ed00 by task exploit/147 Call Trace: ... rmnet_map_checksum_downlink_packet (drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c:413) __rmnet_map_ingress_handler (drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:96) rmnet_rx_handler (drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:129) __netif_receive_skb_core.constprop.0 (net/core/dev.c:6089) netif_receive_skb (net/core/dev.c:6460) tun_get_user (drivers/net/tun.c:1955) tun_chr_write_iter (drivers/net/tun.c:2001) vfs_write (fs/read_write.c:688) ksys_write (fs/read_write.c:740) do_syscall_64 (arch/x86/entry/syscall_64.c:94) ...Factor that validation out of
rmnet_map_deaggregate()intormnet_map_validate_packet_len()and run it on the no-aggregation path too. The MAP header is bounds-checked first, since this path can receive a frame shorter than the header.Fixes ceed73a2cf4a ("drivers: net: ethernet: qualcomm: rmnet: Initial implementation")Reported-by Weiming Shi <[email protected]>Suggested-by Subash Abhinov Kasiviswanathan <[email protected]>Signed-off-by Xiang Mei <[email protected]>---
v2: Validate on the no-aggregation path by reusing the deaggregation
length checks (factored intormnet_map_validate_packet_len()) instead of adding separatepskb_may_pull()guards in__rmnet_map_ingress_handler()..../ethernet/qualcomm/rmnet/rmnet_handlers.c | 5 +- .../net/ethernet/qualcomm/rmnet/rmnet_map.h | 1 + .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 72 ++++++++++--------- 3 files changed, 45 insertions(+), 33 deletions(-)drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +4
-1@@ -126,7 +126,10 @@ rmnet_map_ingress_handler(struct sk_buff *skb,consume_skb (skb); }else { -__rmnet_map_ingress_handler (skb, port); +if (rmnet_map_validate_packet_len (skb, port)) +__rmnet_map_ingress_handler (skb, port); +else +kfree_skb (skb); } }drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h +1
-0@@ -59,5 +59,6 @@ void rmnet_map_tx_aggregate_init(struct rmnet_port *port);void rmnet_map_tx_aggregate_exit (struct rmnet_port *port);void rmnet_map_update_ul_agg_config (struct rmnet_port *port,u32 size,u32 count,u32 time); +u32 rmnet_map_validate_packet_len (struct sk_buff *skb,struct rmnet_port *port);#endif /* _RMNET_MAP_H_ */ drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +40
-33@@ -333,54 +333,62 @@ struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb,return map_header; } -/* Deaggregates a single packet -* A whole new buffer is allocated for each portion of an aggregated frame. -* Caller should keep calling deaggregate() on the source skb until 0 is -* returned, indicating that there are no more packets to deaggregate. Caller -* is responsible for freeing the original skb. -*/ -struct sk_buff *rmnet_map_deaggregate (struct sk_buff *skb, -struct rmnet_port *port) +u32 rmnet_map_validate_packet_len (struct sk_buff *skb,struct rmnet_port *port) {struct rmnet_map_v5_csum_header *next_hdr =NULL ;struct rmnet_map_header *maph;void *data = skb->data; -struct sk_buff *skbn; -u8 nexthdr_type;u32 packet_len; -if (skb->len ==0 ) -return NULL ; +if (skb->len <sizeof (*maph)) +return 0 ; maph = (struct rmnet_map_header *)skb->data; + +/* Some hardware can send us empty frames. Catch them */ +if (!maph->pkt_len) +return 0 ; + packet_len =ntohs (maph->pkt_len) +sizeof (*maph);if (port->data_format &RMNET_FLAGS_INGRESS_MAP_CKSUMV4 ) { packet_len +=sizeof (struct rmnet_map_dl_csum_trailer ); - }else if (port->data_format &RMNET_FLAGS_INGRESS_MAP_CKSUMV5 ) { -if (!(maph->flags &MAP_CMD_FLAG )) { - packet_len +=sizeof (*next_hdr); -if (maph->flags &MAP_NEXT_HEADER_FLAG ) - next_hdr = data +sizeof (*maph); -else -/* Mapv5 data pkt without csum hdr is invalid */ -return NULL ; - } + }else if ((port->data_format &RMNET_FLAGS_INGRESS_MAP_CKSUMV5 ) && + !(maph->flags &MAP_CMD_FLAG )) { +/* Mapv5 data pkt without csum hdr is invalid */ +if (!(maph->flags &MAP_NEXT_HEADER_FLAG )) +return 0 ; + + packet_len +=sizeof (*next_hdr); + next_hdr = data +sizeof (*maph); } -if (((int )skb->len - (int )packet_len) <0 ) -return NULL ; +if (skb->len < packet_len) +return 0 ; -/* Some hardware can send us empty frames. Catch them */ -if (!maph->pkt_len) -return NULL ; +if (next_hdr && +u8_get_bits (next_hdr->header_info,MAPV5_HDRINFO_HDR_TYPE_FMASK ) != +RMNET_MAP_HEADER_TYPE_CSUM_OFFLOAD ) +return 0 ; -if (next_hdr) { - nexthdr_type =u8_get_bits (next_hdr->header_info, -MAPV5_HDRINFO_HDR_TYPE_FMASK ); -if (nexthdr_type !=RMNET_MAP_HEADER_TYPE_CSUM_OFFLOAD ) -return NULL ; - } +return packet_len; +} + +/* Deaggregates a single packet +* A whole new buffer is allocated for each portion of an aggregated frame. +* Caller should keep calling deaggregate() on the source skb until 0 is +* returned, indicating that there are no more packets to deaggregate. Caller +* is responsible for freeing the original skb. +*/ +struct sk_buff *rmnet_map_deaggregate (struct sk_buff *skb, +struct rmnet_port *port) +{ +struct sk_buff *skbn; +u32 packet_len; + + packet_len =rmnet_map_validate_packet_len (skb, port); +if (!packet_len) +return NULL ; skbn =alloc_skb (packet_len +RMNET_MAP_DEAGGR_SPACING ,GFP_ATOMIC );if (!skbn) --2.43.0
[email protected]
maintainerQuoted 11 lines
-----Original Message-----
From: Xiang Mei <[email protected]>
Sent: Tuesday, June 30, 2026 11:41 AM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; Xiang Mei <[email protected]>
Subject: [PATCH net v2] net: qualcomm: rmnet: validate MAP frame length before ingress parsing
Quoted 6 lines
When ingress deaggregation is disabled,
rmnet_map_ingress_handler()passes the skb straight to__rmnet_map_ingress_handler(), skipping the length validation thatrmnet_map_deaggregate()performs on the aggregated path. The parser then dereferences the MAP header and csum header/trailer based on
the on-wirepkt_lenwithout checkingskb->len, so a short frame is read
out
Quoted 22 lines
of bounds:
BUG: KASAN: slab-out-of-bounds in rmnet_map_checksum_downlink_packet Read of size 1 at addr ffff88801118ed00 by task exploit/147 Call Trace: ... rmnet_map_checksum_downlink_packet(
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c:413)
__rmnet_map_ingress_handler
(drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:96)
rmnet_rx_handler
(drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:129)
__netif_receive_skb_core.constprop.0 (net/core/dev.c:6089)netif_receive_skb(net/core/dev.c:6460)tun_get_user(drivers/net/tun.c:1955)tun_chr_write_iter(drivers/net/tun.c:2001)vfs_write(fs/read_write.c:688)
ksys_write(fs/read_write.c:740)
do_syscall_64(arch/x86/entry/syscall_64.c:94)
...
Quoted 3 lines
Factor that validation out of
rmnet_map_deaggregate()intormnet_map_validate_packet_len()and run it on the no-aggregation path too. The MAP header is bounds-checked first, since this path can receive a
frame
Quoted 56 lines
shorter than the header.
Fixes ceed73a2cf4a ("drivers: net: ethernet: qualcomm: rmnet: Initialimplementation")
Reported-by Weiming Shi <[email protected]>Suggested-by Subash Abhinov KasiviswanathanSigned-off-by Xiang Mei <[email protected]>---
v2: Validate on the no-aggregation path by reusing the deaggregation
length checks (factored intormnet_map_validate_packet_len()) instead of adding separatepskb_may_pull()guards in__rmnet_map_ingress_handler()..../ethernet/qualcomm/rmnet/rmnet_handlers.c | 5 +- .../net/ethernet/qualcomm/rmnet/rmnet_map.h | 1 + .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 72 ++++++++++--------- 3 files changed, 45 insertions(+), 33 deletions(-)drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +4
-1@@ -126,7 +126,10 @@ rmnet_map_ingress_handler(struct sk_buff *skb,consume_skb (skb); }else { -__rmnet_map_ingress_handler (skb, port); +if (rmnet_map_validate_packet_len (skb, port)) +__rmnet_map_ingress_handler (skb, port); +else +kfree_skb (skb); } }drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h +1
-0@@ -59,5 +59,6 @@ void rmnet_map_tx_aggregate_init(struct rmnet_port *port);void rmnet_map_tx_aggregate_exit (struct rmnet_port *port);void rmnet_map_update_ul_agg_config (struct rmnet_port *port,u32 size,u32 count,u32 time); +u32 rmnet_map_validate_packet_len (struct sk_buff *skb,struct rmnet_port *port);#endif /* _RMNET_MAP_H_ */
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +0
-0
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c struct rmnet_map_header · line 338
Quoted 6 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +0
-2@@ -333,54 +333,62 @@ struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb, return map_header; } -/* Deaggregates a single packet - * A whole new buffer is allocated for each portion of an aggregated
frame.
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c struct rmnet_map_header · line 340
Quoted 2 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +0
-2-* Caller should keep calling deaggregate() on the source skb until 0 is -* returned, indicating that there are no more packets to deaggregate.
Caller
Quoted 27 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +8
-8-* is responsible for freeing the original skb. -*/ -struct sk_buff *rmnet_map_deaggregate (struct sk_buff *skb, -struct rmnet_port *port) +u32 rmnet_map_validate_packet_len (struct sk_buff *skb,struct rmnet_port *port) {struct rmnet_map_v5_csum_header *next_hdr =NULL ;struct rmnet_map_header *maph;void *data = skb->data; -struct sk_buff *skbn; -u8 nexthdr_type;u32 packet_len; -if (skb->len ==0 ) -return NULL ; +if (skb->len <sizeof (*maph)) +return 0 ; maph = (struct rmnet_map_header *)skb->data; + +/* Some hardware can send us empty frames. Catch them */ +if (!maph->pkt_len) +return 0 ; + packet_len =ntohs (maph->pkt_len) +sizeof (*maph);
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb,
Quoted 10 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +0
-7if (port->data_format &RMNET_FLAGS_INGRESS_MAP_CKSUMV4 ) { packet_len +=sizeof (struct rmnet_map_dl_csum_trailer ); - }else if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV5) { -if (!(maph->flags &MAP_CMD_FLAG )) { - packet_len +=sizeof (*next_hdr); -if (maph->flags &MAP_NEXT_HEADER_FLAG ) - next_hdr = data +sizeof (*maph); -else -/* Mapv5 data pkt without csum hdr is
invalid
Quoted 34 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +1
-2*/ -return NULL ; - } + } else if ((port->data_format &
RMNET_FLAGS_INGRESS_MAP_CKSUMV5) &&drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +11
-5+ !(maph->flags & MAP_CMD_FLAG)) { +/* Mapv5 data pkt without csum hdr is invalid */ +if (!(maph->flags &MAP_NEXT_HEADER_FLAG )) +return 0 ; + + packet_len +=sizeof (*next_hdr); + next_hdr = data +sizeof (*maph); } -if (((int )skb->len - (int )packet_len) <0 ) -return NULL ; +if (skb->len < packet_len) +return 0 ; -/* Some hardware can send us empty frames. Catch them */ -if (!maph->pkt_len) -return NULL ; +if (next_hdr && + u8_get_bits(next_hdr->header_info,
MAPV5_HDRINFO_HDR_TYPE_FMASK) !=drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +2
-3+ RMNET_MAP_HEADER_TYPE_CSUM_OFFLOAD) +return 0 ; -if (next_hdr) { - nexthdr_type = u8_get_bits(next_hdr->header_info, -
MAPV5_HDRINFO_HDR_TYPE_FMASK);drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +0
-1- if (nexthdr_type !=
RMNET_MAP_HEADER_TYPE_CSUM_OFFLOAD)
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb,
Quoted 7 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +5
-2-return NULL ; - } +return packet_len; +} + +/* Deaggregates a single packet +* A whole new buffer is allocated for each portion of an aggregated
frame.
Quoted 2 lines
+ * Caller should keep calling
deaggregate()on the source skb until 0 is
+ * returned, indicating that there are no more packets to deaggregate.
Caller
Quoted 13 lines
+ * is responsible for freeing the original skb.
+ */drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +9
-0+struct sk_buff *rmnet_map_deaggregate (struct sk_buff *skb, +struct rmnet_port *port) +{ +struct sk_buff *skbn; +u32 packet_len; + + packet_len =rmnet_map_validate_packet_len (skb, port); +if (!packet_len) +return NULL ; skbn = alloc_skb(packet_len + RMNET_MAP_DEAGGR_SPACING,
Quoted 4 lines
GFP_ATOMIC);
if (!skbn)
--
2.43.0
Reviewed-by: Subash Abhinov Kasiviswanathan
<[email protected]>
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Tue, 30 Jun 2026 10:41:09 -0700 you wrote:
When ingress deaggregation is disabled,
rmnet_map_ingress_handler()passes the skb straight to__rmnet_map_ingress_handler(), skipping the length validation thatrmnet_map_deaggregate()performs on the aggregated path. The parser then dereferences the MAP header and csum header/trailer based on the on-wirepkt_lenwithout checkingskb->len, so a short frame is read out of bounds:[...]
Here is the summary with links:
- [net,v2] net: qualcomm: rmnet: validate MAP frame length before ingress parsing
https://git.kernel.org/netdev/net/c/f0f1887a9e30
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html