ipsec{4,6}_check_pmtu() look up the SA of the last request of a policy
to learn the outer destination, and from it the path MTU. The lookup
fills in the empty addresses of a transport request from the packet as
it is before any transform. When the transport request follows a
tunnel request, as in "esp/tunnel/A-B/require ah/transportrequire",
the transform applies it after the tunnel request, to the outer header,
and its SA is installed for A and B. The check then finds no SA with
every SA in place. At level require it sends an SADB_ACQUIRE for the
inner addresses and drops the packet. strongSwan installs this shape
for IPComp in tunnel mode,
"ipcomp/tunnel/A-B/unique esp/transportunique", so with such a policy
no forwarded IPv6 packet got through, and no IPv4 packet that the check
covers (net.inet.ipsec.dfbit 1, or above 1 for a packet with DF set).
At level use the check sends the same SADB_ACQUIRE and, since
655407eeea5b, skips the comparison with the path MTU. A packet that is
too big once encapsulated is then dropped by ip_output() if the outer
IPv4 header has DF set, or else fragmented, and its sender never learns
the MTU.
A request with addresses of its own, as every tunnel request has, is
looked up the same way whatever the requests before it do, and the
requests after it without addresses keep its destination. So look up
the requests with addresses instead, from the last one back, until one
has an SA: one at level use without an SA is skipped, and the requests
before it may apply. Only when none of them applies, look up the
requests without addresses, with the addresses of the packet, which then
keeps its header. While the SAs are in place this takes one lookup, as
before. ipsec_hdrsiz_internal() still counts the headers of every
request.
Add require variants of the bundle tests, which also check that ipsecB
received the packets with AH, IPComp variants with the policy strongSwan
installs, variants with a second tunnel request at level use and no SA,
and tests that a forwarded packet too big for the path to the tunnel
endpoint, which a route makes smaller than the other paths, is answered
with an ICMP needfrag or an ICMPv6 packet too big.
Reported by: llm-postcr
Fixes: 6b66194bcb7e ("ipsec: Check PMTU before sending a frame.")
Fixes: 9dfc8606eb80 ("ipsec: Add support for PMTUD for IPv6 tunnels")
Fixes: 655407eeea5b ("netipsec: Apply the rest of a bundle when...")
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")