Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netipsec Fix memory leaks of sah->idents and sah->identd



details:   https://anonhg.NetBSD.org/src/rev/dc5f18986aea
branches:  trunk
changeset: 353653:dc5f18986aea
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Tue May 16 07:43:50 2017 +0000

description:
Fix memory leaks of sah->idents and sah->identd

Originally fixed by the SEIL team of IIJ

diffstat:

 sys/netipsec/key.c |  21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diffs (49 lines):

diff -r 75c51f11c92b -r dc5f18986aea sys/netipsec/key.c
--- a/sys/netipsec/key.c        Tue May 16 07:25:57 2017 +0000
+++ b/sys/netipsec/key.c        Tue May 16 07:43:50 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: key.c,v 1.128 2017/05/16 07:25:57 ozaki-r Exp $        */
+/*     $NetBSD: key.c,v 1.129 2017/05/16 07:43:50 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.128 2017/05/16 07:25:57 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.129 2017/05/16 07:43:50 ozaki-r Exp $");
 
 /*
  * This code is referd to RFC 2367
@@ -2929,6 +2929,11 @@
        if (__LIST_CHAINED(sah))
                LIST_REMOVE(sah, chain);
 
+       if (sah->idents != NULL)
+               KFREE(sah->idents);
+       if (sah->identd != NULL)
+               KFREE(sah->identd);
+
        kmem_free(sah, sizeof(*sah));
 
        splx(s);
@@ -5571,6 +5576,18 @@
        KASSERT(mhp != NULL);
        KASSERT(mhp->msg != NULL);
 
+       /*
+        * Can be called with an existing sah from key_update().
+        */
+       if (sah->idents != NULL) {
+               KFREE(sah->idents);
+               sah->idents = NULL;
+       }
+       if (sah->identd != NULL) {
+               KFREE(sah->identd);
+               sah->identd = NULL;
+       }
+
        /* don't make buffer if not there */
        if (mhp->ext[SADB_EXT_IDENTITY_SRC] == NULL &&
            mhp->ext[SADB_EXT_IDENTITY_DST] == NULL) {



Home | Main Index | Thread Index | Old Index