git: 337c01e48b77 - main - ipsec: Reject an AH IPv6 option length byte past the header

From: Olivier Cochard <olivier_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 15:25:12 UTC
The branch main has been updated by olivier:

URL: https://cgit.FreeBSD.org/src/commit/?id=337c01e48b77fa10b8797eeb83542270b4bd8b38

commit 337c01e48b77fa10b8797eeb83542270b4bd8b38
Author:     Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-11-02 23:02:58 +0000
Commit:     Olivier Cochard <olivier@FreeBSD.org>
CommitDate: 2026-11-17 15:19:22 +0000

    ipsec: Reject an AH IPv6 option length byte past the header
    
    ah_massage_headers() read an IPv6 option's length byte before checking it
    lay within the header, a one-byte over-read of the extension-header copy
    when a non-pad option is the header's last byte.
    
    Reviewed by:    markj, rcm
    Approved by:    markj, rcm
    Sponsored by:   Netflix
    Fixes:  055679e67e13 ("Adopt revision 1.76 and 1.77 from NetBSD: Fix a vulnerability in IPsec-IPv6-AH")
    Differential Revision:  https://ron-dev.freebsd.org/FreeBSD/src/pulls/95
---
 sys/netipsec/xform_ah.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/netipsec/xform_ah.c b/sys/netipsec/xform_ah.c
index ffab85f8128e..5ccf1aebcaf7 100644
--- a/sys/netipsec/xform_ah.c
+++ b/sys/netipsec/xform_ah.c
@@ -476,6 +476,9 @@ ah_massage_headers(struct mbuf **m0, int proto, int skip, int alg, int out)
 						continue; /* Skip padding. */
 					}
 
+					/* The length byte must be in the header. */
+					if (count + 1 >= noff)
+						goto error6;
 					ad = ptr[count + 1] + 2;
 					if (count + ad > noff)
 						goto error6;