1 /* 2 * $FreeBSD$ 3 * 4 * Copyright (c) 2011, 2012, 2013, 2015, 2016, Juniper Networks, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _SECURITY_MAC_VERIEXEC_INTERNAL_H 30 #define _SECURITY_MAC_VERIEXEC_INTERNAL_H 31 32 #ifndef _KERNEL 33 #error "no user-serviceable parts inside" 34 #endif 35 36 #include <sys/queue.h> 37 #include <sys/malloc.h> 38 #include <sys/sysctl.h> 39 40 #define MAC_VERIEXEC_FULLNAME "MAC/veriexec" 41 42 #define VERIEXEC_FILES_FIRST 1 43 44 #if defined(VERIFIED_EXEC_DEBUG) || defined(VERIFIED_EXEC_DEBUG_VERBOSE) 45 # define VERIEXEC_DEBUG(n, x) if (mac_veriexec_debug > (n)) printf x 46 #else 47 # define VERIEXEC_DEBUG(n, x) 48 #endif 49 50 struct mac_veriexec_file_info 51 { 52 int flags; 53 long fileid; 54 unsigned long gen; 55 struct mac_veriexec_fpops *ops; 56 unsigned char fingerprint[MAXFINGERPRINTLEN]; 57 LIST_ENTRY(mac_veriexec_file_info) entries; 58 }; 59 60 MALLOC_DECLARE(M_VERIEXEC); 61 62 SYSCTL_DECL(_security_mac_veriexec); 63 64 struct cred; 65 struct image_params; 66 struct proc; 67 struct sbuf; 68 struct thread; 69 struct ucred; 70 struct vattr; 71 struct vnode; 72 73 int mac_veriexec_metadata_fetch_fingerprint_status(struct vnode *vp, 74 struct vattr *vap, struct thread *td, int check_files); 75 int mac_veriexec_metadata_get_executable_flags(struct ucred *cred, 76 struct proc *p, int *flags, int check_files); 77 int mac_veriexec_metadata_get_file_flags(dev_t fsid, long fileid, 78 unsigned long gen, int *flags, int check_files); 79 void mac_veriexec_metadata_init(void); 80 void mac_veriexec_metadata_print_db(struct sbuf *sbp); 81 int mac_veriexec_metadata_unmounted(dev_t fsid, struct thread *td); 82 83 int mac_veriexec_fingerprint_add_ops(struct mac_veriexec_fpops *fpops); 84 85 int mac_veriexec_fingerprint_check_image(struct image_params *imgp, 86 int check_files, struct thread *td); 87 int mac_veriexec_fingerprint_check_vnode(struct vnode *vp, 88 struct mac_veriexec_file_info *ip, struct thread *td, 89 off_t file_size, unsigned char *fingerprint); 90 void mac_veriexec_fingerprint_init(void); 91 struct mac_veriexec_fpops * 92 mac_veriexec_fingerprint_lookup_ops(const char *type); 93 94 fingerprint_status_t 95 mac_veriexec_get_fingerprint_status(struct vnode *vp); 96 int mac_veriexec_get_state(void); 97 int mac_veriexec_in_state(int state); 98 void mac_veriexec_set_fingerprint_status(struct vnode *vp, 99 fingerprint_status_t fp_status); 100 void mac_veriexec_set_state(int state); 101 102 #endif /* !_SECURITY_MAC_VERIEXEC_INTERNAL_H */ 103