In transport mode ipsec6_common_input_cb() delivers the packet itself,
on the stack of the crypto callback that called it. With a synchronous
crypto driver that is the stack of the thread that dispatched the
request. Since 3cd5f1b307ad the callback hands a further AH, ESP or
IPComp header to ipsec_common_input() from there, so the transform, its
callback and the next delivery all ran below the first one. Every
nested header added a set of frames and only the size of the packet
limited their number. IPComp carries no authentication and
ipcomp_input() only refuses an IPComp header that is directly followed
by another, so anyone who could reach a host with an IPv6 IPComp SA
could overflow the kernel stack with one packet that hides each IPComp
header behind a destination options header.
Requeue the packet to the IPv6 netisr instead, as the IPv4 callback
does for every transport mode packet, and let ip6_input() hand the
header over from a fresh stack. ip6_input() refuses addresses in the
embedded scope form that its first pass left behind, so put them back
as they were on the wire. The packet passes the pfil hooks and its
extension headers again, as it does for IPv4, and the header nesting
limit of ip6_input() now counts the headers that each pass leaves in
front of the next IPsec header.
This needs the two previous changes: ip6_input() has to find a
consistent header chain, and the policy check has to find the AH flags
after the second pass.
A UDP encapsulated ESP header that the delivery reaches still calls its
transform from here; that path is older and is not changed.
Reported by: llm-postcr
Fixes: 3cd5f1b307ad ("netipsec: Process a nested IPsec header on IPv6 input")
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")