Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Remove M_PKTHDR from secondary mbufs when reassembling p...
details: https://anonhg.NetBSD.org/src/rev/5080f305b606
branches: trunk
changeset: 360402:5080f305b606
user: maxv <maxv%NetBSD.org@localhost>
date: Fri Mar 09 11:57:38 2018 +0000
description:
Remove M_PKTHDR from secondary mbufs when reassembling packets.
This is a real problem, because I found at least one component that relies
on the fact that only the first mbuf has M_PKTHDR: far from here, in
m_splithdr, we don't update m->m_pkthdr.len if M_PKTHDR is found in a
secondary mbuf. (The initial intention there was to avoid updating
m_pkthdr.len twice, the assumption was that if M_PKTHDR is set then we're
dealing with the first mbuf.) Therefore, when handling fragmented IPsec
packets (in particular IPv6, IPv4 is a bit more complicated), we may end
up with an incorrect m_pkthdr.len after authentication or decryption. In
the case of ESP, this can lead to a remote crash on this instruction:
m_copydata(m, m->m_pkthdr.len - 3, 3, lastthree);
m_pkthdr.len is bigger than the actual mbuf chain.
It seems possible to me to trigger this bug even if you don't have the ESP
key, because the fragmentation part is outside of the encrypted ESP
payload.
So if you MITM the target, and intercept an incoming ESP packet (which you
can't decrypt), you should be able to forge a new specially-crafted,
fragmented packet and stuff the ESP payload (still encrypted, as you
intercepted it) into it. The decryption succeeds and the target crashes.
diffstat:
sys/kern/uipc_mbuf.c | 14 ++++++++++++--
sys/netinet/ip_reass.c | 8 +++++---
sys/netinet6/frag6.c | 11 +++++------
sys/sys/mbuf.h | 4 +++-
4 files changed, 25 insertions(+), 12 deletions(-)
diffs (130 lines):
diff -r c172996db78f -r 5080f305b606 sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c Fri Mar 09 11:05:56 2018 +0000
+++ b/sys/kern/uipc_mbuf.c Fri Mar 09 11:57:38 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_mbuf.c,v 1.181 2018/01/22 15:05:27 maxv Exp $ */
+/* $NetBSD: uipc_mbuf.c,v 1.182 2018/03/09 11:57:38 maxv Exp $ */
/*
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.181 2018/01/22 15:05:27 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.182 2018/03/09 11:57:38 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_mbuftrace.h"
@@ -455,6 +455,16 @@
return (0);
}
+void
+m_pkthdr_remove(struct mbuf *m)
+{
+ KASSERT(m->m_flags & M_PKTHDR);
+
+ m_tag_delete_chain(m, NULL);
+ m->m_flags &= ~M_PKTHDR;
+ memset(&m->m_pkthdr, 0, sizeof(m->m_pkthdr));
+}
+
/*
* Add mbuf to the end of a chain
*/
diff -r c172996db78f -r 5080f305b606 sys/netinet/ip_reass.c
--- a/sys/netinet/ip_reass.c Fri Mar 09 11:05:56 2018 +0000
+++ b/sys/netinet/ip_reass.c Fri Mar 09 11:57:38 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_reass.c,v 1.13 2018/02/08 10:03:52 maxv Exp $ */
+/* $NetBSD: ip_reass.c,v 1.14 2018/03/09 11:57:38 maxv Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1993
@@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.13 2018/02/08 10:03:52 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.14 2018/03/09 11:57:38 maxv Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -389,6 +389,7 @@
t = q->ipqe_m;
nq = TAILQ_NEXT(q, ipqe_q);
pool_cache_put(ipfren_cache, q);
+ m_pkthdr_remove(t);
m_cat(m, t);
}
@@ -406,7 +407,8 @@
m->m_data -= (ip->ip_hl << 2);
/* Fix up mbuf. XXX This should be done elsewhere. */
- if (m->m_flags & M_PKTHDR) {
+ {
+ KASSERT(m->m_flags & M_PKTHDR);
int plen = 0;
for (t = m; t; t = t->m_next) {
plen += t->m_len;
diff -r c172996db78f -r 5080f305b606 sys/netinet6/frag6.c
--- a/sys/netinet6/frag6.c Fri Mar 09 11:05:56 2018 +0000
+++ b/sys/netinet6/frag6.c Fri Mar 09 11:57:38 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: frag6.c,v 1.66 2018/02/07 09:53:08 maxv Exp $ */
+/* $NetBSD: frag6.c,v 1.67 2018/03/09 11:57:38 maxv Exp $ */
/* $KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $ */
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.66 2018/02/07 09:53:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.67 2018/03/09 11:57:38 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@@ -434,6 +434,7 @@
t = t->m_next;
t->m_next = af6->ip6af_m;
m_adj(t->m_next, af6->ip6af_offset);
+ m_pkthdr_remove(t->m_next);
kmem_intr_free(af6, sizeof(struct ip6asfrag));
af6 = af6dwn;
}
@@ -472,12 +473,10 @@
kmem_intr_free(q6, sizeof(struct ip6q));
frag6_nfragpackets--;
- if (m->m_flags & M_PKTHDR) { /* Isn't it always true? */
+ {
+ KASSERT(m->m_flags & M_PKTHDR);
int plen = 0;
for (t = m; t; t = t->m_next) {
- /*
- * XXX XXX Why don't we remove M_PKTHDR?
- */
plen += t->m_len;
}
m->m_pkthdr.len = plen;
diff -r c172996db78f -r 5080f305b606 sys/sys/mbuf.h
--- a/sys/sys/mbuf.h Fri Mar 09 11:05:56 2018 +0000
+++ b/sys/sys/mbuf.h Fri Mar 09 11:57:38 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mbuf.h,v 1.178 2018/02/28 10:30:20 maxv Exp $ */
+/* $NetBSD: mbuf.h,v 1.179 2018/03/09 11:57:38 maxv Exp $ */
/*
* Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -837,6 +837,8 @@
MALLOC_DECLARE(M_MBUF);
MALLOC_DECLARE(M_SONAME);
+void m_pkthdr_remove(struct mbuf *);
+
struct mbuf *m_copym(struct mbuf *, int, int, int);
struct mbuf *m_copypacket(struct mbuf *, int);
struct mbuf *m_devget(char *, int, int, struct ifnet *,
Home |
Main Index |
Thread Index |
Old Index