verified_exec.h revision 1.50 1 1.50 elad /* $NetBSD: verified_exec.h,v 1.50 2007/01/07 13:55:17 elad Exp $ */
2 1.1 blymn
3 1.1 blymn /*-
4 1.50 elad * Copyright (c) 2005, 2006 Elad Efrat <elad (at) NetBSD.org>
5 1.50 elad * Copyright (c) 2005, 2006 Brett Lymn <blymn (at) NetBSD.org>
6 1.50 elad * All rights reserved.
7 1.1 blymn *
8 1.1 blymn * Redistribution and use in source and binary forms, with or without
9 1.1 blymn * modification, are permitted provided that the following conditions
10 1.1 blymn * are met:
11 1.1 blymn * 1. Redistributions of source code must retain the above copyright
12 1.1 blymn * notice, this list of conditions and the following disclaimer.
13 1.50 elad * 2. Redistributions in binary form must reproduce the above copyright
14 1.50 elad * notice, this list of conditions and the following disclaimer in the
15 1.50 elad * documentation and/or other materials provided with the distribution.
16 1.50 elad * 3. All advertising materials mentioning features or use of this software
17 1.50 elad * must display the following acknowledgement:
18 1.50 elad * This product includes software developed by Brett Lymn and Elad Efrat.
19 1.50 elad * 4. The name of the authors may not be used to endorse or promote products
20 1.50 elad * derived from this software without specific prior written permission.
21 1.7 blymn *
22 1.50 elad * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
23 1.50 elad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.50 elad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.50 elad * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.50 elad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.50 elad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.50 elad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.50 elad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.50 elad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.50 elad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 blymn */
33 1.1 blymn
34 1.14 elad #ifndef _SYS_VERIFIED_EXEC_H_
35 1.14 elad #define _SYS_VERIFIED_EXEC_H_
36 1.14 elad
37 1.14 elad #include <sys/cdefs.h>
38 1.1 blymn #include <sys/param.h>
39 1.44 elad #include <sys/ioctl.h>
40 1.44 elad
41 1.46 agc #if defined(_KERNEL) && !defined(HAVE_NBTOOL_CONFIG_H)
42 1.44 elad #include <sys/malloc.h>
43 1.20 elad #include <uvm/uvm_extern.h>
44 1.20 elad #include <uvm/uvm_pglist.h>
45 1.20 elad #include <uvm/uvm_page.h>
46 1.42 elad #include <prop/proplib.h>
47 1.44 elad #endif /* _KERNEL */
48 1.28 elad
49 1.24 elad /* Flags for a Veriexec entry. These can be OR'd together. */
50 1.16 elad #define VERIEXEC_DIRECT 0x01 /* Direct execution (exec) */
51 1.16 elad #define VERIEXEC_INDIRECT 0x02 /* Indirect execution (#!) */
52 1.16 elad #define VERIEXEC_FILE 0x04 /* Plain file (open) */
53 1.20 elad #define VERIEXEC_UNTRUSTED 0x10 /* Untrusted storage */
54 1.1 blymn
55 1.24 elad /* Operations for /dev/veriexec. */
56 1.43 elad #define VERIEXEC_LOAD _IOW('X', 0x1, struct plistref)
57 1.43 elad #define VERIEXEC_TABLESIZE _IOW('X', 0x2, struct plistref)
58 1.43 elad #define VERIEXEC_DELETE _IOW('X', 0x3, struct plistref)
59 1.43 elad #define VERIEXEC_QUERY _IOWR('X', 0x4, struct plistref)
60 1.7 blymn
61 1.44 elad /* Veriexec modes (strict levels). */
62 1.44 elad #define VERIEXEC_LEARNING 0 /* Learning mode. */
63 1.44 elad #define VERIEXEC_IDS 1 /* Intrusion detection mode. */
64 1.44 elad #define VERIEXEC_IPS 2 /* Intrusion prevention mode. */
65 1.44 elad #define VERIEXEC_LOCKDOWN 3 /* Lockdown mode. */
66 1.8 elad
67 1.28 elad /* Valid status field values. */
68 1.28 elad #define FINGERPRINT_NOTEVAL 0 /* fingerprint has not been evaluated */
69 1.28 elad #define FINGERPRINT_VALID 1 /* fingerprint evaluated and matches list */
70 1.28 elad #define FINGERPRINT_NOMATCH 2 /* fingerprint evaluated but does not match */
71 1.28 elad
72 1.28 elad /* Per-page fingerprint status. */
73 1.28 elad #define PAGE_FP_NONE 0 /* no per-page fingerprints. */
74 1.28 elad #define PAGE_FP_READY 1 /* per-page fingerprints ready for use. */
75 1.28 elad #define PAGE_FP_FAIL 2 /* mismatch in per-page fingerprints. */
76 1.28 elad
77 1.1 blymn /*
78 1.7 blymn * Operations vector for verified exec, this defines the characteristics
79 1.7 blymn * for the fingerprint type.
80 1.24 elad * Function types: init, update, final.
81 1.1 blymn */
82 1.44 elad typedef void (*veriexec_fpop_init_t)(void *);
83 1.44 elad typedef void (*veriexec_fpop_update_t)(void *, u_char *, u_int);
84 1.44 elad typedef void (*veriexec_fpop_final_t)(u_char *, void *);
85 1.1 blymn
86 1.46 agc #if defined(_KERNEL) && !defined(HAVE_NBTOOL_CONFIG_H)
87 1.44 elad MALLOC_DECLARE(M_VERIEXEC);
88 1.44 elad
89 1.44 elad extern int veriexec_verbose;
90 1.44 elad extern int veriexec_strict;
91 1.35 elad
92 1.8 elad /* Readable values for veriexec_report(). */
93 1.34 elad #define REPORT_ALWAYS 0x01 /* Always print */
94 1.34 elad #define REPORT_VERBOSE 0x02 /* Print when verbose >= 1 */
95 1.34 elad #define REPORT_DEBUG 0x04 /* Print when verbose >= 2 (debug) */
96 1.34 elad #define REPORT_PANIC 0x08 /* Call panic() */
97 1.34 elad #define REPORT_ALARM 0x10 /* Alarm - also print pid/uid/.. */
98 1.34 elad #define REPORT_LOGMASK (REPORT_ALWAYS|REPORT_VERBOSE|REPORT_DEBUG)
99 1.8 elad
100 1.44 elad void veriexecattach(struct device *, struct device *, void *);
101 1.44 elad int veriexecopen(dev_t, int, int, struct lwp *);
102 1.44 elad int veriexecclose(dev_t, int, int, struct lwp *);
103 1.44 elad int veriexecioctl(dev_t, u_long, caddr_t, int, struct lwp *);
104 1.11 elad
105 1.40 elad void veriexec_init(void);
106 1.44 elad int veriexec_fpops_add(const char *, size_t, size_t, veriexec_fpop_init_t,
107 1.44 elad veriexec_fpop_update_t, veriexec_fpop_final_t);
108 1.44 elad int veriexec_table_add(struct lwp *, prop_dictionary_t);
109 1.44 elad int veriexec_file_add(struct lwp *, prop_dictionary_t);
110 1.44 elad int veriexec_verify(struct lwp *, struct vnode *, const u_char *, int,
111 1.44 elad boolean_t *);
112 1.49 elad #ifdef notyet
113 1.49 elad int veriexec_page_verify(struct veriexec_file_entry *, struct vm_page *,
114 1.49 elad size_t, struct lwp *);
115 1.49 elad #endif /* notyet */
116 1.47 elad boolean_t veriexec_lookup(struct vnode *);
117 1.45 elad int veriexec_file_delete(struct vnode *);
118 1.45 elad int veriexec_table_delete(struct mount *);
119 1.45 elad int veriexec_convert(struct vnode *, prop_dictionary_t);
120 1.44 elad void veriexec_report(const u_char *, const u_char *, struct lwp *, int);
121 1.44 elad void veriexec_purge(struct vnode *);
122 1.38 elad int veriexec_removechk(struct vnode *, const char *, struct lwp *l);
123 1.38 elad int veriexec_renamechk(struct vnode *, const char *, struct vnode *,
124 1.38 elad const char *, struct lwp *);
125 1.44 elad int veriexec_unmountchk(struct mount *);
126 1.48 elad int veriexec_openchk(struct lwp *, struct vnode *, const char *, int);
127 1.14 elad #endif /* _KERNEL */
128 1.7 blymn
129 1.18 elad #endif /* !_SYS_VERIFIED_EXEC_H_ */
130