]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ethtool: strset: check nla_len overflow
authorHangbin Liu <liuhangbin@gmail.com>
Wed, 8 Apr 2026 07:08:53 +0000 (15:08 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sun, 12 Apr 2026 18:23:50 +0000 (11:23 -0700)
The netlink attribute length field nla_len is a __u16, which can only
represent values up to 65535 bytes. NICs with a large number of
statistics strings (e.g. mlx5_core with thousands of ETH_SS_STATS
entries) can produce a ETHTOOL_A_STRINGSET_STRINGS nest that exceeds
this limit.

When nla_nest_end() writes the actual nest size back to nla_len, the
value is silently truncated. This results in a corrupted netlink message
being sent to userspace: the parser reads a wrong (truncated) attribute
length and misaligns all subsequent attribute boundaries, causing decode
errors.

Fix this by using the new helper nla_nest_end_safe and error out if
the size exceeds U16_MAX.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Link: https://patch.msgid.link/20260408-b4-ynl_ethtool-v2-5-7623a5e8f70b@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ethtool/strset.c

index 9271aba8255edf990b866e146a9ac5e43c33c51f..bb1e829ba099b496929a75bba9a231142198c665 100644 (file)
@@ -443,7 +443,8 @@ static int strset_fill_set(struct sk_buff *skb,
                        if (strset_fill_string(skb, set_info, i) < 0)
                                goto nla_put_failure;
                }
-               nla_nest_end(skb, strings_attr);
+               if (nla_nest_end_safe(skb, strings_attr) < 0)
+                       goto nla_put_failure;
        }
 
        nla_nest_end(skb, stringset_attr);