The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH net V2] net: shaper: Reject reparenting of existing nodes
@ 2026-05-06 23:37 Mohsin Bashir
  2026-05-08 23:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Mohsin Bashir @ 2026-05-06 23:37 UTC (permalink / raw)
  To: netdev
  Cc: alexanderduyck, davem, edumazet, horms, kees, kuba, linux-kernel,
	mohsin.bashr, p, pabeni, jiri

From: Mohsin Bashir <hmohsin@meta.com>

When an existing node-scope shaper is moved to a different parent
via the group operation, the framework fails to update the leaves
count on both the old and new parent shapers. Only newly created
nodes (handle.id == NET_SHAPER_ID_UNSPEC) trigger the parent
leaves increment at line 1039.

This causes the parent's leaves counter to diverge from the
actual number of children in the xarray. When the node is later
deleted, pre_del_node() allocates an array sized by the stale
leaves count, but the xarray iteration finds more children than
expected, hitting the WARN_ON_ONCE guard and returning -EINVAL.

Rather than adding reparenting support with complex leaves count
bookkeeping, reject group calls that attempt to change an existing
node's parent. Updates to an existing node's rate or leaves under
the same parent remain permitted. We expect that for any modification
of the topology user should always create new groups and let the
kernel garbage collect the leaf-less nodes.

Fixes: 5d5d4700e75d ("net-shapers: implement NL group operation")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
Changelog:

V2:
- Add missing maintainer
- Nit: Remove null at the end of fixes tag
- Move reparenting check after parent resolution so updates
  that omit the parent argument are not incorrectly rejected

V1: https://lore.kernel.org/netdev/20260505174321.1794689-1-mohsin.bashr@gmail.com/
---
 net/shaper/shaper.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/net/shaper/shaper.c b/net/shaper/shaper.c
index 94bc9c7382ea..1069fa4eb9f6 100644
--- a/net/shaper/shaper.c
+++ b/net/shaper/shaper.c
@@ -964,15 +964,22 @@ static int __net_shaper_group(struct net_shaper_binding *binding,
 	int i, ret;
 
 	if (node->handle.scope == NET_SHAPER_SCOPE_NODE) {
+		struct net_shaper *cur = NULL;
+
 		new_node = node->handle.id == NET_SHAPER_ID_UNSPEC;
 
-		if (!new_node && !net_shaper_lookup(binding, &node->handle)) {
-			/* The related attribute is not available when
-			 * reaching here from the delete() op.
-			 */
-			NL_SET_ERR_MSG_FMT(extack, "Node shaper %d:%d does not exists",
-					   node->handle.scope, node->handle.id);
-			return -ENOENT;
+		if (!new_node) {
+			cur = net_shaper_lookup(binding, &node->handle);
+			if (!cur) {
+				/* The related attribute is not available
+				 * when reaching here from the delete() op.
+				 */
+				NL_SET_ERR_MSG_FMT(extack,
+						   "Node shaper %d:%d does not exist",
+						   node->handle.scope,
+						   node->handle.id);
+				return -ENOENT;
+			}
 		}
 
 		/* When unspecified, the node parent scope is inherited from
@@ -986,6 +993,15 @@ static int __net_shaper_group(struct net_shaper_binding *binding,
 				return ret;
 		}
 
+		if (cur && net_shaper_handle_cmp(&cur->parent,
+						 &node->parent)) {
+			NL_SET_ERR_MSG_FMT(extack,
+					   "Cannot reparent node shaper %d:%d",
+					   node->handle.scope,
+					   node->handle.id);
+			return -EOPNOTSUPP;
+		}
+
 	} else {
 		net_shaper_default_parent(&node->handle, &node->parent);
 	}
-- 
2.52.0


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

* Re: [PATCH net V2] net: shaper: Reject reparenting of existing nodes
  2026-05-06 23:37 [PATCH net V2] net: shaper: Reject reparenting of existing nodes Mohsin Bashir
@ 2026-05-08 23:00 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-05-08 23:00 UTC (permalink / raw)
  To: Mohsin Bashir
  Cc: netdev, alexanderduyck, davem, edumazet, horms, kees, kuba,
	linux-kernel, p, pabeni, jiri

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  6 May 2026 16:37:45 -0700 you wrote:
> From: Mohsin Bashir <hmohsin@meta.com>
> 
> When an existing node-scope shaper is moved to a different parent
> via the group operation, the framework fails to update the leaves
> count on both the old and new parent shapers. Only newly created
> nodes (handle.id == NET_SHAPER_ID_UNSPEC) trigger the parent
> leaves increment at line 1039.
> 
> [...]

Here is the summary with links:
  - [net,V2] net: shaper: Reject reparenting of existing nodes
    https://git.kernel.org/netdev/net/c/a77d5a069d95

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-05-08 23:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-06 23:37 [PATCH net V2] net: shaper: Reject reparenting of existing nodes Mohsin Bashir
2026-05-08 23:00 ` patchwork-bot+netdevbpf

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