* [PATCH net 0/2] airoha: fixes for sched HTB offload support
@ 2026-06-18 6:00 Lorenzo Bianconi
2026-06-18 6:00 ` [PATCH net 1/2] net: airoha: Fix off-by-one in airoha_tc_remove_htb_queue() Lorenzo Bianconi
2026-06-18 6:00 ` [PATCH net 2/2] net: airoha: fix netif_set_real_num_tx_queues for sparse QoS channels Lorenzo Bianconi
0 siblings, 2 replies; 6+ messages in thread
From: Lorenzo Bianconi @ 2026-06-18 6:00 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: Wayen Yan, linux-arm-kernel, linux-mediatek, netdev,
Lorenzo Bianconi
---
Lorenzo Bianconi (2):
net: airoha: Fix off-by-one in airoha_tc_remove_htb_queue()
net: airoha: fix netif_set_real_num_tx_queues for sparse QoS channels
drivers/net/ethernet/airoha/airoha_eth.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
---
base-commit: 7d8297e26b4e20b5d1c3c3fe51fe81a1c7fbc823
change-id: 20260618-airoha-qos-fixes-b6460b085680
Best regards,
--
Lorenzo Bianconi <lorenzo@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH net 1/2] net: airoha: Fix off-by-one in airoha_tc_remove_htb_queue() 2026-06-18 6:00 [PATCH net 0/2] airoha: fixes for sched HTB offload support Lorenzo Bianconi @ 2026-06-18 6:00 ` Lorenzo Bianconi 2026-06-19 9:34 ` Simon Horman 2026-06-18 6:00 ` [PATCH net 2/2] net: airoha: fix netif_set_real_num_tx_queues for sparse QoS channels Lorenzo Bianconi 1 sibling, 1 reply; 6+ messages in thread From: Lorenzo Bianconi @ 2026-06-18 6:00 UTC (permalink / raw) To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni Cc: Wayen Yan, linux-arm-kernel, linux-mediatek, netdev, Lorenzo Bianconi airoha_tc_htb_alloc_leaf_queue() computes the HTB QoS channel index as opt->classid % AIROHA_NUM_QOS_CHANNELS and stores it in qos_sq_bmap. However, airoha_tc_remove_htb_queue() clears the HTB configuration using queue + 1 as the channel index, causing an off-by-one error. Use queue directly as the QoS channel index to match the allocation logic. Fixes: ef1ca9271313b ("net: airoha: Add sched HTB offload support") Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> --- drivers/net/ethernet/airoha/airoha_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c index 64dde6464f3f..aa98d1823ab6 100644 --- a/drivers/net/ethernet/airoha/airoha_eth.c +++ b/drivers/net/ethernet/airoha/airoha_eth.c @@ -3006,7 +3006,7 @@ static void airoha_tc_remove_htb_queue(struct net_device *netdev, int queue) struct airoha_qdma *qdma = dev->qdma; netif_set_real_num_tx_queues(netdev, netdev->real_num_tx_queues - 1); - airoha_qdma_set_tx_rate_limit(netdev, queue + 1, 0, 0); + airoha_qdma_set_tx_rate_limit(netdev, queue, 0, 0); clear_bit(queue, qdma->qos_channel_map); clear_bit(queue, dev->qos_sq_bmap); -- 2.54.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net 1/2] net: airoha: Fix off-by-one in airoha_tc_remove_htb_queue() 2026-06-18 6:00 ` [PATCH net 1/2] net: airoha: Fix off-by-one in airoha_tc_remove_htb_queue() Lorenzo Bianconi @ 2026-06-19 9:34 ` Simon Horman 0 siblings, 0 replies; 6+ messages in thread From: Simon Horman @ 2026-06-19 9:34 UTC (permalink / raw) To: Lorenzo Bianconi Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Wayen Yan, linux-arm-kernel, linux-mediatek, netdev On Thu, Jun 18, 2026 at 08:00:29AM +0200, Lorenzo Bianconi wrote: > airoha_tc_htb_alloc_leaf_queue() computes the HTB QoS channel index > as opt->classid % AIROHA_NUM_QOS_CHANNELS and stores it in qos_sq_bmap. > However, airoha_tc_remove_htb_queue() clears the HTB configuration > using queue + 1 as the channel index, causing an off-by-one error. > Use queue directly as the QoS channel index to match the allocation > logic. > > Fixes: ef1ca9271313b ("net: airoha: Add sched HTB offload support") > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Reviewed-by: Simon Horman <horms@kernel.org> ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net 2/2] net: airoha: fix netif_set_real_num_tx_queues for sparse QoS channels 2026-06-18 6:00 [PATCH net 0/2] airoha: fixes for sched HTB offload support Lorenzo Bianconi 2026-06-18 6:00 ` [PATCH net 1/2] net: airoha: Fix off-by-one in airoha_tc_remove_htb_queue() Lorenzo Bianconi @ 2026-06-18 6:00 ` Lorenzo Bianconi 2026-06-19 9:35 ` Simon Horman 1 sibling, 1 reply; 6+ messages in thread From: Lorenzo Bianconi @ 2026-06-18 6:00 UTC (permalink / raw) To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni Cc: Wayen Yan, linux-arm-kernel, linux-mediatek, netdev, Lorenzo Bianconi airoha_tc_htb_alloc_leaf_queue() assigns queue IDs based on the channel index (opt->qid = AIROHA_NUM_TX_RING + channel), but updates real_num_tx_queues with a simple increment (num_tx_queues + 1). When QoS channels are allocated sparsely (e.g., channels 0 and 3 without 1 and 2), the returned qid can exceed real_num_tx_queues, causing out-of-bounds accesses in the networking stack. For example, allocating channel 0 then channel 3 results in real_num_tx_queues = 34 but qid = 35, which is out of range [0, 34). Fix this by computing real_num_tx_queues based on the highest active channel index rather than using a simple counter, in both the allocation and deletion paths. Fixes: ef1ca9271313b ("net: airoha: Add sched HTB offload support") Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> --- drivers/net/ethernet/airoha/airoha_eth.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c index aa98d1823ab6..e2652cff67c0 100644 --- a/drivers/net/ethernet/airoha/airoha_eth.c +++ b/drivers/net/ethernet/airoha/airoha_eth.c @@ -2789,7 +2789,7 @@ static int airoha_tc_htb_alloc_leaf_queue(struct net_device *netdev, struct tc_htb_qopt_offload *opt) { u32 channel = TC_H_MIN(opt->classid) % AIROHA_NUM_QOS_CHANNELS; - int err, num_tx_queues = netdev->real_num_tx_queues; + int err, num_tx_queues = AIROHA_NUM_TX_RING + channel + 1; struct airoha_gdm_dev *dev = netdev_priv(netdev); struct airoha_qdma *qdma = dev->qdma; @@ -2806,7 +2806,10 @@ static int airoha_tc_htb_alloc_leaf_queue(struct net_device *netdev, if (err) goto error; - err = netif_set_real_num_tx_queues(netdev, num_tx_queues + 1); + if (num_tx_queues <= netdev->real_num_tx_queues) + goto set_qos_sq_bmap; + + err = netif_set_real_num_tx_queues(netdev, num_tx_queues); if (err) { airoha_qdma_set_tx_rate_limit(netdev, channel, 0, opt->quantum); @@ -2815,6 +2818,7 @@ static int airoha_tc_htb_alloc_leaf_queue(struct net_device *netdev, goto error; } +set_qos_sq_bmap: set_bit(channel, dev->qos_sq_bmap); opt->qid = AIROHA_NUM_TX_RING + channel; @@ -3003,13 +3007,18 @@ static int airoha_dev_setup_tc_block(struct net_device *dev, static void airoha_tc_remove_htb_queue(struct net_device *netdev, int queue) { struct airoha_gdm_dev *dev = netdev_priv(netdev); + int num_tx_queues = AIROHA_NUM_TX_RING; struct airoha_qdma *qdma = dev->qdma; - netif_set_real_num_tx_queues(netdev, netdev->real_num_tx_queues - 1); airoha_qdma_set_tx_rate_limit(netdev, queue, 0, 0); clear_bit(queue, qdma->qos_channel_map); clear_bit(queue, dev->qos_sq_bmap); + + if (!bitmap_empty(dev->qos_sq_bmap, AIROHA_NUM_QOS_CHANNELS)) + num_tx_queues += find_last_bit(dev->qos_sq_bmap, + AIROHA_NUM_QOS_CHANNELS) + 1; + netif_set_real_num_tx_queues(netdev, num_tx_queues); } static int airoha_tc_htb_delete_leaf_queue(struct net_device *netdev, -- 2.54.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net 2/2] net: airoha: fix netif_set_real_num_tx_queues for sparse QoS channels 2026-06-18 6:00 ` [PATCH net 2/2] net: airoha: fix netif_set_real_num_tx_queues for sparse QoS channels Lorenzo Bianconi @ 2026-06-19 9:35 ` Simon Horman 2026-06-19 11:34 ` Lorenzo Bianconi 0 siblings, 1 reply; 6+ messages in thread From: Simon Horman @ 2026-06-19 9:35 UTC (permalink / raw) To: Lorenzo Bianconi Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Wayen Yan, linux-arm-kernel, linux-mediatek, netdev On Thu, Jun 18, 2026 at 08:00:30AM +0200, Lorenzo Bianconi wrote: > airoha_tc_htb_alloc_leaf_queue() assigns queue IDs based on the channel > index (opt->qid = AIROHA_NUM_TX_RING + channel), but updates > real_num_tx_queues with a simple increment (num_tx_queues + 1). When QoS > channels are allocated sparsely (e.g., channels 0 and 3 without 1 and > 2), the returned qid can exceed real_num_tx_queues, causing out-of-bounds > accesses in the networking stack. > For example, allocating channel 0 then channel 3 results in > real_num_tx_queues = 34 but qid = 35, which is out of range [0, 34). > Fix this by computing real_num_tx_queues based on the highest active > channel index rather than using a simple counter, in both the allocation > and deletion paths. > > Fixes: ef1ca9271313b ("net: airoha: Add sched HTB offload support") > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> > --- > drivers/net/ethernet/airoha/airoha_eth.c | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c ... > @@ -2806,7 +2806,10 @@ static int airoha_tc_htb_alloc_leaf_queue(struct net_device *netdev, > if (err) > goto error; > > - err = netif_set_real_num_tx_queues(netdev, num_tx_queues + 1); > + if (num_tx_queues <= netdev->real_num_tx_queues) > + goto set_qos_sq_bmap; > + > + err = netif_set_real_num_tx_queues(netdev, num_tx_queues); > if (err) { > airoha_qdma_set_tx_rate_limit(netdev, channel, 0, > opt->quantum); > @@ -2815,6 +2818,7 @@ static int airoha_tc_htb_alloc_leaf_queue(struct net_device *netdev, > goto error; > } > > +set_qos_sq_bmap: I would prefer if this could be achieved without a goto. > set_bit(channel, dev->qos_sq_bmap); > opt->qid = AIROHA_NUM_TX_RING + channel; > ... ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net 2/2] net: airoha: fix netif_set_real_num_tx_queues for sparse QoS channels 2026-06-19 9:35 ` Simon Horman @ 2026-06-19 11:34 ` Lorenzo Bianconi 0 siblings, 0 replies; 6+ messages in thread From: Lorenzo Bianconi @ 2026-06-19 11:34 UTC (permalink / raw) To: Simon Horman Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Wayen Yan, linux-arm-kernel, linux-mediatek, netdev [-- Attachment #1: Type: text/plain, Size: 2052 bytes --] > On Thu, Jun 18, 2026 at 08:00:30AM +0200, Lorenzo Bianconi wrote: > > airoha_tc_htb_alloc_leaf_queue() assigns queue IDs based on the channel > > index (opt->qid = AIROHA_NUM_TX_RING + channel), but updates > > real_num_tx_queues with a simple increment (num_tx_queues + 1). When QoS > > channels are allocated sparsely (e.g., channels 0 and 3 without 1 and > > 2), the returned qid can exceed real_num_tx_queues, causing out-of-bounds > > accesses in the networking stack. > > For example, allocating channel 0 then channel 3 results in > > real_num_tx_queues = 34 but qid = 35, which is out of range [0, 34). > > Fix this by computing real_num_tx_queues based on the highest active > > channel index rather than using a simple counter, in both the allocation > > and deletion paths. > > > > Fixes: ef1ca9271313b ("net: airoha: Add sched HTB offload support") > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> > > --- > > drivers/net/ethernet/airoha/airoha_eth.c | 15 ++++++++++++--- > > 1 file changed, 12 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c > > ... > > > @@ -2806,7 +2806,10 @@ static int airoha_tc_htb_alloc_leaf_queue(struct net_device *netdev, > > if (err) > > goto error; > > > > - err = netif_set_real_num_tx_queues(netdev, num_tx_queues + 1); > > + if (num_tx_queues <= netdev->real_num_tx_queues) > > + goto set_qos_sq_bmap; > > + > > + err = netif_set_real_num_tx_queues(netdev, num_tx_queues); > > if (err) { > > airoha_qdma_set_tx_rate_limit(netdev, channel, 0, > > opt->quantum); > > @@ -2815,6 +2818,7 @@ static int airoha_tc_htb_alloc_leaf_queue(struct net_device *netdev, > > goto error; > > } > > > > +set_qos_sq_bmap: > > I would prefer if this could be achieved without a goto. ack, I will fix it in v2. Regards, Lorenzo > > > set_bit(channel, dev->qos_sq_bmap); > > opt->qid = AIROHA_NUM_TX_RING + channel; > > > > ... [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-19 11:34 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-06-18 6:00 [PATCH net 0/2] airoha: fixes for sched HTB offload support Lorenzo Bianconi 2026-06-18 6:00 ` [PATCH net 1/2] net: airoha: Fix off-by-one in airoha_tc_remove_htb_queue() Lorenzo Bianconi 2026-06-19 9:34 ` Simon Horman 2026-06-18 6:00 ` [PATCH net 2/2] net: airoha: fix netif_set_real_num_tx_queues for sparse QoS channels Lorenzo Bianconi 2026-06-19 9:35 ` Simon Horman 2026-06-19 11:34 ` Lorenzo Bianconi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox