From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD726165F16 for ; Wed, 6 May 2026 23:38:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778110709; cv=none; b=BPspIQh1SaeQ5UpnO+wHA7GSf+aPL4DbJUzQry2SkRK2UbvzcN+RPL+gWwdprceGcIf/LYuXPyehYVOXWPDIBm902ghUdUaQK723p+9vifV52barB3LkZu6rY3LhJhK9y7KYS81SyBxHQLDO4fa40VToPVslyhQr4O26xw5IJHI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778110709; c=relaxed/simple; bh=OGeVY8CJ5Bv/jYDhk7jrcFCuOc+3AvMlB/RvGmxAHD8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=RZ12m1mlf/IBTbEDaF/m7YwJDyLM5iCd/H90HuT9pNdkyI5dvYqHivYfjAQ/5XJhVJM87io6tD43vsygd+IOeRFD0grp48azfJ84EiKptd83m/T+/NSPeoEnp/Ia0Z8CL4cOOZbKKeQJOkZSTsa6Eiq91UCFkCzYJ+cOKSdo7Yo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CsCCk5ON; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CsCCk5ON" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-43d734223e4so128326f8f.0 for ; Wed, 06 May 2026 16:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778110706; x=1778715506; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Hi27xuT2qEFLgbH9MIgPb6PwKVxA2NXtK/AwQ2Ynx0Y=; b=CsCCk5ONnYBSf4QudVMvrR7vv3k/GHkE//D99y+znygQD58+a77KKQi49PhUdsZAaZ lA5NfIqR9a1HmKITFmn37oenlAGiubmkhltnYyZQrHz+947NPd8btnY34vJTn1qrz3Iz xGUb8SLaOtQoUnpWMifgU13Ly49nfemwKKopLYGs9JIw4lOHIPcqnin9rLvcA1/DxTAh iCWl9hx9nnWPvif4pcA47ab1jl+DKjJWCw0H5Pq/6kV2TKyu7od7qc0J4rGw7sX5krBh MgWGDesJ5KFg+yNZfCEjljQGwVjL6Le3rsJ7pUybcJ6sDIXBxHnCiIqWgtsiGFcgTVu7 WOFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778110706; x=1778715506; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Hi27xuT2qEFLgbH9MIgPb6PwKVxA2NXtK/AwQ2Ynx0Y=; b=i6o3qaS5mV1kDV88pi1CyBB4gSRBUUAvhftB6liSd05A3cCpXAFce5y1nkT/1xHaUW mBo/are87tFnHVe0RO0ptlmC4xnFdDji9WTnL7+EBt+CPjgiz3L2whkxuWzajUpjr+iN qLYyHI68wViG8qysMsFdnoVO0iKBkLJLjJRj1+SIESvhSet82XP5v6etKW3hxVFnRo2O GQYf9dAqDhPqrH2PG9fHtk+K5KrgCdu2jSkQM5qzP5rL+oq3Mn8s/egcpdvB5HgVts4a MzJmPzpkHvnFzPlXXlcpn4oZI6xRfwdZJnboVXrtY75MIbC6k61AM8bcG8n4ukfddUkt i5cw== X-Forwarded-Encrypted: i=1; AFNElJ9GCcbMueZp0N6yI7p9V7JbpP3lSzKRimmtE517cbfpl+hQXXZDke9fazDVj5CCpJMlN8iE2gmuHc7n0SM=@vger.kernel.org X-Gm-Message-State: AOJu0YzoNmxUZ5hJAXDSx3J0ciktZmuCrscwtbiEVgzG9hvzVz7VxRDU uqM9hi+7Gxz07e0eFmfmIlrcBkQen6bYIFJa+BNl1+fb/UwGy2SMB+dH X-Gm-Gg: AeBDieuQhjvCwvrPOwlsSxF4tM7DrErGwlo/+1lpW9pL++ng78CHI7B7f9dLebq+DaW shE8Fp0ahhd6N0B3Zufc10uLCkS0jHKd2OAxHU31HoKE6u4ED26z8c3XL983kPfG2qGLojpNBru W4l+0PIonGOgClupnBITTtbXVO3ywkY2a9zOUKmPNJI86eS3tgRDgM7k5xgSw/5tLCSo9V+39Qk K+HmAPEy9oHHMdux/QtADCiQMstNuZW0wxb+6pXRaZLGQENOPwT7O1Z8m+sphtDjgviBCngWet5 E7KEOZqMJBjRIPWrASc+xXCzBre8+2P2v3pICGlhtC+woas9swa6EfKingqdZwWGd4TZcFmXos+ KsEeehZNf50CZMqjzZmtN2dLijNAq2eBCQrVxQX6lzr69Afqw0tG8411FHGpAam7OjCrBT97FjL DVvrudon0Zwh4+UU9ltbHuHkvU7F/8DJY= X-Received: by 2002:a05:6000:40df:b0:444:2db8:d07a with SMTP id ffacd0b85a97d-452e78b3cf2mr845609f8f.3.1778110705749; Wed, 06 May 2026 16:38:25 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:44::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45055f249bbsm13948970f8f.36.2026.05.06.16.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2026 16:38:25 -0700 (PDT) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: alexanderduyck@gmail.com, davem@davemloft.net, edumazet@google.com, horms@kernel.org, kees@kernel.org, kuba@kernel.org, linux-kernel@vger.kernel.org, mohsin.bashr@gmail.com, p@1g4.org, pabeni@redhat.com, jiri@resnulli.us Subject: [PATCH net V2] net: shaper: Reject reparenting of existing nodes Date: Wed, 6 May 2026 16:37:45 -0700 Message-ID: <20260506233745.111895-1-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Mohsin Bashir 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 Signed-off-by: Mohsin Bashir --- 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