Skip to content

rtnetlink: fix truncation of dump entry

Stephen Hemminger linux-kselftest lkml netdev 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 5 repliesIn review
  2. v23 patches 5 repliesSuperseded
  3. v13 patches 5 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3rtnetlink: return EMSGSIZE when first dump entry does not fitnet/core/rtnetlink.c+4 -13 replies
2/3ipv6: return EMSGSIZE when first route in dump does not fitnet/ipv6/ip6_fib.c+4 -01 reply
3/3selftests: net: netlink-dumps: test dump of route larger than skbtools/testing/selftests/net/config tools/testing/selftests/net/netlink-dumps.c+296 -40 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchIdo SchimmelHangbin LiuDavid Ahern
1/3R-b R-b
2/3R-b R-b
3/3T-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v3 thread

Cover letter [PATCH net v3 0/3] 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