ip_gre: fix header lengths and validation on changelink
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 1 replyIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | ip_gre: validate netlink attributes before changing the tunnelnet/ | +32 | 0 replies | |
| 2/3 | ip_gre: compute tunnel lengths absolutely instead of by deltainclude/ net/ net/ | +46 | 0 replies | |
| 3/3 | ip_gre: recompute erspan header lengths after a changenet/ | +42 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH net 0/3] ip_gre: fix header lengths and validation on changelink
Three fixes in the IPv4 GRE/ERSPAN changelink path, found while preparing an RCU conversion of the IPv4 tunnel configuration. They all come from the same place: ipgre_changelink() and erspan_changelink() mutate the live device as they go, without keeping tunnel->hlen, dev->needed_headroom and dev->mtu in sync.
Patch 1 makes the netlink parsers all-or-nothing. They write into the live tunnel before all attributes have been validated, so a rejected request leaves it half updated; in the worst case dev->type is left at ARPHRD_NONE and the interface is broken for good.
Patch 2 stops maintaining the device lengths as a difference. ipgre_link_update() adjusts them by a delta computed from tun_hlen only, while ip_tunnel_bind_dev() assigns the same fields from tunnel->hlen. Two writers, two models, and a delta that ignores the encapsulation, is applied on top of the absolute assignment when the link changes too, and is computed from a length ip_tunnel_encap_setup() may have published for a request that then failed. tunnel->hlen is now recomputed from tun_hlen and encap_hlen, and ip_tunnel_bind_dev() becomes the only writer of the device lengths. Not a memory safety issue: ip_tunnel_xmit() computes its own headroom for the encapsulation, only the advertised MTU is wrong.
Patch 3 gives ERSPAN the same treatment, where it does crash:erspan_xmit() reserves dev->needed_headroom with skb_cow_head() and then pushes a header sized from the current version, so going from version 0 to version 2 adds 20 bytes and can reach skb_under_panic().
Notes for reviewers, because not all bugs are fixed.
When the header length really changes, dev->mtu
is now recomputed by ip_tunnel_bind_dev() instead of being shifted by the difference, as ip_tunnel_update() already does for a link or fwmark change; a MTU configured by the user still survives a request that does not change the header length.
And the changelink paths still commit into the live tunnel step by step. A rejected request is therefore not a no-op, and since the xmit path is lockless, a concurrent erspan_xmit() can briefly see a new erspan_ver while dev->needed_headroom still describes the old one. Both are pre-existing. These patches shrink the second one from permanent to the duration of a single changelink, since erspan_changelink() does not refresh the lengths at all today, but closing it means publishing a whole new configuration atomically. That needs a larger rework and will come with the ip_tunnel RCU conversion in net-next.
Eric Dumazet (3):
ip_gre: validate netlink attributes before changing the tunnel
ip_gre: compute tunnel lengths absolutely instead of by delta
ip_gre: recompute erspan header lengths after a change
include/net/ip_tunnels.h | 1 + net/ipv4/ip_gre.c | 146 +++++++++++++++++++++++++++------------ net/ipv4/ip_tunnel.c | 16 +++++ 3 files changed, 120 insertions(+), 43 deletions(-)
Signature · 1 line
2.55.0.1007.g17ff1f9808-goog