Home | History | Annotate | Line # | Download | only in sys
verified_exec.h revision 1.42
      1  1.42      elad /*	$NetBSD: verified_exec.h,v 1.42 2006/11/28 22:22:02 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.7     blymn #include <sys/hash.h>
     38  1.20      elad #include <uvm/uvm_extern.h>
     39  1.20      elad #include <uvm/uvm_pglist.h>
     40  1.20      elad #include <uvm/uvm_page.h>
     41   1.1     blymn 
     42  1.42      elad #include <prop/proplib.h>
     43  1.28      elad 
     44  1.24      elad /* Flags for a Veriexec entry. These can be OR'd together. */
     45  1.16      elad #define VERIEXEC_DIRECT		0x01 /* Direct execution (exec) */
     46  1.16      elad #define VERIEXEC_INDIRECT	0x02 /* Indirect execution (#!) */
     47  1.16      elad #define VERIEXEC_FILE		0x04 /* Plain file (open) */
     48  1.20      elad #define	VERIEXEC_UNTRUSTED	0x10 /* Untrusted storage */
     49   1.1     blymn 
     50  1.24      elad /* Operations for /dev/veriexec. */
     51  1.42      elad #define VERIEXEC_LOAD		_IOW('S', 0x1, struct plistref)
     52  1.42      elad #define VERIEXEC_TABLESIZE	_IOW('S', 0x2, struct plistref)
     53  1.42      elad #define VERIEXEC_DELETE		_IOW('S', 0x3, struct plistref)
     54  1.42      elad #define VERIEXEC_QUERY		_IOWR('S', 0x4, struct plistref)
     55   1.7     blymn 
     56   1.8      elad /* Verified exec sysctl objects. */
     57   1.8      elad #define	VERIEXEC_VERBOSE	1 /* Verbosity level. */
     58   1.8      elad #define	VERIEXEC_STRICT		2 /* Strict mode level. */
     59   1.8      elad #define	VERIEXEC_ALGORITHMS	3 /* Supported hashing algorithms. */
     60  1.10      elad #define	VERIEXEC_COUNT		4 /* # of fingerprinted files on device. */
     61   1.8      elad 
     62  1.28      elad /* Valid status field values. */
     63  1.28      elad #define FINGERPRINT_NOTEVAL  0  /* fingerprint has not been evaluated */
     64  1.28      elad #define FINGERPRINT_VALID    1  /* fingerprint evaluated and matches list */
     65  1.28      elad #define FINGERPRINT_NOMATCH  2  /* fingerprint evaluated but does not match */
     66  1.28      elad 
     67  1.28      elad /* Per-page fingerprint status. */
     68  1.28      elad #define	PAGE_FP_NONE	0	/* no per-page fingerprints. */
     69  1.28      elad #define	PAGE_FP_READY	1	/* per-page fingerprints ready for use. */
     70  1.28      elad #define	PAGE_FP_FAIL	2	/* mismatch in per-page fingerprints. */
     71  1.28      elad 
     72   1.7     blymn #ifdef _KERNEL
     73   1.7     blymn void	veriexecattach(struct device *, struct device *, void *);
     74  1.27      elad int     veriexecopen(dev_t, int, int, struct lwp *);
     75  1.27      elad int     veriexecclose(dev_t, int, int, struct lwp *);
     76  1.27      elad int     veriexecioctl(dev_t, u_long, caddr_t, int, struct lwp *);
     77   1.7     blymn 
     78   1.7     blymn /* defined in kern_verifiedexec.c */
     79   1.7     blymn extern char *veriexec_fp_names;
     80   1.8      elad extern int veriexec_verbose;
     81   1.8      elad extern int veriexec_strict;
     82  1.10      elad /* this one requires sysctl.h to be included before verified_exec.h */
     83  1.10      elad #ifdef VERIEXEC_NEED_NODE
     84  1.15      elad extern const struct sysctlnode *veriexec_count_node;
     85  1.10      elad #endif /* VERIEXEC_NEED_NODE */
     86  1.29      elad extern int veriexec_hook;
     87   1.7     blymn 
     88   1.1     blymn /*
     89   1.7     blymn  * Operations vector for verified exec, this defines the characteristics
     90   1.7     blymn  * for the fingerprint type.
     91  1.24      elad  * Function types: init, update, final.
     92   1.1     blymn  */
     93   1.7     blymn typedef void (*VERIEXEC_INIT_FN)(void *);
     94   1.7     blymn typedef void (*VERIEXEC_UPDATE_FN)(void *, u_char *, u_int);
     95   1.7     blymn typedef void (*VERIEXEC_FINAL_FN)(u_char *, void *);
     96   1.7     blymn 
     97   1.7     blymn struct veriexec_fp_ops {
     98  1.42      elad 	const char *type;
     99   1.7     blymn 	size_t hash_len;
    100   1.7     blymn 	size_t context_size;
    101   1.7     blymn 	VERIEXEC_INIT_FN init;
    102   1.7     blymn 	VERIEXEC_UPDATE_FN update;
    103   1.7     blymn 	VERIEXEC_FINAL_FN final;
    104   1.7     blymn 	LIST_ENTRY(veriexec_fp_ops) entries;
    105   1.7     blymn };
    106   1.1     blymn 
    107  1.29      elad /* Veriexec per-file entry data. */
    108  1.29      elad struct veriexec_file_entry {
    109  1.29      elad 	u_char type;				/* Entry type. */
    110  1.29      elad 	u_char status;				/* Evaluation status. */
    111  1.29      elad 	u_char page_fp_status;			/* Per-page FP status. */
    112  1.29      elad 	u_char *fp;				/* Fingerprint. */
    113  1.29      elad 	void *page_fp;				/* Per-page fingerprints */
    114  1.29      elad 	size_t npages;			    	/* Number of pages. */
    115  1.29      elad 	size_t last_page_size;			/* To support < PAGE_SIZE */
    116  1.29      elad 	struct veriexec_fp_ops *ops;		/* Fingerprint ops vector*/
    117  1.29      elad };
    118  1.29      elad 
    119  1.29      elad /* Veriexec per-table data. */
    120  1.29      elad struct veriexec_table_entry {
    121  1.29      elad 	uint64_t vte_count;			/* Number of Veriexec entries. */
    122  1.29      elad 	const struct sysctlnode *vte_node;
    123   1.1     blymn };
    124   1.1     blymn 
    125  1.35      elad /* Veriexec modes (strict levels). */
    126  1.35      elad #define	VERIEXEC_LEARNING	0	/* Learning mode. */
    127  1.35      elad #define	VERIEXEC_IDS		1	/* Intrusion detection mode. */
    128  1.36    dogcow #define	VERIEXEC_IPS		2	/* Intrusion prevention mode. */
    129  1.35      elad #define	VERIEXEC_LOCKDOWN	3	/* Lockdown mode. */
    130  1.35      elad 
    131   1.8      elad /* Readable values for veriexec_report(). */
    132  1.34      elad #define	REPORT_ALWAYS		0x01	/* Always print */
    133  1.34      elad #define	REPORT_VERBOSE		0x02	/* Print when verbose >= 1 */
    134  1.34      elad #define	REPORT_DEBUG		0x04	/* Print when verbose >= 2 (debug) */
    135  1.34      elad #define	REPORT_PANIC		0x08	/* Call panic() */
    136  1.34      elad #define	REPORT_ALARM		0x10	/* Alarm - also print pid/uid/.. */
    137  1.34      elad #define	REPORT_LOGMASK		(REPORT_ALWAYS|REPORT_VERBOSE|REPORT_DEBUG)
    138   1.8      elad 
    139  1.11      elad /* Initialize a fingerprint ops struct. */
    140  1.11      elad #define	VERIEXEC_OPINIT(ops, fp_type, hashlen, ctx_size, init_fn, \
    141  1.11      elad 	update_fn, final_fn) \
    142  1.42      elad 	do {								\
    143  1.42      elad 		(ops)->type = fp_type;					\
    144  1.42      elad 		(ops)->hash_len = (hashlen);				\
    145  1.42      elad 		(ops)->context_size = (ctx_size);			\
    146  1.42      elad 		(ops)->init = (VERIEXEC_INIT_FN) (init_fn);		\
    147  1.42      elad 		(ops)->update = (VERIEXEC_UPDATE_FN) (update_fn);	\
    148  1.42      elad 		(ops)->final = (VERIEXEC_FINAL_FN) (final_fn);		\
    149  1.11      elad 	} while (0);
    150  1.11      elad 
    151  1.11      elad int veriexec_add_fp_ops(struct veriexec_fp_ops *);
    152  1.40      elad void veriexec_init(void);
    153  1.42      elad struct veriexec_fp_ops *veriexec_find_ops(const char *name);
    154  1.32      elad int veriexec_fp_calc(struct lwp *, struct vnode *, struct veriexec_file_entry *,
    155  1.32      elad     u_char *);
    156  1.12      elad int veriexec_fp_cmp(struct veriexec_fp_ops *, u_char *, u_char *);
    157  1.29      elad struct veriexec_table_entry *veriexec_tblfind(struct vnode *);
    158  1.29      elad struct veriexec_file_entry *veriexec_lookup(struct vnode *);
    159  1.29      elad int veriexec_hashadd(struct vnode *, struct veriexec_file_entry *);
    160  1.29      elad int veriexec_verify(struct lwp *, struct vnode *,
    161  1.30      elad     const u_char *, int, struct veriexec_file_entry **);
    162  1.32      elad int veriexec_page_verify(struct veriexec_file_entry *, struct vm_page *, size_t,
    163  1.32      elad     struct lwp *);
    164  1.38      elad int veriexec_removechk(struct vnode *, const char *, struct lwp *l);
    165  1.38      elad int veriexec_renamechk(struct vnode *, const char *, struct vnode *,
    166  1.38      elad     const char *, struct lwp *);
    167  1.34      elad void veriexec_report(const u_char *, const u_char *, struct lwp *, int);
    168  1.29      elad void veriexec_clear(void *, int);
    169  1.39  christos void veriexec_purge(struct veriexec_file_entry *);
    170   1.1     blymn 
    171  1.14      elad #endif /* _KERNEL */
    172   1.7     blymn 
    173  1.18      elad #endif /* !_SYS_VERIFIED_EXEC_H_ */
    174