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. 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 sum of the tx_bytes of rmnet1 and rmnet2 stays above that of v0 after the flush timeout, and kmemleak reports skbs allocated by skb_copy_expand() in rmnet_map_tx_aggregate(). Move the label before the skbagg_head check, and before the timestamps are taken, so that an aggregate found on retry is not aged against a stale agg_last and flushed early. Flush at most once per skb: if it still does not fit the aggregate found on retry, send it without aggregation (or drop it if it exceeds the byte limit) rather than flushing again, which could otherwise repeat for as long as other CPUs keep starting aggregates. A retried skb no longer qualifies for the sparse-traffic bypass, as an aggregate was just sent. Fixes: 64b5d1f8f2d1 ("net: qualcomm: rmnet: add tx packets aggregation") Signed-off-by: Antonio Quartulli --- drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 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 7ee2bc33433f..f02ea5d728d0 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -591,9 +591,11 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port struct timespec64 diff, last; unsigned int len = skb->len; struct sk_buff *agg_skb; + bool flushed = false; unsigned int size; spin_lock_bh(&port->agg_lock); +new_packet: memcpy(&last, &port->agg_last, sizeof(struct timespec64)); ktime_get_real_ts64(&port->agg_last); @@ -601,7 +603,6 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port /* 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; @@ -630,12 +631,20 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port diff = timespec64_sub(port->agg_last, port->agg_time); if (port->skbagg_head->len >= port->egress_agg_params.bytes || skb->len > port->egress_agg_params.bytes - port->skbagg_head->len) { + if (flushed) { + if (skb->len > port->egress_agg_params.bytes) { + spin_unlock_bh(&port->agg_lock); + return 0; + } + goto no_aggr; + } agg_skb = port->skbagg_head; reset_aggr_params(port); spin_unlock_bh(&port->agg_lock); hrtimer_cancel(&port->hrtimer); rmnet_send_skb(port, agg_skb); spin_lock_bh(&port->agg_lock); + flushed = true; goto new_packet; } -- 2.56.1