Skip to content

Commit 7db99a0

Browse files
mjbommargregkh
authored andcommitted
xfrm: ah: account for ESN high bits in async callbacks
commit ec54093 upstream. AH allocates its temporary auth/ICV layout differently when ESN is enabled: the async ahash setup appends a 4-byte seqhi slot before the ICV or auth_data area, but the async completion callbacks still reconstruct the temporary layout as if seqhi were absent. With an async AH implementation selected, that makes AH copy or compare the wrong bytes on both the IPv4 and IPv6 paths. In UML repro on IPv4 AH with ESN and forced async hmac(sha1), ping fails with 100% packet loss, and the callback logs show the pre-fix drift: ah4 output_done: esn=1 err=0 icv_off=20 expected_off=24 ah4 input_done: esn=1 auth_off=20 expected_auth_off=24 icv_off=32 expected_icv_off=36 Reconstruct the callback-side layout the same way the setup path built it by skipping the ESN seqhi slot before locating the saved auth_data or ICV. Per RFC 4302, the ESN high-order 32 bits participate in the AH ICV computation, so the async callbacks must account for the seqhi slot. Post-fix, the same IPv4 AH+ESN+forced-async-hmac(sha1) UML repro shows the corrected offset (ah4 output_done: esn=1 err=0 icv_off=24 expected_off=24) and ping succeeds; net/ipv4/ah4.o and net/ipv6/ah6.o build clean at W=1. IPv6 AH+ESN was not exercised at runtime, and the change has not been tested against a real async hardware AH engine. Fixes: d4d573d ("{IPv4,xfrm} Add ESN support for AH egress part") Fixes: d8b2a86 ("{IPv4,xfrm} Add ESN support for AH ingress part") Fixes: 26dd70c ("{IPv6,xfrm} Add ESN support for AH egress part") Fixes: 8d6da6f ("{IPv6,xfrm} Add ESN support for AH ingress part") Cc: stable@vger.kernel.org Assisted-by: Codex:gpt-5-4 Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9d50477 commit 7db99a0

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

net/ipv4/ah4.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,14 @@ static void ah_output_done(void *data, int err)
124124
struct iphdr *top_iph = ip_hdr(skb);
125125
struct ip_auth_hdr *ah = ip_auth_hdr(skb);
126126
int ihl = ip_hdrlen(skb);
127+
int seqhi_len = 0;
128+
__be32 *seqhi;
127129

130+
if (x->props.flags & XFRM_STATE_ESN)
131+
seqhi_len = sizeof(*seqhi);
128132
iph = AH_SKB_CB(skb)->tmp;
129-
icv = ah_tmp_icv(iph, ihl);
133+
seqhi = (__be32 *)((char *)iph + ihl);
134+
icv = ah_tmp_icv(seqhi, seqhi_len);
130135
memcpy(ah->auth_data, icv, ahp->icv_trunc_len);
131136

132137
top_iph->tos = iph->tos;
@@ -270,12 +275,17 @@ static void ah_input_done(void *data, int err)
270275
struct ip_auth_hdr *ah = ip_auth_hdr(skb);
271276
int ihl = ip_hdrlen(skb);
272277
int ah_hlen = (ah->hdrlen + 2) << 2;
278+
int seqhi_len = 0;
279+
__be32 *seqhi;
273280

274281
if (err)
275282
goto out;
276283

284+
if (x->props.flags & XFRM_STATE_ESN)
285+
seqhi_len = sizeof(*seqhi);
277286
work_iph = AH_SKB_CB(skb)->tmp;
278-
auth_data = ah_tmp_auth(work_iph, ihl);
287+
seqhi = (__be32 *)((char *)work_iph + ihl);
288+
auth_data = ah_tmp_auth(seqhi, seqhi_len);
279289
icv = ah_tmp_icv(auth_data, ahp->icv_trunc_len);
280290

281291
err = crypto_memneq(icv, auth_data, ahp->icv_trunc_len) ? -EBADMSG : 0;

net/ipv6/ah6.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,19 @@ static void ah6_output_done(void *data, int err)
317317
struct ipv6hdr *top_iph = ipv6_hdr(skb);
318318
struct ip_auth_hdr *ah = ip_auth_hdr(skb);
319319
struct tmp_ext *iph_ext;
320+
int seqhi_len = 0;
321+
__be32 *seqhi;
320322

321323
extlen = skb_network_header_len(skb) - sizeof(struct ipv6hdr);
322324
if (extlen)
323325
extlen += sizeof(*iph_ext);
324326

327+
if (x->props.flags & XFRM_STATE_ESN)
328+
seqhi_len = sizeof(*seqhi);
325329
iph_base = AH_SKB_CB(skb)->tmp;
326330
iph_ext = ah_tmp_ext(iph_base);
327-
icv = ah_tmp_icv(iph_ext, extlen);
331+
seqhi = (__be32 *)((char *)iph_ext + extlen);
332+
icv = ah_tmp_icv(seqhi, seqhi_len);
328333

329334
memcpy(ah->auth_data, icv, ahp->icv_trunc_len);
330335
memcpy(top_iph, iph_base, IPV6HDR_BASELEN);
@@ -471,13 +476,18 @@ static void ah6_input_done(void *data, int err)
471476
struct ip_auth_hdr *ah = ip_auth_hdr(skb);
472477
int hdr_len = skb_network_header_len(skb);
473478
int ah_hlen = ipv6_authlen(ah);
479+
int seqhi_len = 0;
480+
__be32 *seqhi;
474481

475482
if (err)
476483
goto out;
477484

485+
if (x->props.flags & XFRM_STATE_ESN)
486+
seqhi_len = sizeof(*seqhi);
478487
work_iph = AH_SKB_CB(skb)->tmp;
479488
auth_data = ah_tmp_auth(work_iph, hdr_len);
480-
icv = ah_tmp_icv(auth_data, ahp->icv_trunc_len);
489+
seqhi = (__be32 *)(auth_data + ahp->icv_trunc_len);
490+
icv = ah_tmp_icv(seqhi, seqhi_len);
481491

482492
err = crypto_memneq(icv, auth_data, ahp->icv_trunc_len) ? -EBADMSG : 0;
483493
if (err)

0 commit comments

Comments
 (0)