[PATCH net-next v2 9/9] devlink: validate the port index in the rate set request
From: Jakub Kicinski <kuba@kernel.org>
Date: 2026-09-15 16:13:54
Subsystem:
devlink, networking [general], the rest, yaml netlink (ynl) · Maintainers:
Jiri Pirko, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds, Donald Hunter
port-index is the only way rate-set can address a leaf (port) rate object, but it was never listed in the request, so the generated policy has no entry for it. The op declares .maxattr = DEVLINK_ATTR_PARENT_DEV, so the attribute still reaches info->attrs[], validated against a zeroed slot - NLA_UNSPEC, length 0 - which GENL_DONT_VALIDATE_STRICT accepts at any length. devlink_port_get_from_attrs() then runs nla_get_u32() on it. Handed a zero-length port-index the kernel reads the four bytes past the payload, which are the next attribute's header, and acts on the port index those spell out. Since we're reading a linear skb the OOB read is still within the same memory allocation, it's just garbage. We also do not echo the garbage back to the user so it's not an info leak either. Hence not treating this is a real bug fix. rate-new is left alone on purpose. It creates rate nodes, resolved by name through devlink_rate_node_get_from_attrs(), and never looks at port-index. Signed-off-by: Jakub Kicinski <kuba@kernel.org> --- v2: new patch --- Documentation/netlink/specs/devlink.yaml | 1 + net/devlink/netlink_gen.c | 1 + 2 files changed, 2 insertions(+)
diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml
index 4fb64e71063d..1de0daa0f921 100644
--- a/Documentation/netlink/specs/devlink.yaml
+++ b/Documentation/netlink/specs/devlink.yaml@@ -2447,6 +2447,7 @@ doc: Partial family for Devlink. - bus-name - dev-name - index + - port-index - rate-node-name - rate-tx-share - rate-tx-max
diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c
index 43ef6864d462..9e1b4c081a7b 100644
--- a/net/devlink/netlink_gen.c
+++ b/net/devlink/netlink_gen.c@@ -618,6 +618,7 @@ static const struct nla_policy devlink_rate_set_nl_policy[DEVLINK_ATTR_PARENT_DE [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_INDEX] = NLA_POLICY_FULL_RANGE(NLA_UINT, &devlink_attr_index_range), + [DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32, }, [DEVLINK_ATTR_RATE_NODE_NAME] = { .type = NLA_NUL_STRING, }, [DEVLINK_ATTR_RATE_TX_SHARE] = { .type = NLA_U64, }, [DEVLINK_ATTR_RATE_TX_MAX] = { .type = NLA_U64, },
--
2.55.0