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