rtnetlink: truncate IFLA_VFINFO_LIST instead of overflowing its length
Subsystems (3)
PATCH 1/1 rtnetlink: truncate IFLA_VFINFO_LIST instead of overflowing its length
rtnl_fill_vf() closes the IFLA_VFINFO_LIST nest with nla_nest_end(), which stores the accumulated length into nla_len. That field is a u16, so a nest larger than 65535 bytes is written truncated modulo 65536.
The skb is sized by if_nlmsg_size(), which adds rtnl_vfinfo_size() for every VF, so the buffer really is large enough for the whole list and none of the nla_put() calls in rtnl_fill_vfinfo() fails. The overflow is therefore silent. Userspace then walks the message with RTA_NEXT(), which advances by the stored length, so parsing resumes inside VF payload and the top-level attributes that follow the nest are read out of VF data. Those are IFLA_VF_PORTS, IFLA_XDP, IFLA_LINKINFO, IFLA_PERM_ADDRESS and IFLA_PROP_LIST. iproute2 prints "!!!Deficit", and strictly validating parsers reject the message outright.
rtnl_fill_vfinfo() emits 296 bytes per VF on a 64-bit kernel with efficient unaligned access, so the nest wraps at 222 VFs; without CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS it is 328 bytes and 200 VFs, and with ndo_get_vf_guid 336 bytes and 196 VFs. ice supports up to 256 VFs per PF (ICE_MAX_SRIOV_VFS), so this is reachable on shipping hardware. Requests that set RTEXT_FILTER_SKIP_STATS need 335 VFs, which the 256-VF limit puts out of reach, so plain "ip link show" is fine today while "ip -s link show" is not.
On CONFIG_DEBUG_NET kernels nla_nest_end() now also splats via DEBUG_NET_WARN_ON_ONCE(), added along with nla_nest_end_safe() in commit 1346586a9ac9 ("netlink: add a nla_nest_end_safe() helper").
Using nla_nest_end_safe() here would not help: a nest that does not fit in a u16 will not fit in a retried skb either, so returning -EMSGSIZE would turn "ip link show" on such a device into a hard failure. Bound the nest in the writer instead, as suggested when this was last
discussed: drop the VF that would push it past U16_MAX and end the list there. Userspace sees IFLA_NUM_VF unchanged and a shorter IFLA_VFINFO_LIST, and everything after the nest stays parsable. An empty nest is already emitted for a PF with no VFs, so a list shorter than IFLA_NUM_VF is not a new encoding.
The other large nests in rtnl_fill_ifinfo() were audited and cannot
overflow: IFLA_AF_SPEC is bounded by a handful of address families at about a kilobyte each, and IFLA_VF_PORTS would need more than 560 VFs.
--- net/core/rtnetlink.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/core/rtnetlink.c +12 -0
@@ -1687,10 +1687,22 @@ static noinline_for_stack int rtnl_fill_vf(struct sk_buff *skb,return -EMSGSIZE ;for (i =0 ; i < num_vfs; i++) { +unsigned char *mark =skb_tail_pointer (skb); +if (rtnl_fill_vfinfo (skb, dev, i, ext_filter_mask)) {nla_nest_cancel (skb, vfinfo);return -EMSGSIZE ; } + +/* An attribute length is a u16, so the nest cannot describe +* more than U16_MAX bytes. Drop the VF that would overflow it +* and stop: a truncated list keeps the rest of the message +* parsable, whereas a wrapped nest length does not. +*/ +if (skb_tail_pointer (skb) - (unsigned char *)vfinfo >U16_MAX ) { +nlmsg_trim (skb, mark); +break ; + } }nla_nest_end (skb, vfinfo);
base-commit: 248951ddc14de84de3910f9b13f51491a8cd91df
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerQuoted 14 lines · On Sat, 25 Jul 2026 16:22:36 +0300 Artem Lytkin wrote:
rtnl_fill_vf()closes theIFLA_VFINFO_LISTnest withnla_nest_end(), which stores the accumulated length intonla_len. That field is a u16, so a nest larger than 65535 bytes is written truncated modulo 65536.The skb is sized by
if_nlmsg_size(), which addsrtnl_vfinfo_size()for every VF, so the buffer really is large enough for the whole list and none of thenla_put()calls inrtnl_fill_vfinfo()fails. The overflow is therefore silent. Userspace then walks the message withRTA_NEXT(), which advances by the stored length, so parsing resumes inside VF payload and the top-level attributes that follow the nest are read out of VF data. Those areIFLA_VF_PORTS,IFLA_XDP,IFLA_LINKINFO,IFLA_PERM_ADDRESSandIFLA_PROP_LIST. iproute2 prints "!!!Deficit", and strictly validating parsers reject the message outright.
Quoted 8 lines
rtnl_fill_vfinfo()emits 296 bytes per VF on a 64-bit kernel with efficient unaligned access, so the nest wraps at 222 VFs; withoutCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSit is 328 bytes and 200 VFs, and withndo_get_vf_guid336 bytes and 196 VFs. ice supports up to 256 VFs per PF (ICE_MAX_SRIOV_VFS), so this is reachable on shipping hardware. Requests that setRTEXT_FILTER_SKIP_STATSneed 335 VFs, which the 256-VF limit puts out of reach, so plain "ip link show" is fine today while "ip -s link show" is not.
We should cap the output at known values and document them as the max the interface supports. "The number depends on attr set and random things like CPU alignment requirements" sounds like a terrible uAPI contract.
Perhaps 128 with stats and 256 without?
Quoted 14 lines
On
CONFIG_DEBUG_NETkernelsnla_nest_end()now also splats viaDEBUG_NET_WARN_ON_ONCE(), added along withnla_nest_end_safe()in commit1346586a9ac9("netlink: add anla_nest_end_safe()helper").Using
nla_nest_end_safe()here would not help: a nest that does not fit in a u16 will not fit in a retried skb either, so returning-EMSGSIZEwould turn "ip link show" on such a device into a hard failure. Bound the nest in the writer instead, as suggested when this was last
discussed: drop the VF that would push it pastU16_MAXand end the list there. Userspace seesIFLA_NUM_VFunchanged and a shorterIFLA_VFINFO_LIST, and everything after the nest stays parsable. An empty nest is already emitted for a PF with no VFs, so a list shorter thanIFLA_NUM_VFis not a new encoding.
Quoted 5 lines
The other large nests in
rtnl_fill_ifinfo()were audited and cannot
overflow:IFLA_AF_SPECis bounded by a handful of address families at about a kilobyte each, andIFLA_VF_PORTSwould need more than 560 VFs.Fixes c02db8c6290b ("rtnetlink: make SR-IOV VF interface symmetric")
Not a fix - this is along standing limitation of the interface.
Signature · 1 line
pw-bot: cr
PATCH v2 1/1 rtnetlink: cap IFLA_VFINFO_LIST at a documented number of VFs
rtnl_fill_vf() emits one IFLA_VF_INFO per VF into the IFLA_VFINFO_LIST nest and closes it with nla_nest_end(), which stores the accumulated length into nla_len. That field is a u16, so a nest larger than 65535 bytes is written truncated modulo 65536.
Nothing catches it on the way. if_nlmsg_size() adds rtnl_vfinfo_size() for every VF, so the skb really is large enough and none of the nla_put() calls fails. Userspace then walks the message with RTA_NEXT(), which advances by the stored length, so parsing resumes inside VF payload and the attributes after the nest are read out of VF data: IFLA_VF_PORTS, IFLA_XDP, IFLA_LINKINFO, IFLA_PERM_ADDRESS, IFLA_AF_SPEC. iproute2 prints "!!!Deficit" and strictly validating parsers reject the message. On CONFIG_DEBUG_NET kernels nla_nest_end() also splats, via the DEBUG_NET_WARN_ON_ONCE() added in commit 1346586a9ac9 ("netlink: add a nla_nest_end_safe() helper").
Where the wrap falls depends on what was asked for and on the host. A VF costs 196 bytes, 296 with statistics, 236 with GUIDs and 336 with both. On a kernel without CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS the statistics carry a padding attribute each and cost 32 bytes more, which makes those two 328 and 368. So the nest overflows somewhere between 179 and 335 VFs. ice allows 256 VFs per PF
(ICE_MAX_SRIOV_VFS), which reaches it. Statistics are included unless the request sets RTEXT_FILTER_SKIP_STATS, so the common case is the one that wraps first.
A limit that moves with the requested attribute set and with the host's alignment requirements is not something userspace can be told, so use fixed numbers instead and document them as what the interface supports:
256 VFs, or 128 when statistics are included. Both stay well inside U16_MAX even in the largest per-VF encoding, at 60416 and 47104 bytes respectively. rtnl_vfinfo_size() applies the same limit so that the skb is not sized for VFs that will not be emitted.
A device with more VFs than the limit reports a shorter IFLA_VFINFO_LIST. IFLA_NUM_VF keeps carrying the real count, and everything after the nest stays parsable, which is the part that is broken today. An empty nest is already emitted for a PF with no VFs, so a list shorter than IFLA_NUM_VF is not a new encoding.
Returning -EMSGSIZE instead, which is what nla_nest_end_safe() would give, is not an option here: a nest that does not fit in a u16 will not fit in a retried skb either, so it would turn a link dump on such a device into a hard failure.
The other large nests in rtnl_fill_ifinfo() were audited and cannot overflow. IFLA_AF_SPEC is bounded by a handful of address families at about a kilobyte each, and IFLA_VF_PORTS would need more than 560 VFs, which no in-tree driver allows.
---
v2:
- cap at fixed limits, 256 VFs and 128 when statistics are included, and document them in the netlink spec, rather than dropping whichever VF happens not to fit (Jakub)
- drop the Fixes: tag, this is a long standing limitation of the interface and not a regression (Jakub)
- retarget net-next for the same reason
- changelog: corrected the per-VF sizes, which mixed two configurations, and dropped IFLA_PROP_LIST from the list of attributes that follow the nest, since it is emitted before it
v1: https://lore.kernel.org/netdev/[email protected]/
Documentation/netlink/specs/rt-link.yaml | 5 +++++ net/core/rtnetlink.c | 25 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-)
Documentation/netlink/specs/rt-link.yaml +5 -0
@@ -928,6 +928,11 @@ attribute-sets: name: vfinfo-list type: nest nested-attributes: vfinfo-list-attrs + doc: | + Per-VF details. The list holds at most 256 VFs, or 128 when + statistics are included, because it is one attribute and has to fit + in a u16 length. A device with more VFs than that reports a + truncated list; num-vf still carries the real count. - name: stats64 type: binary
net/core/rtnetlink.c +24 -1
@@ -1174,12 +1174,30 @@ static void copy_rtnl_link_stats(struct rtnl_link_stats *a, a->rx_nohandler = b->rx_nohandler; } +/* IFLA_VFINFO_LIST is one netlink attribute, so everything nested inside it +* has to fit in the u16 nla_len. Bound the number of VFs described there at a +* fixed value rather than at whatever happens to fit, so that the limit is a +* property of the interface instead of one of the requested attribute set and +* the host's alignment requirements. The largest per-VF encoding is 368 bytes +* with statistics and GUIDs and 236 bytes without statistics, so both limits +* keep the nest well inside U16_MAX. +*/ +#define RTNL_VFINFO_MAX_VFS 256 +#define RTNL_VFINFO_MAX_VFS_STATS 128 + +static int rtnl_vfinfo_max_vfs (u32 ext_filter_mask) +{ +return ext_filter_mask &RTEXT_FILTER_SKIP_STATS ? +RTNL_VFINFO_MAX_VFS :RTNL_VFINFO_MAX_VFS_STATS ; +} +/* All VF info */ static inline int rtnl_vfinfo_size (const struct net_device *dev,u32 ext_filter_mask) {if (dev->dev.parent && (ext_filter_mask &RTEXT_FILTER_VF )) { -int num_vfs =dev_num_vf (dev->dev.parent); +int num_vfs =min (dev_num_vf (dev->dev.parent), +rtnl_vfinfo_max_vfs (ext_filter_mask));size_t size =nla_total_size (0 ); size += num_vfs * (nla_total_size(0) +
@@ -1717,6 +1735,11 @@ static noinline_for_stack int rtnl_fill_vf(struct sk_buff *skb,if (!vfinfo)return -EMSGSIZE ; +/* IFLA_NUM_VF above stays the device's VF count; the list itself is +* capped so that its length cannot overflow nla_len. +*/ + num_vfs =min (num_vfs,rtnl_vfinfo_max_vfs (ext_filter_mask)); +for (i =0 ; i < num_vfs; i++) {if (rtnl_fill_vfinfo (skb, dev, i, ext_filter_mask)) {nla_nest_cancel (skb, vfinfo);
base-commit: bc03e080390a1b8dd6252b598aa5ec801fc5e13d
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v2] rtnetlink: cap IFLA_VFINFO_LIST at a documented number of VFs
Quoted 95 lines · On Thu, 30 Jul 2026 12:07:00 +0300 Artem Lytkin wrote:
rtnl_fill_vf()emits oneIFLA_VF_INFOper VF into theIFLA_VFINFO_LISTnest and closes it withnla_nest_end(), which stores the accumulated length intonla_len. That field is a u16, so a nest larger than 65535 bytes is written truncated modulo 65536.Nothing catches it on the way.
if_nlmsg_size()addsrtnl_vfinfo_size()for every VF, so the skb really is large enough and none of thenla_put()calls fails. Userspace then walks the message withRTA_NEXT(), which advances by the stored length, so parsing resumes inside VF payload and the attributes after the nest are read out of VF data:IFLA_VF_PORTS,IFLA_XDP,IFLA_LINKINFO,IFLA_PERM_ADDRESS,IFLA_AF_SPEC. iproute2 prints "!!!Deficit" and strictly validating parsers reject the message. OnCONFIG_DEBUG_NETkernelsnla_nest_end()also splats, via theDEBUG_NET_WARN_ON_ONCE()added in commit1346586a9ac9("netlink: add anla_nest_end_safe()helper").Where the wrap falls depends on what was asked for and on the host. A VF costs 196 bytes, 296 with statistics, 236 with GUIDs and 336 with both. On a kernel without
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSthe statistics carry a padding attribute each and cost 32 bytes more, which makes those two 328 and 368. So the nest overflows somewhere between 179 and 335 VFs. ice allows 256 VFs per PF
(ICE_MAX_SRIOV_VFS), which reaches it. Statistics are included unless the request setsRTEXT_FILTER_SKIP_STATS, so the common case is the one that wraps first.A limit that moves with the requested attribute set and with the host's alignment requirements is not something userspace can be told, so use fixed numbers instead and document them as what the interface supports:
256 VFs, or 128 when statistics are included. Both stay well insideU16_MAXeven in the largest per-VF encoding, at 60416 and 47104 bytes respectively.rtnl_vfinfo_size()applies the same limit so that the skb is not sized for VFs that will not be emitted.A device with more VFs than the limit reports a shorter
IFLA_VFINFO_LIST.IFLA_NUM_VFkeeps carrying the real count, and everything after the nest stays parsable, which is the part that is broken today. An empty nest is already emitted for a PF with no VFs, so a list shorter thanIFLA_NUM_VFis not a new encoding.Returning
-EMSGSIZEinstead, which is whatnla_nest_end_safe()would give, is not an option here: a nest that does not fit in a u16 will not fit in a retried skb either, so it would turn a link dump on such a device into a hard failure.The other large nests in
rtnl_fill_ifinfo()were audited and cannot overflow.IFLA_AF_SPECis bounded by a handful of address families at about a kilobyte each, andIFLA_VF_PORTSwould need more than 560 VFs, which no in-tree driver allows.Reported-by Jacob Keller <[email protected]>Assisted-by Claude:claude-fable-5Signed-off-by Artem Lytkin <[email protected]>---
v2:
- cap at fixed limits, 256 VFs and 128 when statistics are included, and document them in the netlink spec, rather than dropping whichever VF happens not to fit (Jakub)
- drop the Fixes: tag, this is a long standing limitation of the interface and not a regression (Jakub)
- retarget net-next for the same reason
- changelog: corrected the per-VF sizes, which mixed two configurations, and droppedIFLA_PROP_LISTfrom the list of attributes that follow the nest, since it is emitted before it
v1: https://lore.kernel.org/netdev/[email protected]/Documentation/netlink/specs/rt-link.yaml | 5 +++++ net/core/rtnetlink.c | 25 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-)Documentation/netlink/specs/rt-link.yaml +5
-0@@ -928,6 +928,11 @@ attribute-sets: name: vfinfo-list type: nest nested-attributes: vfinfo-list-attrs + doc: | + Per-VF details. The list holds at most 256 VFs, or 128 when + statistics are included, because it is one attribute and has to fit + in a u16 length. A device with more VFs than that reports a + truncated list; num-vf still carries the real count. - name: stats64 type: binarynet/core/rtnetlink.c +0
-0@@ -1174,12 +1174,30 @@ static void copy_rtnl_link_stats(struct rtnl_link_stats *a, a->rx_nohandler = b->rx_nohandler; }
net/core/rtnetlink.c static void copy_rtnl_link_stats(struct rtnl_link_stats *a, · line 1186
Quoted 10 lines
net/core/rtnetlink.c +10
-0+/* IFLA_VFINFO_LIST is one netlink attribute, so everything nested inside it +* has to fit in the u16 nla_len. Bound the number of VFs described there at a +* fixed value rather than at whatever happens to fit, so that the limit is a +* property of the interface instead of one of the requested attribute set and +* the host's alignment requirements. The largest per-VF encoding is 368 bytes +* with statistics and GUIDs and 236 bytes without statistics, so both limits +* keep the nest well inside U16_MAX. +*/ +#define RTNL_VFINFO_MAX_VFS 256 +#define RTNL_VFINFO_MAX_VFS_STATS 128
No strong opinion which to choose but I'd either move these defines somewhere visible or just use the literal values. There's a common fallacy that all literals must have defines, IMO if the literal is only used once, by a small well scoped helper (here rtnl_vfinfo_max_vfs()) there's no ambiguity. The define is an extra indirection obfuscating the code.
If you don't care either way either - I'd do the literal thing, and let the comment describe the helper
net/core/rtnetlink.c static void copy_rtnl_link_stats(struct rtnl_link_stats *a, · line 1188
Quoted 1 line
net/core/rtnetlink.c +1
-0+static int rtnl_vfinfo_max_vfs (u32 ext_filter_mask)
if you pass the "real" num_vfs in here you can also subsume the min() into the helper. Perhaps the helper should then be renamed s/_max/_cap/
net/core/rtnetlink.c static void copy_rtnl_link_stats(struct rtnl_link_stats *a, · line 1192
Quoted 4 lines
net/core/rtnetlink.c +4
-0+{ +return ext_filter_mask &RTEXT_FILTER_SKIP_STATS ? +RTNL_VFINFO_MAX_VFS :RTNL_VFINFO_MAX_VFS_STATS ; +}
Other than that LGTM. Please send v3 as a new thread, not in reply to.
And FWIW (sorry, Im going to reply here to avoid splintering) I maintain that net-next is better :) We are capping, who knows is someone complains. So I _don't_ want this in LTS.
Re: [PATCH net-next v2] rtnetlink: cap IFLA_VFINFO_LIST at a documented number of VFs
Quoted 4 lines · Jakub Kicinski
And FWIW (sorry, Im going to reply here to avoid splintering) I maintain that net-next is better :) We are capping, who knows is someone complains. So I _don't_ want this in LTS.
Fair enough, no objections here. I'd appreciate something in the commit message mentioning the commit this originated in, since that may still be helpful to future readers for context, but I won't hold an objection regardless of what ends up in v3.
Thanks,
Jake
Quoted 24 lines · Jakub Kicinski
Quoted 14 lines · On Sat, 25 Jul 2026 16:22:36 +0300 Artem Lytkin wrote:
rtnl_fill_vf()closes theIFLA_VFINFO_LISTnest withnla_nest_end(), which stores the accumulated length intonla_len. That field is a u16, so a nest larger than 65535 bytes is written truncated modulo 65536.The skb is sized by
if_nlmsg_size(), which addsrtnl_vfinfo_size()for every VF, so the buffer really is large enough for the whole list and none of thenla_put()calls inrtnl_fill_vfinfo()fails. The overflow is therefore silent. Userspace then walks the message withRTA_NEXT(), which advances by the stored length, so parsing resumes inside VF payload and the top-level attributes that follow the nest are read out of VF data. Those areIFLA_VF_PORTS,IFLA_XDP,IFLA_LINKINFO,IFLA_PERM_ADDRESSandIFLA_PROP_LIST. iproute2 prints "!!!Deficit", and strictly validating parsers reject the message outright.Quoted 8 lines
rtnl_fill_vfinfo()emits 296 bytes per VF on a 64-bit kernel with efficient unaligned access, so the nest wraps at 222 VFs; withoutCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESSit is 328 bytes and 200 VFs, and withndo_get_vf_guid336 bytes and 196 VFs. ice supports up to 256 VFs per PF (ICE_MAX_SRIOV_VFS), so this is reachable on shipping hardware. Requests that setRTEXT_FILTER_SKIP_STATSneed 335 VFs, which the 256-VF limit puts out of reach, so plain "ip link show" is fine today while "ip -s link show" is not.
Quoted 7 lines
We should cap the output at known values and document them as the max the interface supports. "The number depends on attr set and random things like CPU alignment requirements" sounds like a terrible uAPI contract.
Perhaps 128 with stats and 256 without?
This seems reasonable to me.
Quoted 14 lines
Quoted 14 lines
On
CONFIG_DEBUG_NETkernelsnla_nest_end()now also splats viaDEBUG_NET_WARN_ON_ONCE(), added along withnla_nest_end_safe()in commit1346586a9ac9("netlink: add anla_nest_end_safe()helper").Using
nla_nest_end_safe()here would not help: a nest that does not fit in a u16 will not fit in a retried skb either, so returning-EMSGSIZEwould turn "ip link show" on such a device into a hard failure. Bound the nest in the writer instead, as suggested when this was last
discussed: drop the VF that would push it pastU16_MAXand end the list there. Userspace seesIFLA_NUM_VFunchanged and a shorterIFLA_VFINFO_LIST, and everything after the nest stays parsable. An empty nest is already emitted for a PF with no VFs, so a list shorter thanIFLA_NUM_VFis not a new encoding.
Quoted 7 lines
Quoted 5 lines
The other large nests in
rtnl_fill_ifinfo()were audited and cannot
overflow:IFLA_AF_SPECis bounded by a handful of address families at about a kilobyte each, andIFLA_VF_PORTSwould need more than 560 VFs.Fixes c02db8c6290b ("rtnetlink: make SR-IOV VF interface symmetric")Not a fix - this is along standing limitation of the interface.
I'd argue this is a "fix", as we were previously doing objectively the wrong thing by randomly truncating the message at arbitrary points.
That being said, this *is* a well known limitation of the interface that has been around for a while, so I can accept the argument not to tag it as a fix for net.
Quoted 2 lines · Jacob Keller
I'd argue this is a "fix", as we were previously doing objectively the wrong thing by randomly truncating the message at arbitrary points.
Our mails crossed. v2 went out ten minutes before yours, taking Jakub's 128 and 256, documenting them in the netlink spec and dropping the tag:
https://lore.kernel.org/netdev/[email protected]/
I have no strong view on who is right, but the tag decides more than bookkeeping here. With it this goes to net and gets backported, so an ice PF with 256 VFs stops producing a corrupt link dump on a stable kernel; without it that waits for the merge window. Against that, nothing
regressed: the interface has been able to write a length it cannot represent since 2010, which I take to be Jakub's point.
Happy to restore the tag and resend against net if Jakub is persuaded.
Artem