Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net wg: KASSERT m_len before mtod.
details: https://anonhg.NetBSD.org/src/rev/28b4da7ef9e2
branches: trunk
changeset: 943117:28b4da7ef9e2
user: riastradh <riastradh%NetBSD.org@localhost>
date: Thu Aug 27 02:54:31 2020 +0000
description:
wg: KASSERT m_len before mtod.
XXX We should really make mtod do this automagically, and use
something else for mtod(m, void *).
diffstat:
sys/net/if_wg.c | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
diffs (66 lines):
diff -r b37ed34fe90c -r 28b4da7ef9e2 sys/net/if_wg.c
--- a/sys/net/if_wg.c Thu Aug 27 02:53:47 2020 +0000
+++ b/sys/net/if_wg.c Thu Aug 27 02:54:31 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_wg.c,v 1.26 2020/08/27 02:53:47 riastradh Exp $ */
+/* $NetBSD: if_wg.c,v 1.27 2020/08/27 02:54:31 riastradh Exp $ */
/*
* Copyright (C) Ryota Ozaki <ozaki.ryota%gmail.com@localhost>
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.26 2020/08/27 02:53:47 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.27 2020/08/27 02:54:31 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -1570,7 +1570,6 @@
m = m_gethdr(M_WAIT, MT_DATA);
m->m_pkthdr.len = m->m_len = sizeof(*wgmi);
wgmi = mtod(m, struct wg_msg_init *);
-
wg_fill_msg_init(wg, wgp, wgs, wgmi);
error = wg->wg_ops->send_hs_msg(wgp, m);
@@ -2387,6 +2386,7 @@
free_encrypted_buf = true;
}
/* m_ensure_contig may change m regardless of its result */
+ KASSERT(m->m_len >= sizeof(*wgmd));
wgmd = mtod(m, struct wg_msg_data *);
decrypted_len = encrypted_len - WG_AUTHTAG_LEN;
@@ -2683,6 +2683,7 @@
}
KASSERT(paddr != NULL);
+ KASSERT(paddr->m_len >= sizeof(struct sockaddr));
src = mtod(paddr, struct sockaddr *);
wg_handle_packet(wg, m, src);
@@ -3683,6 +3684,7 @@
error = ENOBUFS;
goto end;
}
+ KASSERT(n->m_len >= sizeof(*wgmd));
wgmd = mtod(n, struct wg_msg_data *);
wg_fill_msg_data(wg, wgp, wgs, wgmd);
/* [W] 5.4.6: AEAD(Tm^send, Nm^send, P, e) */
@@ -4553,11 +4555,15 @@
if (af == AF_INET) {
struct sockaddr_in *sin = (struct sockaddr_in *)&ss;
struct ip *ip;
+
+ KASSERT(m->m_len >= sizeof(struct ip));
ip = mtod(m, struct ip *);
sockaddr_in_init(sin, &ip->ip_dst, 0);
} else {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ss;
struct ip6_hdr *ip6;
+
+ KASSERT(m->m_len >= sizeof(struct ip6_hdr));
ip6 = mtod(m, struct ip6_hdr *);
sockaddr_in6_init(sin6, &ip6->ip6_dst, 0, 0, 0);
}
Home |
Main Index |
Thread Index |
Old Index