Commit Graph

38 Commits

Author SHA1 Message Date
pgoyette
4013b4c801 Take a reference on the (activity log) file itself, and not on the
descriptor.

Should fix PR kern/50627
2016-01-11 01:37:36 +00:00
pgoyette
c67d972cba When following process parent pointers, lock the new (parent) before
releasing the initial process.
2016-01-09 07:27:31 +00:00
pgoyette
2477c9d9f5 Don't release the proc_lock mutex until we're finished using the stuff
that the mutex protects (ie, the proc list and the entry we found in
the list).
2016-01-08 08:57:14 +00:00
dholland
d76306360c typo in debug print 2016-01-08 07:16:13 +00:00
pgoyette
4676dce1f0 KNF - blank line after (non-existant) declarations. No functional change. 2016-01-05 22:08:54 +00:00
pgoyette
9d416a60e6 Although not recommended, it is possible to include filemon(4) as a
built-in module.  If we do this, don't try to call devsw_attach() as
our device structures will already have been included via ioconf.[ch].

This avoids calling the init routine twice (once for CLASS_DRIVER and
then later for CLASS_ANY), which in turn avoids trying to initialize
an already initialized lock.
2016-01-05 09:37:11 +00:00
pgoyette
dd025ffd3b Be a bit more paranoid about hijacking (and restoring) syscall function
pointers.  Ensure that we have the correct "old" values before setting
new values, for both "intall" and "deinstall".

XXX This is NOT intended to encourage additional cases of hijacking!  If
XXX some other hijack feature ever gets committed, this code should be
XXX moved to (most likely) kern/kern_syscall.c.
2015-11-25 07:34:49 +00:00
pgoyette
5a91b3ef3b Add missing /* $NetBSD$ */ keyword 2015-11-24 01:05:50 +00:00
pgoyette
d511d03d04 finish previous - remove no-longer-used variables 2015-11-24 01:01:42 +00:00
pgoyette
8ed3d37d0b Remove the requirement that the target (tracked) process be a descendant
of the tracking process.  The call to kauth() should be sufficient to
address any security concerns.
2015-11-23 23:27:38 +00:00
pgoyette
6cf6af127d Clean up the error paths in filemon_ioctl(), making sure to release the
rw_lock before returning.  Avoids a "locking against myself" error
reported by Brad Harder.
2015-11-23 22:20:57 +00:00
pgoyette
76f6833566 Retrieve the pathname of the exec'd file before we call sys_execve().
We cannot rely on using copyinstr() to retrieve the pathname from
user mode after a successful exec, since the user mode address space
is no longer valid (and may not even be accessible).  This worked in
earlier code but was broken by rev 1.7.
2015-11-23 00:47:43 +00:00
pgoyette
28b908ec33 Fix return-code handling for execve and chdir wrappers.
Fixes PR kern/50309
2015-11-22 01:20:52 +00:00
pgoyette
eb9db23cbe If a second call to the SET_FD ioctl occurs, release the reference we
hold on the earlier outout file.
2015-11-21 07:45:30 +00:00
pgoyette
eab5fcbc7e The correct default return value from a module's xxx_modcmd() routine
is ENOTTY, not EOPNOTSUPP!  The former will allow the module to be
auto-unloaded, while the latter will prevent it.

Note that manual unloading of the filemon module is unaffected, as
that is controlled by actual usage of the module.
2015-11-21 03:34:28 +00:00
pgoyette
53ffed1b78 Ensure that the PID specified in the FILEMON_SET_PID ioctl() call
belongs to the caller or one of its descendants.
2015-11-20 02:58:19 +00:00
pgoyette
e0b2ceba2b Remove extra ')' (bad cut&paste) 2015-11-20 01:33:59 +00:00
pgoyette
77a2d6cbf8 Don't allow setting the PID-to-trace if the target has a non-native
emulation.
2015-11-20 01:21:05 +00:00
pgoyette
e019cfbdd6 Install wrapper functions only in native emulation.
(This also removes the dependency on curproc, which may not be available
at the time that built-in kernel modules are initialized.)
2015-11-20 01:16:04 +00:00
pgoyette
96cae660f4 Don't initialize twice. 2015-11-20 01:12:38 +00:00
dholland
1fbab01a93 More on PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers (I think) all the MI headers outside of external/ (and dist/).
2015-09-06 06:00:59 +00:00
christos
e7ae23fd9e include "ioconf.h" to get the 'void <driver>attach(int count);' prototype. 2015-08-20 14:40:16 +00:00
sjg
728c79547f Bump version due to openat 2015-06-17 02:17:00 +00:00
christos
3c2ff4444e staircase flattening police. 2015-06-15 19:45:31 +00:00
sjg
ad7adde11d Latest clang uses openat, filemon thus needs to handle it.
For the simple cases where path is absolute or dirfd is for cwd
we can handle this just like open.
For the remaining case we output an 'A' record to offer a clue that
a search for open dir is needed (earlier in the trace).
2015-06-15 18:11:36 +00:00
joerg
adac2d746a Improve wording. 2015-05-30 19:14:46 +00:00
christos
2d38ee4936 Avoid dereferencing NULL tp crashing the kernel (brad harder)
XXX: pullup 7
2015-05-21 12:00:59 +00:00
dholland
f9228f4225 Add d_discard to all struct cdevsw instances I could find.
All have been set to "nodiscard"; some should get a real implementation.
2014-07-25 08:10:31 +00:00
christos
2cd2c9ba7b remove a bunch of repetitive code by introducing filemon_printf. 2014-03-27 18:27:34 +00:00
dholland
a68f9396b6 Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
2014-03-16 05:20:22 +00:00
sjg
756a23da8b filemon_pid_check:
Avoid recursion, and hold a reader lock on p_reflock while we
check for filemon, and until we have p_pptr.

filemon_ioctl:
Do not allow FILEMON_SET_PID unless caller would be allowed
to ptrace the target pid.

filemon_wrapper_deinstall:
Do not touch syscalls if they no longer point to us, return EBUSY.

filemon_unload:
return EBUSY if filemon_wrapper_deinstall() fails.
2012-11-19 22:20:10 +00:00
sjg
7b6d7531a8 Install filemon.h 2012-06-20 21:38:26 +00:00
sjg
db4d363da5 Add the plumbing so one could compile filemon(4) into a kernel. 2011-10-15 00:23:08 +00:00
sjg
053773f1f4 For files opened O_RDWR, output an R record as well as W
so that clients that only care about files read can ignore W.
Bump version.
2011-09-24 18:08:15 +00:00
sjg
98cc584599 Set FILEMON_VERSION to 3 2011-07-04 23:37:30 +00:00
rmind
3c66f2d262 filemon_open: remove unnecessary check (which has a leak in error path). 2011-05-13 22:31:08 +00:00
sjg
a864846b25 EJUSTRETURN is expected return from sys_execve() 2011-03-13 21:26:31 +00:00
sjg
ce171c67f4 First cut of simple syscall wrapper, which make(1) can use
to track process activity.
2010-09-09 00:10:16 +00:00