Commit Graph

124 Commits

Author SHA1 Message Date
christos 27ec421326 fix sysctl again. 2011-01-08 20:29:13 +00:00
christos 7e1e338bd2 Simplify and avoid kernel segv when the list is NULL. 2011-01-02 20:50:55 +00:00
dholland 06a95d4af1 typo in comment 2010-11-17 20:07:50 +00:00
elad ac90530da8 In veriexec_file_verify(), always check 'lockstate' before unlocking
'veriexec_op_lock'. Triggering a panic is possible in the path from
veriexec_openchk() (easily repeatable). The two switch cases at the
bottom of the function are going to panic anyway, but they might as well
panic as they're intended to as opposed to tripping over a locking
violation...
2009-12-28 07:16:41 +00:00
elad fa8206aeb0 Our error paths can call veriexec_file_free(), whicn in turn will try to
rw_destroy() the vfe lock. The easiest way to fix it for now is simply to
initialize the lock right after allocating the vfe...
2009-12-28 02:35:20 +00:00
elad d67e78d45a Only kmem_free() the filename if we have one. 2009-12-25 22:57:54 +00:00
cegger 9480c51b04 Add a flags argument to pmap_kenter_pa(9).
Patch showed on tech-kern@ http://mail-index.netbsd.org/tech-kern/2009/11/04/msg006434.html
No objections.
2009-11-07 07:27:40 +00:00
elad 756638cf95 Factor out a block of code that appears in three places (Veriexec, keylock,
and securelevel) so that others can use it as well.
2009-10-06 04:28:10 +00:00
elad 54d08ac134 Update a comment. No functional change. 2009-10-03 21:03:55 +00:00
dholland effcf1af5c Convert 67 namei call sites to use namei_simple, in these functions:
check_console, veriexecclose, veriexec_delete, veriexec_file_add,
emul_find_root, coff_load_shlib (sh3 version), coff_load_shlib,
compat_20_sys_statfs, compat_20_netbsd32_statfs,
ELFNAME2(netbsd32,probe_noteless), darwin_sys_statfs,
ibcs2_sys_statfs, ibcs2_sys_statvfs, linux_sys_uselib,
osf1_sys_statfs, sunos_sys_statfs, sunos32_sys_statfs,
ultrix_sys_statfs, do_sys_mount, fss_create_files (3 of 4),
adosfs_mount, cd9660_mount, coda_ioctl, coda_mount, ext2fs_mount,
ffs_mount, filecore_mount, hfs_mount, lfs_mount, msdosfs_mount,
ntfs_mount, sysvbfs_mount, udf_mount, union_mount, sys_chflags,
sys_lchflags, sys_chmod, sys_lchmod, sys_chown, sys_lchown,
sys___posix_chown, sys___posix_lchown, sys_link, do_sys_pstatvfs,
sys_quotactl, sys_revoke, sys_truncate, do_sys_utimes, sys_extattrctl,
sys_extattr_set_file, sys_extattr_set_link, sys_extattr_get_file,
sys_extattr_get_link, sys_extattr_delete_file,
sys_extattr_delete_link, sys_extattr_list_file, sys_extattr_list_link,
sys_setxattr, sys_lsetxattr, sys_getxattr, sys_lgetxattr,
sys_listxattr, sys_llistxattr, sys_removexattr, sys_lremovexattr

All have been scrutinized (several times, in fact) and compile-tested,
but not all have been explicitly tested in action.

XXX: While I haven't (intentionally) changed the use or nonuse of
XXX: TRYEMULROOT in any of these places, I'm not convinced all the
XXX: uses are correct; an audit might be desirable.
2009-06-29 05:08:15 +00:00
elad b1bd59c577 Fix locking around mountlist usage, as pointed out by ad@ in:
http://mail-index.netbsd.org/source-changes-d/2009/04/22/msg000322.html
  http://mail-index.netbsd.org/tech-kern/2009/04/22/msg004897.html

Use vfs_busy() and vfs_unbusy(), and properly iterate the mountlist.
2009-05-02 21:47:12 +00:00
elad d4cc1b437c PR/41251: YAMAMOTO Takashi: veriexec locking seems broken
Part 1: Take the mountlist_lock before traversing the mount list.
2009-04-20 22:09:54 +00:00
elad f4f1989ae8 PR/39559: Juan RP: veriexec(4): too easy to cause a NULL dereference
through it in kernel

Patch from PR applied with tiny modifications, thanks!

Discussed with blymn@ a while ago.
2008-12-14 23:20:23 +00:00
blymn 57614abcf2 Conditionalise bypass of veriexec routines on veriexec_strict to prevent
loophole if tables fail to load and strict is then raised.
2008-10-23 13:18:14 +00:00
blymn 6a3775d153 * Fix from Elad to correct a couple of places where functions exited
without releasing locks.
* Corrected a panic caused by veriexec_file_verify() not setting the
  returned struct veriexec_file_entry **vfep in all cases.

Thanks to Stathis Kamperis for finding the issues and testing the fixes.
2008-09-10 16:36:54 +00:00
blymn 762e875434 Add locking around veriexec operations to prevent all sorts of badness
happening.  This fixes kern/38646.
2008-07-20 08:50:20 +00:00
chris 2ff98bbc26 Add missing pmap_update(pmap_kernel()); calls after pmap_kenter_pa and
pmap_remove.
2008-02-23 16:05:17 +00:00
ad af6be237a6 Use vp->v_rdev. 2008-01-15 18:51:43 +00:00
elad 86f224903e Replace malloc/free usage with kmem_alloc/kmem_zalloc/kmem_free.
okay yamt@.
2008-01-03 17:51:05 +00:00
ad 4a780c9ae2 Merge vmlocking2 to head. 2008-01-02 11:48:20 +00:00
pooka db06a930e6 Remove cn_lwp from struct componentname. curlwp should be used
from on.  The NDINIT() macro no longer takes the lwp parameter and
associates the credentials of the calling thread with the namei
structure.
2007-12-08 19:29:36 +00:00
pooka 61e8303e9d Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start.  In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern
2007-11-26 19:01:26 +00:00
matt 11910619f7 Change some initialization of static queues to compile time.
(xxx_INIT to xxx_HEAD_INITIALIZER).  Drop code which inits
non-auto (global or static) variables to 0 since that's
already implied by being non-auto.  Init some static/global
cpu_simple_locks at compile time.
2007-11-11 23:22:23 +00:00
ad 88ab7da936 Merge some of the less invasive changes from the vmlocking branch:
- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
2007-07-09 20:51:58 +00:00
christos 09a50be501 - remove pathname_ interface.
- use macros to deal with pathnames in userspace, when veriexec is used.
- reorder the veriexec_ call arguments for consistency.
With help from elad@ finding the last bug.
2007-05-19 22:11:22 +00:00
elad 6700cfccd6 Some Veriexec stuff that's been rotting in my tree for months.
Bug fixes:
  - Fix crash reported by Scott Ellis on current-users@.

  - Fix race conditions in enforcing the Veriexec rename and remove
    policies. These are NOT security issues.

  - Fix memory leak in rename handling when overwriting a monitored
    file.

  - Fix table deletion logic.

  - Don't prevent query requests if not in learning mode.


KPI updates:
  - fileassoc_table_run() now takes a cookie to pass to the callback.

  - veriexec_table_add() was removed, it is now done internally. As a
    result, there's no longer a need for VERIEXEC_TABLESIZE.

  - veriexec_report() was removed, it is now internal.

  - Perform sanity checks on the entry type, and enforce default type
    in veriexec_file_add() rather than in veriexecctl.

  - Add veriexec_flush(), used to delete all Veriexec tables, and
    veriexec_dump(), used to fill an array with all Veriexec entries.


New features:
  - Add a '-k' flag to veriexecctl, to keep the filenames in the kernel
    database. This allows Veriexec to produce slightly more accurate
    logs under certain circumstances. In the future, this can be either
    replaced by vnode->pathname translation, or combined with it.

  - Add a VERIEXEC_DUMP ioctl, to dump the entire Veriexec database.
    This can be used to recover a database if the file was lost.
    Example usage:

        # veriexecctl dump > /etc/signatures

    Note that only entries with the filename kept (that is, were loaded
    with the '-k' flag) will be dumped.

    Idea from Brett Lymn.

  - Add a VERIEXEC_FLUSH ioctl, to delete all Veriexec entries. Sample
    usage:

        # veriexecctl flush

  - Add a 'veriexec_flags' rc(8) variable, and make its default have
    the '-k' flag. On systems using the default signatures file
    (generaetd from running 'veriexecgen' with no arguments), this will
    use additional 32kb of kernel memory on average.

  - Add a '-e' flag to veriexecctl, to evaluate the fingerprint during
    load. This is done automatically for files marked as 'untrusted'.


Misc. stuff:
  - The code for veriexecctl was massively simplified as a result of
    eliminating the need for VERIEXEC_TABLESIZE, and now uses a single
    pass of the signatures file, making the loading somewhat faster.

  - Lots of minor fixes found using the (still under development)
    Veriexec regression testsuite.

  - Some of the messages Veriexec prints were improved.

  - Various documentation fixes.


All relevant man-pages were updated to reflect the above changes.

Binary compatibility with existing veriexecctl binaries is maintained.
2007-05-15 19:47:43 +00:00
yamt ef47d5b67e - don't use veriexec_mountspecific_key uninitialized.
- fix weird "Veriexec: IDS mode, allowing unmount" messages.
2007-04-03 09:17:31 +00:00
thorpej 4f3d5a9cc0 TRUE -> true, FALSE -> false 2007-02-22 06:34:42 +00:00
thorpej 712239e366 Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
2007-02-21 22:59:35 +00:00
elad 119d4b5acd PR/35253: YAMAMOTO Takashi: fileassoc hash size problem
fileassoc_table_add() was removed from the KPI and made internal. From now
fileassoc(9) will manage the optimal table size internally.

Input from and okay yamt@.
2007-02-06 01:09:48 +00:00
elad 8ed50e44ae veriexec_file_delete() and veriexec_table_delete() now take 'struct lwp *'
too.
2007-01-11 16:24:47 +00:00
elad 4cc18ba6e8 Make 'veriexec_verbose' static. 2007-01-11 15:10:25 +00:00
elad d2e4f7167b Remove advertising clause from all of my stuff. 2007-01-09 12:49:36 +00:00
elad cf9d4bd6af Update copyright/license, okay blymn@ few days ago. 2007-01-07 13:55:17 +00:00
elad 2a32293a9f Make more things static. From halflife. 2007-01-03 18:32:11 +00:00
elad 8a4dd2d69d #if 0 -> #ifdef notyet, and no need to forward declare internal
data-structures anymore.
2006-12-31 12:07:16 +00:00
elad c5c6251521 Avoid TOCTOU in Veriexec by introducing veriexec_openchk() to enforce
the policy and using a single namei() call in vn_open().
2006-12-30 15:26:55 +00:00
elad 8657d4ffbb Veriexec should not explicitly allow anything (raw disk access). 2006-12-29 11:34:14 +00:00
elad 74409752fc Fix copy/paste error: Veriexec's sysctl setup routine was named after
PaX's.
2006-12-26 19:31:33 +00:00
elad ff39342b33 veriexec_lookup() should not return an internal data-structure, but rather
just a boolean value.
2006-12-26 07:50:40 +00:00
yamt e49bb7c765 - remove the fileassoc "tabledata" functionality. use mountspecific instead.
- make pax_segvguard_cb static.

tested and ok'ed by elad.
2006-12-23 08:35:43 +00:00
christos 80b162af27 fix kernel panic with veriexec and raidframe. 2006-12-20 01:51:48 +00:00
elad 711e88f6f4 Split handling of unmount in Veriexec, where veriexec_unmountchk() will do
the permission check only, and the removal of the table/entries will be
done by fileassoc(9) after a successful unmount.

Prompted by and okay yamt@.
2006-12-18 06:43:12 +00:00
elad aa4d8a2d6c PR/35252: YAMAMOTO Takashi: veriexec doesn't handle unmount
Call veriexec_table_delete() in the cases where we won't be failing the
unmount request.
2006-12-14 11:15:27 +00:00
elad 52944a66d2 entry-type is uint8 2006-12-14 05:15:33 +00:00
yamt b0a14e5934 - remove a static configuration, FILEASSOC_NHOOKS. do it dynamically instead.
- make fileassoc_t a pointer and remove FILEASSOC_INVAL.
- clean up kern_fileassoc.c.  unify duplicated code.
- unexport fileassoc_init using RUN_ONCE(9).
- plug memory leaks in fileassoc_file_delete and fileassoc_table_delete.
- always call callbacks, regardless of the value of the associated data.

ok'ed by elad.
2006-12-11 15:24:27 +00:00
elad 7a71c77e81 More cleaning... split veriexec_delete() to veriexec_file_delete() to
handle a single entry and veriexec_table_delete() to handle an entire
table. veriexec_convert() now takes a struct vnode *, and made
veriexec_table_lookup() take struct mount * (that's entirely internal
now).

Tested on amd64, built successfully on amd64, i386, sparc, and sparc64.
2006-11-30 16:53:47 +00:00
elad 3cd8d27403 Return 'error' in veriexec_unmountchk(), not always 0. 2006-11-30 13:42:46 +00:00
elad cc26e2da8f Make sure that memory freed as M_VERIEXEC was allocated with that type.
Pointed out by Jason Thorpe, thanks!
2006-11-30 01:42:21 +00:00
elad 0c67c581a5 Massive restructuring and cleanup of Veriexec, mainly in preparation
for work on some future functionality.

  - Veriexec data-structures are no longer exposed.

  - Thanks to using proplib for data passing now, the interface
    changes further to accomodate that.

    Introduce four new functions. First, veriexec_file_add(), to add
    a new file to be monitored by Veriexec, to replace both
    veriexec_load() and veriexec_hashadd(). veriexec_table_add(), to
    replace veriexec_newtable(), will be used to optimize hash table
    size (during preload), and finally, veriexec_convert(), to convert
    an internal entry to one userland can read.

  - Introduce veriexec_unmountchk(), to enforce Veriexec unmount
    policy. This cleans up a bit of code in kern/vfs_syscalls.c.

  - Rename veriexec_tblfind() with veriexec_table_lookup(), and make
    it static. More functions that became static: veriexec_fp_cmp(),
    veriexec_fp_calc().

  - veriexec_verify() no longer returns the entry as well, but just
    sets a boolean indicating whether an entry was found or not.

  - veriexec_purge() now takes a struct vnode *.

  - veriexec_add_fp_name() was merged into veriexec_add_fp_ops(), that
    changed its name to veriexec_fpops_add(). veriexec_find_ops() was
    also renamed to veriexec_fpops_lookup().

    Also on the fp-ops front, the three function types used to initialize,
    update, and finalize a hash context were renamed to
    veriexec_fpop_init_t, veriexec_fpop_update_t, and veriexec_fpop_final_t
    respectively.

  - Introduce a new malloc(9) type, M_VERIEXEC, and use it instead of
    M_TEMP, so we can tell exactly how much memory is used by Veriexec.

  - And, most importantly, whitespace and indentation nits.

Built successfuly for amd64, i386, sparc, and sparc64. Tested on amd64.
2006-11-30 01:09:47 +00:00