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