Fri Oct 2 22:05:52 2009 UTC ()
Let the ipkdb subsystem allow operations related to it rather than wrongly
doing so in the suser secmodel.


(elad)
diff -r1.26 -r1.27 src/sys/ipkdb/ipkdb_ipkdb.c
diff -r1.3 -r1.4 src/sys/secmodel/suser/secmodel_suser.c

cvs diff -r1.26 -r1.27 src/sys/ipkdb/Attic/ipkdb_ipkdb.c (expand / switch to unified diff)

--- src/sys/ipkdb/Attic/ipkdb_ipkdb.c 2009/04/12 22:37:50 1.26
+++ src/sys/ipkdb/Attic/ipkdb_ipkdb.c 2009/10/02 22:05:52 1.27
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ipkdb_ipkdb.c,v 1.26 2009/04/12 22:37:50 elad Exp $ */ 1/* $NetBSD: ipkdb_ipkdb.c,v 1.27 2009/10/02 22:05:52 elad Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1993-2000 Wolfgang Solfrank. 4 * Copyright (C) 1993-2000 Wolfgang Solfrank.
5 * Copyright (C) 1993-2000 TooLs GmbH. 5 * Copyright (C) 1993-2000 TooLs GmbH.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: ipkdb_ipkdb.c,v 1.26 2009/04/12 22:37:50 elad Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: ipkdb_ipkdb.c,v 1.27 2009/10/02 22:05:52 elad Exp $");
36 36
37#include "opt_ipkdb.h" 37#include "opt_ipkdb.h"
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/socket.h> 40#include <sys/socket.h>
41#include <sys/mbuf.h> 41#include <sys/mbuf.h>
42#include <sys/reboot.h> 42#include <sys/reboot.h>
43#include <sys/systm.h> 43#include <sys/systm.h>
44#include <sys/kauth.h> 44#include <sys/kauth.h>
45#include <sys/cpu.h> 45#include <sys/cpu.h>
46 46
47#include <net/if.h> 47#include <net/if.h>
48#include <net/if_arp.h> 48#include <net/if_arp.h>
@@ -60,56 +60,80 @@ __KERNEL_RCSID(0, "$NetBSD: ipkdb_ipkdb. @@ -60,56 +60,80 @@ __KERNEL_RCSID(0, "$NetBSD: ipkdb_ipkdb.
60#include <ipkdb/ipkdb.h> 60#include <ipkdb/ipkdb.h>
61#include <machine/ipkdb.h> 61#include <machine/ipkdb.h>
62 62
63int ipkdbpanic = 0; 63int ipkdbpanic = 0;
64 64
65#ifndef IPKDBKEY 65#ifndef IPKDBKEY
66#error You must specify the IPKDBKEY option to use IPKDB. 66#error You must specify the IPKDBKEY option to use IPKDB.
67#else 67#else
68static char ipkdbkey[] = IPKDBKEY; 68static char ipkdbkey[] = IPKDBKEY;
69#endif 69#endif
70 70
71static struct ipkdb_if ipkdb_if; 71static struct ipkdb_if ipkdb_if;
72 72
 73static kauth_listener_t ipkdb_listener;
 74
73static u_char *ipkdbaddr(u_char *, int *, void **); 75static u_char *ipkdbaddr(u_char *, int *, void **);
74static void peekmem(struct ipkdb_if *, u_char *, void *, long); 76static void peekmem(struct ipkdb_if *, u_char *, void *, long);
75static void pokemem(struct ipkdb_if *, u_char *, void *, long); 77static void pokemem(struct ipkdb_if *, u_char *, void *, long);
76static u_int32_t getnl(void *); 78static u_int32_t getnl(void *);
77static u_int getns(void *); 79static u_int getns(void *);
78static void setnl(void *, u_int32_t); 80static void setnl(void *, u_int32_t);
79static void setns(void *, int); 81static void setns(void *, int);
80static u_short cksum(u_short, void *, int); 82static u_short cksum(u_short, void *, int);
81static int assemble(struct ipkdb_if *, void *); 83static int assemble(struct ipkdb_if *, void *);
82static char *inpkt(struct ipkdb_if *, char *, int); 84static char *inpkt(struct ipkdb_if *, char *, int);
83static void outpkt(struct ipkdb_if *, char *, int, int, int); 85static void outpkt(struct ipkdb_if *, char *, int, int, int);
84static void init(struct ipkdb_if *); 86static void init(struct ipkdb_if *);
85static void *chksum(void *, int); 87static void *chksum(void *, int);
86static void getpkt(struct ipkdb_if *, char *, int *); 88static void getpkt(struct ipkdb_if *, char *, int *);
87static void putpkt(struct ipkdb_if *, const char *, int); 89static void putpkt(struct ipkdb_if *, const char *, int);
88static int check_ipkdb(struct ipkdb_if *, struct in_addr *, char *, int); 90static int check_ipkdb(struct ipkdb_if *, struct in_addr *, char *, int);
89static int connectipkdb(struct ipkdb_if *, char *, int); 91static int connectipkdb(struct ipkdb_if *, char *, int);
90static int hmac_init(void); 92static int hmac_init(void);
91 93
 94static int
 95ipkdb_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
 96 void *arg0, void *arg1, void *arg2, void *arg3)
 97{
 98 enum kauth_system_req req;
 99 int result;
 100
 101 req = (enum kauth_system_req)arg0;
 102 result = KAUTH_RESULT_DEFER;
 103
 104 if ((action != KAUTH_SYSTEM_DEBUG) ||
 105 (req != KAUTH_REQ_SYSTEM_DEBUG_IPKDB))
 106 return result;
 107
 108 result = KAUTH_RESULT_ALLOW;
 109
 110 return result;
 111}
 112
92void 113void
93ipkdb_init(void) 114ipkdb_init(void)
94{ 115{
95 ipkdbinit(); 116 ipkdbinit();
96 if ( ipkdbifinit(&ipkdb_if) < 0 117 if ( ipkdbifinit(&ipkdb_if) < 0
97 || !(ipkdb_if.flags&IPKDB_MYHW) 118 || !(ipkdb_if.flags&IPKDB_MYHW)
98 || !hmac_init()) { 119 || !hmac_init()) {
99 /* Interface not found, drop IPKDB */ 120 /* Interface not found, drop IPKDB */
100 printf("IPKDB: No interface found!\n"); 121 printf("IPKDB: No interface found!\n");
101 boothowto &= ~RB_KDB; 122 boothowto &= ~RB_KDB;
102 } 123 }
 124
 125 ipkdb_listener = kauth_listen_scope(KAUTH_SCOPE_SYSTEM,
 126 ipkdb_listener_cb, NULL);
103} 127}
104 128
105void 129void
106ipkdb_connect(int when) 130ipkdb_connect(int when)
107{ 131{
108 boothowto |= RB_KDB; 132 boothowto |= RB_KDB;
109 if (when == 0) 133 if (when == 0)
110 printf("waiting for remote debugger\n"); 134 printf("waiting for remote debugger\n");
111 ipkdb_trap(); 135 ipkdb_trap();
112} 136}
113 137
114void 138void
115ipkdb_panic(void) 139ipkdb_panic(void)

cvs diff -r1.3 -r1.4 src/sys/secmodel/suser/secmodel_suser.c (expand / switch to unified diff)

--- src/sys/secmodel/suser/secmodel_suser.c 2009/10/02 21:56:28 1.3
+++ src/sys/secmodel/suser/secmodel_suser.c 2009/10/02 22:05:52 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: secmodel_suser.c,v 1.3 2009/10/02 21:56:28 elad Exp $ */ 1/* $NetBSD: secmodel_suser.c,v 1.4 2009/10/02 22:05:52 elad Exp $ */
2/*- 2/*-
3 * Copyright (c) 2006 Elad Efrat <elad@NetBSD.org> 3 * Copyright (c) 2006 Elad Efrat <elad@NetBSD.org>
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products 14 * 3. The name of the author may not be used to endorse or promote products
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 28
29/* 29/*
30 * This file contains kauth(9) listeners needed to implement the traditional 30 * This file contains kauth(9) listeners needed to implement the traditional
31 * NetBSD superuser access restrictions. 31 * NetBSD superuser access restrictions.
32 * 32 *
33 * There are two main resources a request can be issued to: user-owned and 33 * There are two main resources a request can be issued to: user-owned and
34 * system owned. For the first, traditional Unix access checks are done, as 34 * system owned. For the first, traditional Unix access checks are done, as
35 * well as superuser checks. If needed, the request context is examined before 35 * well as superuser checks. If needed, the request context is examined before
36 * a decision is made. For the latter, usually only superuser checks are done 36 * a decision is made. For the latter, usually only superuser checks are done
37 * as normal users are not allowed to access system resources. 37 * as normal users are not allowed to access system resources.
38 */ 38 */
39 39
40#include <sys/cdefs.h> 40#include <sys/cdefs.h>
41__KERNEL_RCSID(0, "$NetBSD: secmodel_suser.c,v 1.3 2009/10/02 21:56:28 elad Exp $"); 41__KERNEL_RCSID(0, "$NetBSD: secmodel_suser.c,v 1.4 2009/10/02 22:05:52 elad Exp $");
42 42
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/kauth.h> 45#include <sys/kauth.h>
46 46
47#include <sys/acct.h> 47#include <sys/acct.h>
48#include <sys/mutex.h> 48#include <sys/mutex.h>
49#include <sys/ktrace.h> 49#include <sys/ktrace.h>
50#include <sys/mount.h> 50#include <sys/mount.h>
51#include <sys/pset.h> 51#include <sys/pset.h>
52#include <sys/socketvar.h> 52#include <sys/socketvar.h>
53#include <sys/sysctl.h> 53#include <sys/sysctl.h>
54#include <sys/tty.h> 54#include <sys/tty.h>
@@ -461,37 +461,26 @@ secmodel_suser_system_cb(kauth_cred_t cr @@ -461,37 +461,26 @@ secmodel_suser_system_cb(kauth_cred_t cr
461 461
462 break; 462 break;
463 463
464 case KAUTH_SYSTEM_SWAPCTL: 464 case KAUTH_SYSTEM_SWAPCTL:
465 case KAUTH_SYSTEM_ACCOUNTING: 465 case KAUTH_SYSTEM_ACCOUNTING:
466 case KAUTH_SYSTEM_REBOOT: 466 case KAUTH_SYSTEM_REBOOT:
467 case KAUTH_SYSTEM_CHROOT: 467 case KAUTH_SYSTEM_CHROOT:
468 case KAUTH_SYSTEM_FILEHANDLE: 468 case KAUTH_SYSTEM_FILEHANDLE:
469 case KAUTH_SYSTEM_MKNOD: 469 case KAUTH_SYSTEM_MKNOD:
470 if (isroot) 470 if (isroot)
471 result = KAUTH_RESULT_ALLOW; 471 result = KAUTH_RESULT_ALLOW;
472 break; 472 break;
473 473
474 case KAUTH_SYSTEM_DEBUG: 
475 switch (req) { 
476 case KAUTH_REQ_SYSTEM_DEBUG_IPKDB: 
477 default: 
478 /* Decisions are root-agnostic. */ 
479 result = KAUTH_RESULT_ALLOW; 
480 break; 
481 } 
482 
483 break; 
484 
485 case KAUTH_SYSTEM_CHSYSFLAGS: 474 case KAUTH_SYSTEM_CHSYSFLAGS:
486 /* 475 /*
487 * Needs to be checked in conjunction with the immutable and 476 * Needs to be checked in conjunction with the immutable and
488 * append-only flags (usually). Should be handled differently. 477 * append-only flags (usually). Should be handled differently.
489 * Infects ufs, ext2fs, tmpfs, and rump. 478 * Infects ufs, ext2fs, tmpfs, and rump.
490 */ 479 */
491 if (isroot) 480 if (isroot)
492 result = KAUTH_RESULT_ALLOW; 481 result = KAUTH_RESULT_ALLOW;
493 482
494 break; 483 break;
495 484
496 case KAUTH_SYSTEM_SETIDCORE: 485 case KAUTH_SYSTEM_SETIDCORE:
497 if (isroot) 486 if (isroot)