git: c1914b1be9ed - main - ipsec: Reject an AH IPv4 option that runs past the header
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Nov 2026 17:36:10 UTC
The branch main has been updated by olivier:
URL: https://cgit.FreeBSD.org/src/commit/?id=c1914b1be9edcd4e9b76c42f445d116c946b61f1
commit c1914b1be9edcd4e9b76c42f445d116c946b61f1
Author: Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-11-02 23:02:58 +0000
Commit: Olivier Cochard <olivier@FreeBSD.org>
CommitDate: 2026-11-17 17:31:20 +0000
ipsec: Reject an AH IPv4 option that runs past the header
ah_massage_headers() zeroed each mutable IPv4 option before checking its
length fit the header, so an option length byte could write up to 255 zero
bytes past the IP header (and the mbuf) when ip_dooptions() had not
validated the options (process_options=0).
With the check done up front, the post-switch off > skip test is dead;
remove it.
Reviewed by: markj, rcm
Approved by: markj, rcm
Sponsored by: Netflix
Fixes: b12a7532e390 ("Merge revision 1.35 from NetBSD: fix pointer/offset mistakes in handling of IPv4 options")
Differential Revision: https://ron-dev.freebsd.org/FreeBSD/src/pulls/94
---
sys/netipsec/xform_ah.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/sys/netipsec/xform_ah.c b/sys/netipsec/xform_ah.c
index 5ccf1aebcaf7..832554b0f514 100644
--- a/sys/netipsec/xform_ah.c
+++ b/sys/netipsec/xform_ah.c
@@ -314,6 +314,15 @@ ah_massage_headers(struct mbuf **m0, int proto, int skip, int alg, int out)
return EINVAL;
}
+ /* An option must not run past the header. */
+ if (ptr[off] != IPOPT_EOL && ptr[off] != IPOPT_NOP &&
+ off + ptr[off + 1] > skip) {
+ DPRINTF(("%s: malformed IPv4 options header\n",
+ __func__));
+ m_freem(m);
+ return EINVAL;
+ }
+
switch (ptr[off]) {
case IPOPT_EOL:
off = skip; /* End the loop. */
@@ -384,15 +393,6 @@ ah_massage_headers(struct mbuf **m0, int proto, int skip, int alg, int out)
off += count;
break;
}
-
- /* Sanity check. */
- if (off > skip) {
- DPRINTF(("%s: malformed IPv4 options header\n",
- __func__));
-
- m_freem(m);
- return EINVAL;
- }
}
break;