Source-Changes-HG archive

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

[src/trunk]: src/sys mark security policy that should persist in the system "...



details:   https://anonhg.NetBSD.org/src/rev/9a0df7097120
branches:  trunk
changeset: 552244:9a0df7097120
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Sep 22 04:47:43 2003 +0000

description:
mark security policy that should persist in the system "persistent".
this should prevent recently-reported kernel panic when "spdflush" is issued.

diffstat:

 sys/netinet6/ipsec.c |  10 ++++++----
 sys/netinet6/ipsec.h |   3 ++-
 sys/netkey/key.c     |  32 +++++++++++++++++++++++++++++---
 3 files changed, 37 insertions(+), 8 deletions(-)

diffs (144 lines):

diff -r 8034edfc6fe5 -r 9a0df7097120 sys/netinet6/ipsec.c
--- a/sys/netinet6/ipsec.c      Mon Sep 22 04:25:16 2003 +0000
+++ b/sys/netinet6/ipsec.c      Mon Sep 22 04:47:43 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ipsec.c,v 1.81 2003/09/12 07:58:25 itojun Exp $        */
+/*     $NetBSD: ipsec.c,v 1.82 2003/09/22 04:47:43 itojun Exp $        */
 /*     $KAME: ipsec.c,v 1.136 2002/05/19 00:36:39 itojun Exp $ */
 
 /*
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.81 2003/09/12 07:58:25 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.82 2003/09/22 04:47:43 itojun Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1175,13 +1175,15 @@
                in->policy = IPSEC_POLICY_ENTRUST;
                in->dir = IPSEC_DIR_INBOUND;
                in->readonly = 1;
-               in->so = so;
+               in->persist = 1;
+               in->so = NULL;
 
                out->state = IPSEC_SPSTATE_ALIVE;
                out->policy = IPSEC_POLICY_ENTRUST;
                out->dir = IPSEC_DIR_OUTBOUND;
                out->readonly = 1;
-               out->so = so;
+               out->persist = 1;
+               out->so = NULL;
 
                initialized++;
        }
diff -r 8034edfc6fe5 -r 9a0df7097120 sys/netinet6/ipsec.h
--- a/sys/netinet6/ipsec.h      Mon Sep 22 04:25:16 2003 +0000
+++ b/sys/netinet6/ipsec.h      Mon Sep 22 04:47:43 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ipsec.h,v 1.40 2003/09/12 07:38:13 itojun Exp $        */
+/*     $NetBSD: ipsec.h,v 1.41 2003/09/22 04:47:44 itojun Exp $        */
 /*     $KAME: ipsec.h,v 1.51 2001/08/05 04:52:58 itojun Exp $  */
 
 /*
@@ -74,6 +74,7 @@
 
        u_int8_t dir;                   /* direction of packet flow */
        int readonly;                   /* write prohibited */
+       int persist;                    /* will never be removed */
        int refcnt;                     /* reference count */
        struct secpolicyindex *spidx;   /* selector - NULL if not valid */
        u_int16_t tag;                  /* PF tag */
diff -r 8034edfc6fe5 -r 9a0df7097120 sys/netkey/key.c
--- a/sys/netkey/key.c  Mon Sep 22 04:25:16 2003 +0000
+++ b/sys/netkey/key.c  Mon Sep 22 04:47:43 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: key.c,v 1.100 2003/09/20 05:12:45 itojun Exp $ */
+/*     $NetBSD: key.c,v 1.101 2003/09/22 04:47:45 itojun Exp $ */
 /*     $KAME: key.c,v 1.310 2003/09/08 02:23:44 itojun Exp $   */
 
 /*
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.100 2003/09/20 05:12:45 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.101 2003/09/22 04:47:45 itojun Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1681,6 +1681,13 @@
                newsp = key_getspbytag(tagvalue, xpl0->sadb_x_policy_dir);
        }
 #endif
+
+       if (newsp && (newsp->readonly || newsp->persist)) {
+               ipseclog((LOG_DEBUG,
+                   "key_spdadd: tried to alter readonly/persistent SP.\n"));
+               return key_senderror(so, m, EPERM);
+       }
+
        if (mhp->msg->sadb_msg_type == SADB_X_SPDUPDATE) {
                if (newsp) {
                        key_sp_dead(newsp);
@@ -1940,6 +1947,13 @@
                return key_senderror(so, m, EINVAL);
        }
 
+       if (sp->persist) {
+               ipseclog((LOG_DEBUG,
+                   "key_spddelete2: attempt to remove persistent SP:%u.\n",
+                   sp->id));
+               return key_senderror(so, m, EPERM);
+       }
+
        /* save policy id to be returned. */
        xpl0->sadb_x_policy_id = sp->id;
 
@@ -2005,10 +2019,18 @@
 
        /* Is there SP in SPD ? */
        if ((sp = key_getspbyid(id)) == NULL) {
-               ipseclog((LOG_DEBUG, "key_spddelete2: no SP found id:%u.\n", id));
+               ipseclog((LOG_DEBUG, "key_spddelete2: no SP found id:%u.\n",
+                   id));
                return key_senderror(so, m, EINVAL);
        }
 
+       if (sp->persist) {
+               ipseclog((LOG_DEBUG,
+                   "key_spddelete2: attempt to remove persistent SP:%u.\n",
+                   id));
+               return key_senderror(so, m, EPERM);
+       }
+
        key_sp_dead(sp);
        key_freesp(sp); /* ref gained by key_getsp */
        key_sp_unlink(sp);
@@ -2239,6 +2261,8 @@
 
        for (sp = TAILQ_FIRST(&sptailq); sp; sp = nextsp) {
                nextsp = TAILQ_NEXT(sp, tailq);
+               if (sp->persist)
+                       continue;
                if (sp->state == IPSEC_SPSTATE_DEAD)
                        continue;
                key_sp_dead(sp);
@@ -7476,6 +7500,7 @@
        ip4_def_policy->policy = IPSEC_POLICY_NONE;
        ip4_def_policy->dir = IPSEC_DIR_ANY;
        ip4_def_policy->readonly = 1;
+       ip4_def_policy->persist = 1;
 #endif
 #ifdef INET6
        ip6_def_policy = key_newsp(0);
@@ -7485,6 +7510,7 @@
        ip6_def_policy->policy = IPSEC_POLICY_NONE;
        ip6_def_policy->dir = IPSEC_DIR_ANY;
        ip6_def_policy->readonly = 1;
+       ip6_def_policy->persist = 1;
 #endif
 
        callout_reset(&key_timehandler_ch, hz, key_timehandler, (void *)0);



Home | Main Index | Thread Index | Old Index