1 .\" $NetBSD: veriexec.9,v 1.21 2009/03/15 14:14:50 joerg Exp $
3 .\" Copyright 2006 Elad Efrat <elad@NetBSD.org>
4 .\" Copyright 2006 Brett Lymn <blymn@NetBSD.org>
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Brett Lymn and Elad Efrat
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Neither the name of The NetBSD Foundation nor the names of its
15 .\" contributors may be used to endorse or promote products derived
16 .\" from this software without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nd in-kernel file integrity subsystem KPI
37 .In sys/verified_exec.h
44 in-kernel file integrity subsystem.
45 It is responsible for managing the supported hashing algorithms, fingerprint
46 calculation and comparison, file monitoring tables, and relevant hooks to
51 .Bl -tag -width compact
52 .It Ft void Fn veriexec_init "void"
56 Called only once during system startup.
57 .It Ft "bool" Fn veriexec_lookup "struct vnode *vp"
68 .It Ft int Fn veriexec_verify "struct lwp *l" "struct vnode *vp" \
69 "const u_char *name" "int flag" "bool *found"
70 Verifies the digital fingerprint of
76 The access flag can be one of:
77 .Bl -tag -width VERIEXEC_INDIRECT
78 .It Dv VERIEXEC_DIRECT
79 The file was executed directly via
81 .It Dv VERIEXEC_INDIRECT
82 The file was executed indirectly, either as an interpreter for a script or
83 mapped to an executable memory region.
85 The file was opened for reading/writing.
89 is the LWP for the request context.
93 is a pointer to a boolean indicating whether an entry for the file was found
97 .It Ft void Fn veriexec_purge "struct vnode *vp"
98 Purge the file entry for
100 This invalidates the fingerprint so it will be evaluated next time the file
102 .\" veriexec_page_verify() intentionally not documented.
104 .Ss Fingerprint Related Routines
105 .Bl -tag -width compact
106 .It Ft int Fn veriexec_fpops_add "const char *fp_type" "size_t hash_len" \
107 "size_t ctx_size" "veriexec_fpop_init_t init" "veriexec_fpop_update_t update" \
108 "veriexec_fpop_final_t final"
109 Add support for fingerprinting algorithm
111 with binary hash length
113 and calculation context size
121 are the routines used to initialize, update, and finalize a calculation
124 .Ss Table Management Routines
125 .Bl -tag -width compact
126 .It Ft int Fn veriexec_file_add "struct lwp *l" \
127 "prop_dictionary_t dict"
130 entry for the file described by
134 is expected to have the following:
135 .Bl -column entry-type string "entry type flags (see veriexec(4))"
136 .It Sy Name Type Purpose
137 .It file string filename
138 .It entry-type uint8 entry type flags ( see Xr veriexec 4 )
139 .It fp-type string fingerprint hashing algorithm
140 .It fp data the fingerprint
142 .It Ft int Fn veriexec_file_delete "struct lwp *l" "struct vnode *vp"
147 .It Ft int Fn veriexec_table_delete "struct lwp *l" "struct mount *mp"
150 table for mount-point
152 .It Ft int Fn veriexec_flush "struct lwp *l"
158 .Bl -tag -width compact
159 .It Ft int Fn veriexec_openchk "struct lwp *l" "struct vnode *vp" \
160 "const char *path" "int fmode"
161 Called when a file is opened.
164 is the LWP opening the file,
166 is a vnode for the file being opened as returned from
170 the file is being created.
172 is the pathname for the file (not necessarily a full path), and
174 are the mode bits with which the file was opened.
175 .It Ft int Fn veriexec_renamechk "struct lwp *l" "struct vnode *fromvp" \
176 "const char *fromname" "struct vnode *tovp" "const char *toname"
177 Called when a file is renamed.
182 are the vnode and filename of the file being renamed.
186 are the vnode and filename of the target file.
188 is the LWP renaming the file.
190 Depending on the strict level,
192 will either track changes appropriately or prevent the rename.
193 .It Ft int Fn veriexec_removechk "struct lwp *l" "struct vnode *vp" \
195 Called when a file is removed.
198 is the vnode of the file being removed, and
202 is the LWP removing the file,
204 Depending on the strict level,
206 will either clean-up after the file or prevent its removal.
207 .It Ft int Fn veriexec_unmountchk "struct mount *mp"
208 Checks if the current strict level allows
212 .Ss Miscellaneous Routines
213 .Bl -tag -width compact
214 .It Ft int Fn veriexec_convert "struct vnode *vp" "prop_dictionary_t rdict"
223 with the following elements:
224 .Bl -column entryxtype string
225 .It Sy Name Type Purpose
226 .It entry-type uint8 entry type flags ( see Xr veriexec 4 )
227 .It status uint8 entry status ( see below )
228 .It fp-type string fingerprint hashing algorithm
229 .It fp data the fingerprint
234 can be one of the following:
235 .Bl -column fingerprintxmismatch effect
236 .It Sy Status Meaning
237 .It FINGERPRINT_NOTEVAL not evaluated
238 .It FINGERPRINT_VALID fingerprint match
239 .It FINGERPRINT_MISMATCH fingerprint mismatch
242 If no entry was found,
246 .It Ft int Fn veriexec_dump "struct lwp *l" "prop_array_t rarray"
249 with entries for all files monitored by
251 that have a filename associated with them.
255 is a dictionary with the same elements as filled by
256 .Fn veriexec_convert ,
257 with an additional field,
259 containing the filename.
262 .Bl -column srcxsysxkernxkernxverifiedexecxc foo
264 .It src/sys/dev/verified_exec.c driver for userland communication
265 .It src/sys/sys/verified_exec.h shared (userland/kernel) header file
266 .It src/sys/kern/kern_verifiedexec.c subsystem code
267 .It src/sys/kern/vfs_syscalls.c rename, remove, and unmount policies
268 .It src/sys/kern/vfs_vnops.c regular file access policy
280 .An Brett Lymn Aq blymn@NetBSD.org
281 .An Elad Efrat Aq elad@NetBSD.org
283 There are two known issues with
285 that should be considered when using it.
286 .Ss Remote File-systems
287 There is an issue providing protection for files residing on mounts from
289 Because access to the file-system does not necessarily go through
291 there is no way to track on-disk changes.
292 While it is possible to minimize the effect by evaluating the file's
293 fingerprint on each access without caching the result, a problem arises when
294 a file is overwritten after its fingerprint has been evaluated and it is
295 running on the local host.
297 An attacker could potentially overwrite the file contents in the remote host
298 at that point, and force a flush on the local host, resulting in paging in
299 of the files from the disk, introducing malicious code into a supposedly
302 There is a fix for this issue, however due to dependencies on other work
303 that is still in progress it has not been committed yet.
304 .Ss Layered File-systems
305 Due to VFS limitations,
307 cannot track the same on-disk file across multiple layers of overlay
309 Therefore, you cannot expect changes to files on overlay mounts will be
310 detected simply because the underlying mount is monitored by
313 A workaround for this issue is listing all files, under all mounts, you want
314 monitored in the signature file.