Re: [PATCH net] team: validate the length of U32 and S32 option data
From: Wenbo Sun
Date: Thu Nov 12 2026 - 02:01:17 EST
Hi Hangbin,
Thanks for the review and good catch.
On Thu, Nov 12, 2026 at 01:22:11AM +0000, Hangbin Liu wrote:
> What if the data size larger than s32/u32? Should we check it with
>
> if (nla_len(attr_data) != sizeof(s32))
>
> ?
Agreed -- checking exact length (!= sizeof(u32) for TEAM_OPTION_TYPE_U32
and != sizeof(s32) for TEAM_OPTION_TYPE_S32) is definitely cleaner and
safer.
While '<' prevents the out-of-bounds read, standard NLA_U32 and NLA_S32
attributes require an exact 4-byte payload (as tracked in nla_attr_len[]
in lib/nlattr.c). Since TEAM_ATTR_OPTION_DATA uses NLA_BINARY in
team_attr_option_nl_policy and TEAM_CMD_OPTIONS_SET skips strict
validation, checking only '<' would silently ignore trailing bytes on
oversized attributes (or read the upper 32 bits if an 8-byte integer were
sent on big-endian). Valid callers using nla_put_u32()/nla_put_s32()
always emit exact 4-byte attributes.
I will update both branches to use:
if (nla_len(attr_data) != sizeof(u32))
and
if (nla_len(attr_data) != sizeof(s32))
respectively, extend the test to cover oversized payloads as well, and
send a [PATCH net v2] after the 24-hour resend window.
Thanks,
Wenbo