From 658b7d4eac1c975025e572a07707fa5e129f0f4e Mon Sep 17 00:00:00 2001 From: riastradh Date: Thu, 27 Aug 2020 02:55:04 +0000 Subject: [PATCH] wg: Drop invalid message types on the floor faster. Don't even let them reach the thread -- drop them in softint. --- sys/net/if_wg.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sys/net/if_wg.c b/sys/net/if_wg.c index a5e6961adf5a..aebbd7833897 100644 --- a/sys/net/if_wg.c +++ b/sys/net/if_wg.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_wg.c,v 1.27 2020/08/27 02:54:31 riastradh Exp $ */ +/* $NetBSD: if_wg.c,v 1.28 2020/08/27 02:55:04 riastradh Exp $ */ /* * Copyright (C) Ryota Ozaki @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.27 2020/08/27 02:54:31 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.28 2020/08/27 02:55:04 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -2934,6 +2934,7 @@ wg_overudp_cb(struct mbuf **mp, int offset, struct socket *so, /* Verify the mbuf chain is long enough to have a wg msg header. */ KASSERT(offset <= m_length(m)); if (__predict_false(m_length(m) - offset < sizeof(struct wg_msg))) { + /* drop on the floor */ m_freem(m); return -1; } @@ -2952,15 +2953,21 @@ wg_overudp_cb(struct mbuf **mp, int offset, struct socket *so, */ switch (wgm.wgm_type) { case WG_MSG_TYPE_DATA: + /* handle immediately */ m_adj(m, offset); wg_handle_msg_data(wg, m, src); *mp = NULL; return 1; + case WG_MSG_TYPE_INIT: + case WG_MSG_TYPE_RESP: + case WG_MSG_TYPE_COOKIE: + /* pass through to so_receive in wg_receive_packets */ + return 0; default: - break; + /* drop on the floor */ + m_freem(m); + return -1; } - - return 0; } static int