Netdev List
 help / color / mirror / Atom feed
* [PATCH net 0/6] net: qualcomm: rmnet: fix TX aggregation and teardown bugs
@ 2026-11-26 16:32 Antonio Quartulli
  2026-11-26 16:32 ` [PATCH net 1/6] net: qualcomm: rmnet: recheck the aggregate after flushing it Antonio Quartulli
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Antonio Quartulli @ 2026-11-26 16:32 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Taehee Yoo, koen.vandeputte, Antonio Quartulli

Bugs in rmnet TX aggregation and bridge teardown, found while
reviewing [1]. Each commit message includes a reproducer.

All were reproduced in a VM (KASAN, kmemleak, DEBUG_OBJECTS) before the
fix and are gone after it; patch 2 needs a debug udelay() to widen the
race window, patch 3 a 32-bit kernel.

Although this patchset is targeting net, the described reproducers
should help maintainers understandsing if patches should rather be
demoted to net-next material...

Regards,

[1] https://lore.kernel.org/netdev/20261002143529.3217189-1-koen.vandeputte@citymesh.com/

Antonio Quartulli (6):
  net: qualcomm: rmnet: recheck the aggregate after flushing it
  net: qualcomm: rmnet: always arm the flush timer for a new aggregate
  net: qualcomm: rmnet: fix TX aggregation timeout overflow on 32-bit
  net: qualcomm: rmnet: stop TX aggregation after detaching the port
  net: qualcomm: rmnet: account linearization failures on the real
    device
  net: qualcomm: rmnet: unlink the bridge from the vnd it is attached to

 .../net/ethernet/qualcomm/rmnet/rmnet_config.c    |  7 ++++---
 .../net/ethernet/qualcomm/rmnet/rmnet_map_data.c  | 15 ++++++---------
 2 files changed, 10 insertions(+), 12 deletions(-)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net 1/6] net: qualcomm: rmnet: recheck the aggregate after flushing it
  2026-11-26 16:32 [PATCH net 0/6] net: qualcomm: rmnet: fix TX aggregation and teardown bugs Antonio Quartulli
@ 2026-11-26 16:32 ` Antonio Quartulli
  2026-11-26 16:32 ` [PATCH net 2/6] net: qualcomm: rmnet: always arm the flush timer for a new aggregate Antonio Quartulli
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Antonio Quartulli @ 2026-11-26 16:32 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Taehee Yoo, koen.vandeputte, Antonio Quartulli

When an skb does not fit in the pending aggregate,
rmnet_map_tx_aggregate() flushes it with agg_lock dropped, then jumps
back past the skbagg_head check. rmnet vnds are lltx and can share a
port, so another CPU may start an aggregate meanwhile: it is then
overwritten and leaked along with the packets chained to it, or
overtaken by a skb sent without aggregation.

Reproducer, with UDP sent through both vnds from several CPUs:

  ip link add v0 mtu 9000 type veth peer name v1 mtu 9000
  ip link set v0 up; ip link set v1 up
  ip link add link v0 name rmnet1 type rmnet mux_id 1
  ip link add link v0 name rmnet2 type rmnet mux_id 2
  ethtool -C rmnet1 tx-aggr-max-frames 64 tx-aggr-max-bytes 4096 \
          tx-aggr-time-usecs 2000

The tx_bytes of rmnet1 and rmnet2 soon exceed those of v0, and kmemleak
reports skbs allocated by skb_copy_expand() in rmnet_map_tx_aggregate().

Move the label before the skbagg_head check.

Fixes: 64b5d1f8f2d1 ("net: qualcomm: rmnet: add tx packets aggregation")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index 39d6d084e73f..73b04fe386df 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -600,11 +600,11 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port
 	memcpy(&last, &port->agg_last, sizeof(struct timespec64));
 	ktime_get_real_ts64(&port->agg_last);
 
+new_packet:
 	if (!port->skbagg_head) {
 		/* Check to see if we should agg first. If the traffic is very
 		 * sparse, don't aggregate.
 		 */
-new_packet:
 		diff = timespec64_sub(port->agg_last, last);
 		size = port->egress_agg_params.bytes - skb->len;
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net 2/6] net: qualcomm: rmnet: always arm the flush timer for a new aggregate
  2026-11-26 16:32 [PATCH net 0/6] net: qualcomm: rmnet: fix TX aggregation and teardown bugs Antonio Quartulli
  2026-11-26 16:32 ` [PATCH net 1/6] net: qualcomm: rmnet: recheck the aggregate after flushing it Antonio Quartulli
@ 2026-11-26 16:32 ` Antonio Quartulli
  2026-11-26 16:32 ` [PATCH net 3/6] net: qualcomm: rmnet: fix TX aggregation timeout overflow on 32-bit Antonio Quartulli
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Antonio Quartulli @ 2026-11-26 16:32 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Taehee Yoo, koen.vandeputte, Antonio Quartulli

On flush, rmnet_map_tx_aggregate() resets agg_state and drops agg_lock
before cancelling the flush timer. A CPU starting a new aggregate in
that window finds the old timer active, so it neither arms it nor sets
agg_state. Once the old timer is cancelled, the new aggregate waits for
the next packet, and rmnet_map_tx_aggregate_exit() leaks it because
agg_state is not -EINPROGRESS.

To make reproducing this bug easier, a udelay(2000) was added
after agg_lock is dropped in the flush paths. Then, with two vnds on one
port, tx-aggr-max-frames 2 and tx-aggr-time-usecs 100000, one CPU sends
3 packets on the first vnd (bypass, new aggregate, flush) and another
sends 1 packet on the second vnd 0.5 ms later: that packet stays queued
past the timeout.

Cancel the timer under agg_lock, so a timer armed for a newer aggregate
cannot be cancelled, and arm it whenever agg_state is not -EINPROGRESS;
hrtimer_start() copes with a timer that is still enqueued or running.
If the cancel races with a running callback, the flush work it queued
finds either no aggregate or the new one, which it flushes early.

Fixes: 64b5d1f8f2d1 ("net: qualcomm: rmnet: add tx packets aggregation")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index 73b04fe386df..fdfc65c7c5e5 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -635,8 +635,8 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port
 	if (skb->len > size) {
 		agg_skb = port->skbagg_head;
 		reset_aggr_params(port);
+		hrtimer_try_to_cancel(&port->hrtimer);
 		spin_unlock_bh(&port->agg_lock);
-		hrtimer_cancel(&port->hrtimer);
 		rmnet_send_skb(port, agg_skb);
 		spin_lock_bh(&port->agg_lock);
 		goto new_packet;
@@ -658,14 +658,14 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port
 	    port->skbagg_head->len == port->egress_agg_params.bytes) {
 		agg_skb = port->skbagg_head;
 		reset_aggr_params(port);
+		hrtimer_try_to_cancel(&port->hrtimer);
 		spin_unlock_bh(&port->agg_lock);
-		hrtimer_cancel(&port->hrtimer);
 		rmnet_send_skb(port, agg_skb);
 		return len;
 	}
 
 schedule:
-	if (!hrtimer_active(&port->hrtimer) && port->agg_state != -EINPROGRESS) {
+	if (port->agg_state != -EINPROGRESS) {
 		port->agg_state = -EINPROGRESS;
 		hrtimer_start(&port->hrtimer,
 			      ns_to_ktime(port->egress_agg_params.time_nsec),
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net 3/6] net: qualcomm: rmnet: fix TX aggregation timeout overflow on 32-bit
  2026-11-26 16:32 [PATCH net 0/6] net: qualcomm: rmnet: fix TX aggregation and teardown bugs Antonio Quartulli
  2026-11-26 16:32 ` [PATCH net 1/6] net: qualcomm: rmnet: recheck the aggregate after flushing it Antonio Quartulli
  2026-11-26 16:32 ` [PATCH net 2/6] net: qualcomm: rmnet: always arm the flush timer for a new aggregate Antonio Quartulli
@ 2026-11-26 16:32 ` Antonio Quartulli
  2026-11-26 16:32 ` [PATCH net 4/6] net: qualcomm: rmnet: stop TX aggregation after detaching the port Antonio Quartulli
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Antonio Quartulli @ 2026-11-26 16:32 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Taehee Yoo, koen.vandeputte, Antonio Quartulli

On 32-bit, time * NSEC_PER_USEC is computed in 32 bits before being
stored in the u64 time_nsec, so a tx-aggr-time-usecs above 4294967
wraps: 5000000 is stored as 705032704 ns and read back as 705032.

Reproducer:

  ethtool -C rmnet0 tx-aggr-max-frames 64 tx-aggr-time-usecs 5000000
  ethtool -c rmnet0

Do the multiplication in 64 bits.

Fixes: 64b5d1f8f2d1 ("net: qualcomm: rmnet: add tx packets aggregation")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index fdfc65c7c5e5..b156e864535f 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -689,7 +689,7 @@ void rmnet_map_update_ul_agg_config(struct rmnet_port *port, u32 size,
 	spin_lock_bh(&port->agg_lock);
 	port->egress_agg_params.bytes = size;
 	WRITE_ONCE(port->egress_agg_params.count, count);
-	port->egress_agg_params.time_nsec = time * NSEC_PER_USEC;
+	port->egress_agg_params.time_nsec = (u64)time * NSEC_PER_USEC;
 	spin_unlock_bh(&port->agg_lock);
 }
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net 4/6] net: qualcomm: rmnet: stop TX aggregation after detaching the port
  2026-11-26 16:32 [PATCH net 0/6] net: qualcomm: rmnet: fix TX aggregation and teardown bugs Antonio Quartulli
                   ` (2 preceding siblings ...)
  2026-11-26 16:32 ` [PATCH net 3/6] net: qualcomm: rmnet: fix TX aggregation timeout overflow on 32-bit Antonio Quartulli
@ 2026-11-26 16:32 ` Antonio Quartulli
  2026-11-26 16:32 ` [PATCH net 5/6] net: qualcomm: rmnet: account linearization failures on the real device Antonio Quartulli
  2026-11-26 16:32 ` [PATCH net 6/6] net: qualcomm: rmnet: unlink the bridge from the vnd it is attached to Antonio Quartulli
  5 siblings, 0 replies; 7+ messages in thread
From: Antonio Quartulli @ 2026-11-26 16:32 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Taehee Yoo, koen.vandeputte, Antonio Quartulli

rmnet_unregister_real_device() tears down the aggregation state before
unregistering the rx handler. When the last vnd on a port is deleted,
that vnd is still registered and the egress path still finds the port
through rx_handler_data, so a transmit can start an aggregate and arm
the timer. The port is then freed: the timer fires on freed memory and
the aggregate leaks.

Reproducer:

  ip link add link v0 name rmnet1 type rmnet mux_id 1
  ethtool -C rmnet1 tx-aggr-max-frames 64 tx-aggr-max-bytes 4096 \
          tx-aggr-time-usecs 1000000

then delete rmnet1 while flooding UDP through it from all CPUs.
DEBUG_OBJECTS_TIMERS reports "ODEBUG: free active object type: hrtimer",
KASAN a use-after-free once the timer fires.

Unregister the rx handler first: after its RCU grace period no transmit
can find the port.

Fixes: 64b5d1f8f2d1 ("net: qualcomm: rmnet: add tx packets aggregation")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
index 61b04c6c0390..2ff4b9519139 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
@@ -40,10 +40,10 @@ static int rmnet_unregister_real_device(struct net_device *real_dev)
 	if (port->nr_rmnet_devs)
 		return -EINVAL;
 
-	rmnet_map_tx_aggregate_exit(port);
-
 	netdev_rx_handler_unregister(real_dev);
 
+	rmnet_map_tx_aggregate_exit(port);
+
 	kfree(port);
 
 	netdev_dbg(real_dev, "Removed from rmnet\n");
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net 5/6] net: qualcomm: rmnet: account linearization failures on the real device
  2026-11-26 16:32 [PATCH net 0/6] net: qualcomm: rmnet: fix TX aggregation and teardown bugs Antonio Quartulli
                   ` (3 preceding siblings ...)
  2026-11-26 16:32 ` [PATCH net 4/6] net: qualcomm: rmnet: stop TX aggregation after detaching the port Antonio Quartulli
@ 2026-11-26 16:32 ` Antonio Quartulli
  2026-11-26 16:32 ` [PATCH net 6/6] net: qualcomm: rmnet: unlink the bridge from the vnd it is attached to Antonio Quartulli
  5 siblings, 0 replies; 7+ messages in thread
From: Antonio Quartulli @ 2026-11-26 16:32 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Taehee Yoo, koen.vandeputte, Antonio Quartulli

When the real device lacks NETIF_F_FRAGLIST and linearizing an
aggregate fails, rmnet_send_skb() counts the drop on port->rmnet_dev.
That is the vnd created last on the port, never updated when it is
deleted, so it may point to a freed net_device.

The aggregate head is sized for tx-aggr-max-bytes, so linearizing only
allocates when that limit grows while an aggregate is pending.
Reproducer:

  ip link add v0 mtu 16000 type veth peer name v1 mtu 16000
  ethtool -K v0 tx-scatter-gather-fraglist off
  ip link add link v0 name rmnet1 type rmnet mux_id 1
  ip link add link v0 name rmnet2 type rmnet mux_id 2
  ethtool -C rmnet1 tx-aggr-max-frames 64 tx-aggr-time-usecs 2000
  ip link del rmnet2

then flood UDP through rmnet1 with failslab on the senders (task-filter,
probability 10) while switching tx-aggr-max-bytes between 512 and
12288. KASAN reports a use-after-free in rmnet_send_skb().

Count the drop on the real device, where it happens: the aggregate may
hold packets from any vnd.

Fixes: 64b5d1f8f2d1 ("net: qualcomm: rmnet: add tx packets aggregation")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index b156e864535f..3de093198474 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -543,10 +543,7 @@ static void rmnet_send_skb(struct rmnet_port *port, struct sk_buff *skb)
 {
 	if (skb_needs_linearize(skb, port->dev->features)) {
 		if (unlikely(__skb_linearize(skb))) {
-			struct rmnet_priv *priv;
-
-			priv = netdev_priv(port->rmnet_dev);
-			this_cpu_inc(priv->pcpu_stats->stats.tx_drops);
+			dev_core_stats_tx_dropped_inc(port->dev);
 			dev_kfree_skb_any(skb);
 			return;
 		}
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net 6/6] net: qualcomm: rmnet: unlink the bridge from the vnd it is attached to
  2026-11-26 16:32 [PATCH net 0/6] net: qualcomm: rmnet: fix TX aggregation and teardown bugs Antonio Quartulli
                   ` (4 preceding siblings ...)
  2026-11-26 16:32 ` [PATCH net 5/6] net: qualcomm: rmnet: account linearization failures on the real device Antonio Quartulli
@ 2026-11-26 16:32 ` Antonio Quartulli
  5 siblings, 0 replies; 7+ messages in thread
From: Antonio Quartulli @ 2026-11-26 16:32 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Taehee Yoo, koen.vandeputte, Antonio Quartulli

When the real device of a bridged port is unregistered or moved to
another netns, rmnet_unregister_bridge() unlinks the bridge device from
the real port's rmnet_dev: the vnd created last, never updated when it
is deleted. If the newest vnd was deleted before attaching the bridge to
the remaining one, the unlink reads and writes the freed net_device,
the actual bridge link is left in place and unregistering the vnd hangs
on its references.

Reproducer:

  ip link add v0 type veth peer name v1
  ip link add v2 type veth peer name v3
  ip link set v0 up; ip link set v2 up
  ip link add link v0 name rmnet1 type rmnet mux_id 1
  ip link add link v0 name rmnet2 type rmnet mux_id 2
  ip link del rmnet2
  ip link set v2 master rmnet1
  ip link del v0

Take the vnd from the bridge device's port, which records the one it is
attached to.

Fixes: d939b6d30bea ("net: rmnet: fix bridge mode bugs")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
index 2ff4b9519139..96129101e477 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
@@ -96,9 +96,9 @@ static void rmnet_unregister_bridge(struct rmnet_port *port)
 	if (port->rmnet_mode != RMNET_EPMODE_BRIDGE)
 		return;
 
-	rmnet_dev = port->rmnet_dev;
 	if (!port->nr_rmnet_devs) {
 		/* bridge device */
+		rmnet_dev = port->rmnet_dev;
 		real_dev = port->bridge_ep;
 		bridge_dev = port->dev;
 
@@ -108,6 +108,7 @@ static void rmnet_unregister_bridge(struct rmnet_port *port)
 	} else {
 		/* real device */
 		bridge_dev = port->bridge_ep;
+		rmnet_dev = rmnet_get_port_rtnl(bridge_dev)->rmnet_dev;
 
 		port->bridge_ep = NULL;
 		port->rmnet_mode = RMNET_EPMODE_VND;
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-26 16:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 16:32 [PATCH net 0/6] net: qualcomm: rmnet: fix TX aggregation and teardown bugs Antonio Quartulli
2026-11-26 16:32 ` [PATCH net 1/6] net: qualcomm: rmnet: recheck the aggregate after flushing it Antonio Quartulli
2026-11-26 16:32 ` [PATCH net 2/6] net: qualcomm: rmnet: always arm the flush timer for a new aggregate Antonio Quartulli
2026-11-26 16:32 ` [PATCH net 3/6] net: qualcomm: rmnet: fix TX aggregation timeout overflow on 32-bit Antonio Quartulli
2026-11-26 16:32 ` [PATCH net 4/6] net: qualcomm: rmnet: stop TX aggregation after detaching the port Antonio Quartulli
2026-11-26 16:32 ` [PATCH net 5/6] net: qualcomm: rmnet: account linearization failures on the real device Antonio Quartulli
2026-11-26 16:32 ` [PATCH net 6/6] net: qualcomm: rmnet: unlink the bridge from the vnd it is attached to Antonio Quartulli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox