Skip to contentSkip to conversation

net: qualcomm: rmnet: set skb->dev for deaggregated MAP commands

PATCH In review Xiang Mei 2 participants 3 messages Aug 20

Subsystems (3)
lore
Share & tools
lore

Xiang Mei

author
#0 lore raw

PATCH 1/1 net: qualcomm: rmnet: set skb->dev for deaggregated MAP commands

rmnet_map_deaggregate() allocates each sub-frame with alloc_skb() and leaves skb->dev NULL. __rmnet_map_ingress_handler() assigns skb->dev = ep->egress_dev only on the data path, but a MAP command frame is dispatched to rmnet_map_command() before that, so rmnet_map_send_ack() runs netif_tx_lock(skb->dev) on a NULL device. An unprivileged user reaches this by unsharing a user+net namespace, creating an rmnet link over a tap device with INGRESS_DEAGGREGATION and INGRESS_MAP_COMMANDS, and writing an aggregated frame carrying a flow-control command to the tap fd.

Assign port->dev before dispatch: the command was received on the real device tracked by port->dev and the ACK must egress on that same device. The non-deaggregated path already has skb->dev == real_dev.

  BUG: KASAN: null-ptr-deref in _raw_spin_lock (kernel/locking/spinlock.c:158)
  Write of size 4 at addr 00000000000004b4 by task exploit/144
  Call Trace:
   _raw_spin_lock (kernel/locking/spinlock.c:158)
   netif_tx_lock (net/sched/sch_generic.c:497)
   rmnet_map_command (drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c:67)
   rmnet_rx_handler (drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:125)
   __netif_receive_skb_core.constprop.0 (net/core/dev.c:6103)
   ...
   __netif_receive_skb_one_core (net/core/dev.c:6214)
   netif_receive_skb (net/core/dev.c:6474)
   tun_get_user (drivers/net/tun.c:1966)
   tun_chr_write_iter (drivers/net/tun.c:2012)
   vfs_write (fs/read_write.c:687)
   ksys_write (fs/read_write.c:739)
   do_syscall_64 (arch/x86/entry/syscall_64.c:94)
   entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
  Kernel panic - not syncing: Fatal exception in interrupt
Fixes 378e25357ac7 ("net: qualcomm: rmnet: Remove unnecessary device assignment")
Reported-by [email protected]
Assisted-by Claude:claude-opus-4-8
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c +2 -0
index add0f5ade2e6..3944925566fc 100644
@@ -79,6 +79,8 @@ void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port)
 	unsigned char command_name;
 	unsigned char rc = 0;
 
+	skb->dev = port->dev;
+
 	/* Command data immediately follows the MAP header */
 	cmd = (struct rmnet_map_control_command *)(map_header + 1);
 	command_name = cmd->command_name;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 48 lines · Xiang Mei

rmnet_map_deaggregate() allocates each sub-frame with alloc_skb() and leaves skb->dev NULL. __rmnet_map_ingress_handler() assigns skb->dev = ep->egress_dev only on the data path, but a MAP command frame is dispatched to rmnet_map_command() before that, so rmnet_map_send_ack() runs netif_tx_lock(skb->dev) on a NULL device. An unprivileged user reaches this by unsharing a user+net namespace, creating an rmnet link over a tap device with INGRESS_DEAGGREGATION and INGRESS_MAP_COMMANDS, and writing an aggregated frame carrying a flow-control command to the tap fd.

Assign port->dev before dispatch: the command was received on the real device tracked by port->dev and the ACK must egress on that same device. The non-deaggregated path already has skb->dev == real_dev.

  BUG: KASAN: null-ptr-deref in _raw_spin_lock (kernel/locking/spinlock.c:158)
  Write of size 4 at addr 00000000000004b4 by task exploit/144
  Call Trace:
   _raw_spin_lock (kernel/locking/spinlock.c:158)
   netif_tx_lock (net/sched/sch_generic.c:497)
   rmnet_map_command (drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c:67)
   rmnet_rx_handler (drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:125)
   __netif_receive_skb_core.constprop.0 (net/core/dev.c:6103)
   ...
   __netif_receive_skb_one_core (net/core/dev.c:6214)
   netif_receive_skb (net/core/dev.c:6474)
   tun_get_user (drivers/net/tun.c:1966)
   tun_chr_write_iter (drivers/net/tun.c:2012)
   vfs_write (fs/read_write.c:687)
   ksys_write (fs/read_write.c:739)
   do_syscall_64 (arch/x86/entry/syscall_64.c:94)
   entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
  Kernel panic - not syncing: Fatal exception in interrupt
Fixes 378e25357ac7 ("net: qualcomm: rmnet: Remove unnecessary device assignment")
Reported-by [email protected]
Assisted-by Claude:claude-opus-4-8
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c +0 -0
index add0f5ade2e6..3944925566fc 100644

drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port) · line 83

Quoted 5 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c +2 -0
@@ -79,6 +79,8 @@ void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port)
        unsigned char command_name;
        unsigned char rc = 0;
 
+       skb->dev = port->dev;
+

This works, but the suggested patch is cleaner IMO

https://bugs.sh/b/4638111fe2a12980/patch.diff

author
#2 lore raw
Quoted 53 lines · Eric Dumazet
Quoted 51 lines · Xiang Mei

rmnet_map_deaggregate() allocates each sub-frame with alloc_skb() and leaves skb->dev NULL. __rmnet_map_ingress_handler() assigns skb->dev = ep->egress_dev only on the data path, but a MAP command frame is dispatched to rmnet_map_command() before that, so rmnet_map_send_ack() runs netif_tx_lock(skb->dev) on a NULL device. An unprivileged user reaches this by unsharing a user+net namespace, creating an rmnet link over a tap device with INGRESS_DEAGGREGATION and INGRESS_MAP_COMMANDS, and writing an aggregated frame carrying a flow-control command to the tap fd.

Assign port->dev before dispatch: the command was received on the real device tracked by port->dev and the ACK must egress on that same device. The non-deaggregated path already has skb->dev == real_dev.

  BUG: KASAN: null-ptr-deref in _raw_spin_lock (kernel/locking/spinlock.c:158)
  Write of size 4 at addr 00000000000004b4 by task exploit/144
  Call Trace:
   _raw_spin_lock (kernel/locking/spinlock.c:158)
   netif_tx_lock (net/sched/sch_generic.c:497)
   rmnet_map_command (drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c:67)
   rmnet_rx_handler (drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:125)
   __netif_receive_skb_core.constprop.0 (net/core/dev.c:6103)
   ...
   __netif_receive_skb_one_core (net/core/dev.c:6214)
   netif_receive_skb (net/core/dev.c:6474)
   tun_get_user (drivers/net/tun.c:1966)
   tun_chr_write_iter (drivers/net/tun.c:2012)
   vfs_write (fs/read_write.c:687)
   ksys_write (fs/read_write.c:739)
   do_syscall_64 (arch/x86/entry/syscall_64.c:94)
   entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
  Kernel panic - not syncing: Fatal exception in interrupt
Fixes 378e25357ac7 ("net: qualcomm: rmnet: Remove unnecessary device assignment")
Reported-by [email protected]
Assisted-by Claude:claude-opus-4-8
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c +0 -0
index add0f5ade2e6..3944925566fc 100644
@@ -79,6 +79,8 @@ void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port)
        unsigned char command_name;
        unsigned char rc = 0;
 
Quoted 5 lines

drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port) · line 83

Quoted 2 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c +2 -0
+       skb->dev = port->dev;
+

This works, but the suggested patch is cleaner IMO

Thanks for your review!

Quoted 1 line

https://bugs.sh/b/4638111fe2a12980/patch.diff

Agreed, that is the better fix (fix the problem at producer end). v2 has been sent:
https://lore.kernel.org/netdev/[email protected]/T/#u

-Xiang