Tue Jul 11 04:50:59 2017 UTC ()
Correct wrong assumption of sav->refcnt in key_delsah

A sav in a list is basically not to be sav->refcnt == 0. And also
KEY_FREESAV assumes sav->refcnt > 0.


(ozaki-r)
diff -r1.172 -r1.173 src/sys/netipsec/key.c

cvs diff -r1.172 -r1.173 src/sys/netipsec/key.c (expand / switch to unified diff)

--- src/sys/netipsec/key.c 2017/07/10 07:46:02 1.172
+++ src/sys/netipsec/key.c 2017/07/11 04:50:59 1.173
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: key.c,v 1.172 2017/07/10 07:46:02 ozaki-r Exp $ */ 1/* $NetBSD: key.c,v 1.173 2017/07/11 04:50:59 ozaki-r Exp $ */
2/* $FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $ */ 2/* $FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $ */
3/* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */ 3/* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */
4 4
5/* 5/*
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE. 31 * SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.172 2017/07/10 07:46:02 ozaki-r Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.173 2017/07/11 04:50:59 ozaki-r Exp $");
36 36
37/* 37/*
38 * This code is referd to RFC 2367 38 * This code is referd to RFC 2367
39 */ 39 */
40 40
41#if defined(_KERNEL_OPT) 41#if defined(_KERNEL_OPT)
42#include "opt_inet.h" 42#include "opt_inet.h"
43#include "opt_ipsec.h" 43#include "opt_ipsec.h"
44#include "opt_gateway.h" 44#include "opt_gateway.h"
45#endif 45#endif
46 46
47#include <sys/types.h> 47#include <sys/types.h>
48#include <sys/param.h> 48#include <sys/param.h>
@@ -2835,47 +2835,41 @@ key_newsah(const struct secasindex *said @@ -2835,47 +2835,41 @@ key_newsah(const struct secasindex *said
2835 /* add to saidxtree */ 2835 /* add to saidxtree */
2836 newsah->state = SADB_SASTATE_MATURE; 2836 newsah->state = SADB_SASTATE_MATURE;
2837 LIST_INSERT_HEAD(&sahtree, newsah, chain); 2837 LIST_INSERT_HEAD(&sahtree, newsah, chain);
2838 2838
2839 return newsah; 2839 return newsah;
2840} 2840}
2841 2841
2842/* 2842/*
2843 * delete SA index and all SA registerd. 2843 * delete SA index and all SA registerd.
2844 */ 2844 */
2845static void 2845static void
2846key_delsah(struct secashead *sah) 2846key_delsah(struct secashead *sah)
2847{ 2847{
2848 struct secasvar *sav, *nextsav; 2848 struct secasvar *sav;
2849 u_int state; 2849 u_int state;
2850 int s; 2850 int s;
2851 int zombie = 0; 2851 int zombie = 0;
2852 2852
2853 KASSERT(!cpu_softintr_p()); 2853 KASSERT(!cpu_softintr_p());
2854 KASSERT(sah != NULL); 2854 KASSERT(sah != NULL);
2855 2855
2856 s = splsoftnet(); 2856 s = splsoftnet();
2857 2857
2858 /* searching all SA registerd in the secindex. */ 2858 /* searching all SA registerd in the secindex. */
2859 SASTATE_ANY_FOREACH(state) { 2859 SASTATE_ANY_FOREACH(state) {
2860 LIST_FOREACH_SAFE(sav, &sah->savtree[state], chain, nextsav) { 2860 LIST_FOREACH(sav, &sah->savtree[state], chain) {
2861 if (sav->refcnt == 0) { 2861 /* give up to delete this sa */
2862 /* sanity check */ 2862 zombie++;
2863 KEY_CHKSASTATE(state, sav->state); 
2864 KEY_FREESAV(&sav); 
2865 } else { 
2866 /* give up to delete this sa */ 
2867 zombie++; 
2868 } 
2869 } 2863 }
2870 } 2864 }
2871 2865
2872 /* don't delete sah only if there are savs. */ 2866 /* don't delete sah only if there are savs. */
2873 if (zombie) { 2867 if (zombie) {
2874 splx(s); 2868 splx(s);
2875 return; 2869 return;
2876 } 2870 }
2877 2871
2878 rtcache_free(&sah->sa_route); 2872 rtcache_free(&sah->sa_route);
2879 2873
2880 /* remove from tree of SA index */ 2874 /* remove from tree of SA index */
2881 KASSERT(__LIST_CHAINED(sah)); 2875 KASSERT(__LIST_CHAINED(sah));