summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2026-04-12 21:23:52 +0300
committerJakub Kicinski <kuba@kernel.org>2026-04-12 21:23:53 +0300
commit200df94709118d58f2ee3b398e63b2b03ac9b4d6 (patch)
tree02d67dde984beb008ce87dcfb9b3493a6bb688f5 /include
parent5acd07df8683371161969a7bb43f4a5b33e74870 (diff)
parentb2fb1a336383f1fb4667a9cc930c70f52ae1e20e (diff)
downloadlinux-200df94709118d58f2ee3b398e63b2b03ac9b4d6.tar.xz
Merge branch 'ynl-ethtool-netlink-fix-nla_len-overflow-for-large-string-sets'
Hangbin Liu says: ==================== ynl/ethtool/netlink: fix nla_len overflow for large string sets This series addresses a silent data corruption issue triggered when ynl retrieves string sets from NICs with a large number of statistics entries (e.g. mlx5_core with thousands of ETH_SS_STATS strings). The root cause is that struct nlattr.nla_len is a __u16 (max 65535 bytes). When a NIC exports enough statistics strings, the ETHTOOL_A_STRINGSET_STRINGS nest built by strset_fill_set() exceeds this limit. nla_nest_end() silently truncates the length on assignment, producing a corrupted netlink message. Patch 1 moves ethtool.py to selftest. Patch 2 improves the ethtool tool: rename the doit/dumpit helpers to do_set/do_get and convert do_get to use ynl.do() with an explicit device header instead of a full dump with client-side filtering. Patch 3 adds a --dbg-small-recv option to the YNL ethtool tool, matching the same option already present in cli.py, to help debug netlink message size issues Patch 4 adds a new helper nla_nest_end_safe() to check whether the nla_len is overflow and return -EMSGSIZE early if so. Patch 5 uses the new helper in ethtool to make sure the ethtool doesn't reply a corrupted netlink message. ==================== Link: https://patch.msgid.link/20260408-b4-ynl_ethtool-v2-0-7623a5e8f70b@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/net/netlink.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/net/netlink.h b/include/net/netlink.h
index 1a8356ca4b78..546d10586576 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -2265,6 +2265,25 @@ static inline int nla_nest_end(struct sk_buff *skb, struct nlattr *start)
}
/**
+ * nla_nest_end_safe - Validate and finalize nesting of attributes
+ * @skb: socket buffer the attributes are stored in
+ * @start: container attribute
+ *
+ * Corrects the container attribute header to include all appended
+ * attributes.
+ *
+ * Returns: the total data length of the skb, or -EMSGSIZE if the
+ * nested attribute length exceeds U16_MAX.
+ */
+static inline int nla_nest_end_safe(struct sk_buff *skb, struct nlattr *start)
+{
+ if (skb_tail_pointer(skb) - (unsigned char *)start > U16_MAX)
+ return -EMSGSIZE;
+
+ return nla_nest_end(skb, start);
+}
+
+/**
* nla_nest_cancel - Cancel nesting of attributes
* @skb: socket buffer the message is stored in
* @start: container attribute