Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/netipsec Provide a function to call MGETHDR and MCLGET
details: https://anonhg.NetBSD.org/src/rev/328ec2fe129a
branches: trunk
changeset: 357675:328ec2fe129a
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Tue Nov 21 06:49:56 2017 +0000
description:
Provide a function to call MGETHDR and MCLGET
The change fixes two usages of MGETHDR that don't check whether a mbuf is really
allocated before passing it to MCLGET.
diffstat:
sys/netipsec/key.c | 66 +++++++++++++++++++----------------------------------
1 files changed, 24 insertions(+), 42 deletions(-)
diffs (129 lines):
diff -r ca2764c2fe7b -r 328ec2fe129a sys/netipsec/key.c
--- a/sys/netipsec/key.c Tue Nov 21 06:35:22 2017 +0000
+++ b/sys/netipsec/key.c Tue Nov 21 06:49:56 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: key.c,v 1.235 2017/11/08 10:35:30 ozaki-r Exp $ */
+/* $NetBSD: key.c,v 1.236 2017/11/21 06:49:56 ozaki-r Exp $ */
/* $FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $ */
/* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.235 2017/11/08 10:35:30 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.236 2017/11/21 06:49:56 ozaki-r Exp $");
/*
* This code is referred to RFC 2367
@@ -788,6 +788,7 @@
static void key_sa_chgstate (struct secasvar *, u_int8_t);
static struct mbuf *key_alloc_mbuf (int);
+static struct mbuf *key_alloc_mbuf_simple(int, int);
static void key_timehandler(void *);
static void key_timehandler_work(struct work *, void *);
@@ -2416,6 +2417,22 @@
}
}
+static struct mbuf *
+key_alloc_mbuf_simple(int len, int mflag)
+{
+ struct mbuf *n;
+
+ MGETHDR(n, mflag, MT_DATA);
+ if (n && len > MHLEN) {
+ MCLGET(n, mflag);
+ if ((n->m_flags & M_EXT) == 0) {
+ m_freem(n);
+ n = NULL;
+ }
+ }
+ return n;
+}
+
/*
* SADB_SPDDELETE2 processing
* receive
@@ -2465,14 +2482,7 @@
/* create new sadb_msg to reply. */
len = PFKEY_ALIGN8(sizeof(struct sadb_msg));
- MGETHDR(n, M_DONTWAIT, MT_DATA);
- if (n && len > MHLEN) {
- MCLGET(n, M_DONTWAIT);
- if ((n->m_flags & M_EXT) == 0) {
- m_freem(n);
- n = NULL;
- }
- }
+ n = key_alloc_mbuf_simple(len, M_DONTWAIT);
if (!n)
return key_senderror(so, m, ENOBUFS);
@@ -4072,14 +4082,7 @@
len = PFKEY_ALIGN8(sizeof(struct sadb_msg));
- MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m && len > MHLEN) {
- MCLGET(m, M_DONTWAIT);
- if ((m->m_flags & M_EXT) == 0) {
- m_freem(m);
- m = NULL;
- }
- }
+ m = key_alloc_mbuf_simple(len, M_DONTWAIT);
if (!m)
return NULL;
m->m_pkthdr.len = m->m_len = len;
@@ -5257,14 +5260,7 @@
len = PFKEY_ALIGN8(sizeof(struct sadb_msg)) +
PFKEY_ALIGN8(sizeof(struct sadb_sa));
- MGETHDR(n, M_DONTWAIT, MT_DATA);
- if (len > MHLEN) {
- MCLGET(n, M_DONTWAIT);
- if ((n->m_flags & M_EXT) == 0) {
- m_freem(n);
- n = NULL;
- }
- }
+ n = key_alloc_mbuf_simple(len, M_DONTWAIT);
if (!n)
return key_senderror(so, m, ENOBUFS);
@@ -7105,14 +7101,7 @@
if (len > MCLBYTES)
return key_senderror(so, m, ENOBUFS);
- MGETHDR(n, M_DONTWAIT, MT_DATA);
- if (len > MHLEN) {
- MCLGET(n, M_DONTWAIT);
- if ((n->m_flags & M_EXT) == 0) {
- m_freem(n);
- n = NULL;
- }
- }
+ n = key_alloc_mbuf_simple(len, M_DONTWAIT);
if (!n)
return key_senderror(so, m, ENOBUFS);
@@ -7728,14 +7717,7 @@
if (m->m_next) {
struct mbuf *n;
- MGETHDR(n, M_DONTWAIT, MT_DATA);
- if (n && m->m_pkthdr.len > MHLEN) {
- MCLGET(n, M_DONTWAIT);
- if ((n->m_flags & M_EXT) == 0) {
- m_free(n);
- n = NULL;
- }
- }
+ n = key_alloc_mbuf_simple(m->m_pkthdr.len, M_DONTWAIT);
if (!n) {
m_freem(m);
return ENOBUFS;
Home |
Main Index |
Thread Index |
Old Index