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