rtnetlink: fix truncation of dump entry
Subsystems (4)
v3 cover rtnetlink: fix truncation of dump entry
While going through an OSS Scanner dump report for iproute2, I found a bug in the netlink route dump.
If the first entry of a route dump is too big for the dump skb, the dump ends with NLMSG_DONE and status 0. That route, and everything after it, is quietly dropped: "ip route show table 100" prints nothing and exits 0. It takes something well outside normal use to get there, such as a 500 way multipath route.
Two separate paths get it wrong, so there are two fixes.
Patch 1 covers the generic RTNL_FLAG_DUMP_SPLIT_NLM_DONE path in rtnl_dumpit(), which drops -EMSGSIZE and returns skb->len. On an empty skb that is 0. This is the IPv4 FIB case.
Patch 2 covers inet6_dump_fib(), which doesn't use -EMSGSIZE at all; it suspends the walker and returns a positive value. That one goes back further, to when IPv6 multipath routes started being dumped as a single RTA_MULTIPATH message. It has to come after patch 1, since it relies on rtnl_dumpit() no longer swallowing the error.
Patch 3 adds a selftest: IPv4 and IPv6 multipath routes wide enough to miss the first dump skb of a fresh socket. The dump has to either return the route or fail with -EMSGSIZE.
v3 - move to net-next and resolve conflicts
incorporate Sashiko suggestions
v2 - drop Assisted-by
- correct commit message about "ip route get"
Stephen Hemminger (3):
rtnetlink: return EMSGSIZE when first dump entry does not fit
ipv6: return EMSGSIZE when first route in dump does not fit
selftests: net: netlink-dumps: test dump of route larger than skb
net/core/rtnetlink.c | 5 +- net/ipv6/ip6_fib.c | 6 + tools/testing/selftests/net/config | 3 + tools/testing/selftests/net/netlink-dumps.c | 297 +++++++++++++++++++++++++++- 4 files changed, 306 insertions(+), 5 deletions(-)
Signature · 15 lines
2.53.0 Stephen Hemminger (3): rtnetlink: return EMSGSIZE when first dump entry does not fit ipv6: return EMSGSIZE when first route in dump does not fit selftests: net: netlink-dumps: test dump of route larger than skb net/core/rtnetlink.c | 5 +- net/ipv6/ip6_fib.c | 4 + tools/testing/selftests/net/config | 3 + tools/testing/selftests/net/netlink-dumps.c | 297 +++++++++++++++++++- 4 files changed, 304 insertions(+), 5 deletions(-) -- 2.53.0
PATCH v3 1/3 rtnetlink: return EMSGSIZE when first dump entry does not fit
If a route entry is too large for the dump skb, the dump is silently truncated and no error is returned.
For handlers with RTNL_FLAG_DUMP_SPLIT_NLM_DONE, rtnl_dumpit() drops -EMSGSIZE and returns skb->len. With an empty skb this is 0, so the dump ends with NLMSG_DONE and status 0, and the remaining entries are lost.
The first dump skb is allocated from __netlink_dump_start() while max_recvmsg_len is still 0, so it is only NLMSG_GOODSIZE. On a 4K page kernel that is under 4000 bytes, and a 500 way multipath route does not fit:
ip link add dummy0 type dummy
ip link set dummy0 up
ip route add 198.51.100.0/24 table 100 \
$(for i in $(seq 500); do echo -n "nexthop dev dummy0 "; done)
ip route show table 100The dump prints nothing and exits 0
Only ignore -EMSGSIZE when the skb has data, so that an entry which does not fit in an empty skb reports the error to user space.
This only covers handlers which report a too large entry with -EMSGSIZE, such as the IPv4 FIB dump. inet6_dump_fib() instead returns a positive value when the first route does not fit, so the check added here never fires for it; that case is fixed by the next patch in this series.
--- net/core/rtnetlink.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/core/rtnetlink.c +4 -1
@@ -7043,7 +7043,10 @@ static int rtnl_dumpit(struct sk_buff *skb, struct netlink_callback *cb)* Some applications which parse netlink manually depend on this. */ if (cb->flags &RTNL_FLAG_DUMP_SPLIT_NLM_DONE ) { -if (err <0 && err != -EMSGSIZE ) +/* -EMSGSIZE with nothing in the skb is an error, as returning +* a length of 0 would end the dump as if it was complete. +*/ +if (err <0 && (err != -EMSGSIZE || !skb->len))return err;if (!err) cb->data =NULL ;
Signature · 1 line
2.53.0
Re: [PATCH net-next v3 1/3] rtnetlink: return EMSGSIZE when first dump entry does not fit
Hi Stephen,
Quoted 24 lines · Stephen Hemminger
If a route entry is too large for the dump skb, the dump is silently truncated and no error is returned.
For handlers with
RTNL_FLAG_DUMP_SPLIT_NLM_DONE,rtnl_dumpit()drops-EMSGSIZEand returnsskb->len. With an empty skb this is 0, so the dump ends withNLMSG_DONEand status 0, and the remaining entries are lost.The first dump skb is allocated from
__netlink_dump_start()whilemax_recvmsg_lenis still 0, so it is onlyNLMSG_GOODSIZE. On a 4K page kernel that is under 4000 bytes, and a 500 way multipath route does not fit:ip link add dummy0 type dummy ip link set dummy0 up ip route add 198.51.100.0/24 table 100 \ $(for i in $(seq 500); do echo -n "nexthop dev dummy0 "; done) ip route show table 100The dump prints nothing and exits 0
Only ignore
-EMSGSIZEwhen the skb has data, so that an entry which does not fit in an empty skb reports the error to user space.
Quoted 7 lines
This only covers handlers which report a too large entry with
-EMSGSIZE, such as the IPv4 FIB dump.inet6_dump_fib()instead returns a positive value when the first route does not fit, so the check added here never fires for it; that case is fixed by the next patch in this series.Fixes 5b4b62a169e1 ("rtnetlink: make the "split" NLM_DONE handling generic")
Should we keep the Fixes tag or not for net-next?
Thanks
Hangbin
Re: [PATCH net-next v3 1/3] rtnetlink: return EMSGSIZE when first dump entry does not fit
Quoted 6 lines · On Wed, 18 Nov 2026 10:01:52 +0800 Hangbin Liu <[email protected]> wrote:
Quoted 1 line
Fixes 5b4b62a169e1 ("rtnetlink: make the "split" NLM_DONE handling generic")Should we keep the Fixes tag or not for net-next?
Thanks
Hangbin
Yes it is fixing a regression, though I doubt any user would bump into it. The commit referenced changed userspace API behavior
Re: [PATCH net-next v3 1/3] rtnetlink: return EMSGSIZE when first dump entry does not fit
In reply to Stephen HemmingerQuoted 30 lines · Stephen Hemminger
If a route entry is too large for the dump skb, the dump is silently truncated and no error is returned.
For handlers with
RTNL_FLAG_DUMP_SPLIT_NLM_DONE,rtnl_dumpit()drops-EMSGSIZEand returnsskb->len. With an empty skb this is 0, so the dump ends withNLMSG_DONEand status 0, and the remaining entries are lost.The first dump skb is allocated from
__netlink_dump_start()whilemax_recvmsg_lenis still 0, so it is onlyNLMSG_GOODSIZE. On a 4K page kernel that is under 4000 bytes, and a 500 way multipath route does not fit:ip link add dummy0 type dummy ip link set dummy0 up ip route add 198.51.100.0/24 table 100 \ $(for i in $(seq 500); do echo -n "nexthop dev dummy0 "; done) ip route show table 100The dump prints nothing and exits 0
Only ignore
-EMSGSIZEwhen the skb has data, so that an entry which does not fit in an empty skb reports the error to user space.This only covers handlers which report a too large entry with
-EMSGSIZE, such as the IPv4 FIB dump.inet6_dump_fib()instead returns a positive value when the first route does not fit, so the check added here never fires for it; that case is fixed by the next patch in this series.
Quoted 7 lines
Fixes 5b4b62a169e1 ("rtnetlink: make the "split" NLM_DONE handling generic")Signed-off-by Stephen Hemminger <[email protected]>Reviewed-by Ido Schimmel <[email protected]>--- net/core/rtnetlink.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
PATCH v3 2/3 ipv6: return EMSGSIZE when first route in dump does not fit
In reply to Stephen HemmingerIf a route does not fit in an empty dump skb, fib6_dump_node() suspends the walker and inet6_dump_fib() returns 1.rtnl_dumpit() then returns skb->len, which is 0, and the dump ends with NLMSG_DONE and status 0, silently dropping the route and those after it.
This became reachable when multipath routes started being dumped as a single message with an RTA_MULTIPATH attribute; a wide enough route no longer fits.
Return -EMSGSIZE in this case, as IPv4 does. This depends on the rtnl_dumpit() fix in the previous patch.
--- net/ipv6/ip6_fib.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv6/ip6_fib.c +4 -0
@@ -755,6 +755,10 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) unlock:rcu_read_unlock (); + +/* If stopped before adding, it was because next route too large for skb */ +if (err >0 && !skb->len) + err = -EMSGSIZE ;if (err <=0 )fib6_dump_end (cb);return err;
Signature · 1 line
2.53.0
Re: [PATCH net-next v3 2/3] ipv6: return EMSGSIZE when first route in dump does not fit
Quoted 12 lines · Stephen Hemminger
If a route does not fit in an empty dump skb,
fib6_dump_node()suspends the walker andinet6_dump_fib()returns 1.rtnl_dumpit()then returnsskb->len, which is 0, and the dump ends withNLMSG_DONEand status 0, silently dropping the route and those after it.This became reachable when multipath routes started being dumped as a single message with an
RTA_MULTIPATHattribute; a wide enough route no longer fits.Return
-EMSGSIZEin this case, as IPv4 does. This depends on thertnl_dumpit()fix in the previous patch.
Quoted 7 lines
Fixes beb1afac518d ("net: ipv6: Add support to dump multipath routes via RTA_MULTIPATH attribute")Signed-off-by Stephen Hemminger <[email protected]>Reviewed-by Ido Schimmel <[email protected]>--- net/ipv6/ip6_fib.c | 4 ++++ 1 file changed, 4 insertions(+)
PATCH v3 3/3 selftests: net: netlink-dumps: test dump of route larger than skb
In reply to Stephen HemmingerAdd IPv4 and IPv6 multipath routes that do not fit in the first dump skb of a fresh socket. The dump must return the route or fail with -EMSGSIZE, not end with status 0.
Each nexthop carries a gateway so the dumped route grows faster than the kernel side fib_info. A gateway-less IPv4 nexthop only adds 8 bytes to the dump, which would need enough nexthops to make fib_create_info() attempt a high order allocation.
IPv6 nexthops cannot use lo, so create a dummy device and generalize lo_set_up() to if_set_up(). Add the IPv4 routing options to config.
--- tools/testing/selftests/net/config | 3 + tools/testing/selftests/net/netlink-dumps.c | 297 +++++++++++++++++++- 2 files changed, 296 insertions(+), 4 deletions(-)
tools/testing/selftests/net/config +3 -0
@@ -33,6 +33,8 @@ CONFIG_IP6_NF_RAW=m CONFIG_IP6_NF_TARGET_REJECT=m CONFIG_IP_MROUTE=y CONFIG_IP_MULTICAST=y +CONFIG_IP_ADVANCED_ROUTER=y +CONFIG_IP_MULTIPLE_TABLES=y CONFIG_IP_NF_FILTER=m CONFIG_IP_NF_IPTABLES=m CONFIG_IP_NF_IPTABLES_LEGACY=m
@@ -42,6 +44,7 @@ CONFIG_IP_NF_NAT=m CONFIG_IP_NF_RAW=m CONFIG_IP_NF_TARGET_REJECT=m CONFIG_IP_NF_TARGET_TTL=m +CONFIG_IP_ROUTE_MULTIPATH=y CONFIG_IP_SCTP=m CONFIG_IPV6=y CONFIG_IPV6_FOU=m
tools/testing/selftests/net/netlink-dumps.c +293 -4
320 lines not on this page · raw message
Signature · 1 line
2.53.0
Simon Horman
reviewerQuoted 21 lines · Stephen Hemminger
While going through an OSS Scanner dump report for iproute2, I found a bug in the netlink route dump.
If the first entry of a route dump is too big for the dump skb, the dump ends with
NLMSG_DONEand status 0. That route, and everything after it, is quietly dropped: "ip route show table 100" prints nothing and exits 0. It takes something well outside normal use to get there, such as a 500 way multipath route.Two separate paths get it wrong, so there are two fixes.
Patch 1 covers the generic
RTNL_FLAG_DUMP_SPLIT_NLM_DONEpath inrtnl_dumpit(), which drops-EMSGSIZEand returnsskb->len. On an empty skb that is 0. This is the IPv4 FIB case.Patch 2 covers
inet6_dump_fib(), which doesn't use-EMSGSIZEat all; it suspends the walker and returns a positive value. That one goes back further, to when IPv6 multipath routes started being dumped as a singleRTA_MULTIPATHmessage. It has to come after patch 1, since it relies onrtnl_dumpit()no longer swallowing the error.
Quoted 8 lines
Patch 3 adds a selftest: IPv4 and IPv6 multipath routes wide enough to miss the first dump skb of a fresh socket. The dump has to either return the route or fail with
-EMSGSIZE.v3 - move to net-next and resolve conflicts
incorporate Sashiko suggestions
v2 - drop Assisted-by
- correct commit message about "ip route get"
Hi Stephen,
Unfortunately CI was unable to apply this patch to net-next using git am. And stopped there.
Please rebase and post a v4 accumulating tags provided by others.
Signature · 1 line
pw-bot: changes-requested