aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/filemon
Commit message (Collapse)AuthorAgeFilesLines
* machine/stdarg.h -> sys/stdarg.hBrooks Davis2025-06-111-2/+1
| | | | | | | | | | | | | Switch to using sys/stdarg.h for va_list type and va_* builtins. Make an attempt to insert the include in a sensible place. Where style(9) was followed this is easy, where it was ignored, aim for the first block of sys/*.h headers and don't get too fussy or try to fix other style bugs. Reviewed by: imp Exp-run by: antoine (PR 286274) Pull Request: https://github.com/freebsd/freebsd-src/pull/1595
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-271-1/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-162-4/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-123-3/+3
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* filemon: Reject FILEMON_SET_FD commands when the fd is a kqueueMark Johnston2022-02-031-5/+15
| | | | | | | | | | | | | When FILEMON_SET_FD is used, the filemon handle effectively wraps the passed file. In particular, the handle may be inherited by a child process, or transferred over a unix domain socket, so we must verify that the backing file permits this. Reported by: syzbot+36e6be9e02735fe66ca8@syzkaller.appspotmail.com Reviewed by: emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34128
* Convert remaining cap_rights_init users to cap_rights_init_oneMateusz Guzik2021-01-121-1/+1
| | | | | | | | | | | | | semantic patch: @@ expression rights, r; @@ - cap_rights_init(&rights, r) + cap_rights_init_one(&rights, r)
* cache: drop the always curthread argument from reverse lookup routinesMateusz Guzik2020-08-241-2/+1
| | | | | | | | | Note VOP_VPTOCNP keeps getting it as temporary compatibility for zfs. Tested by: pho Notes: svn path=/head/; revision=364633
* Remove unused argument to priv_check_cred.Mateusz Guzik2018-12-111-2/+1
| | | | | | | | | | | | | | | | Patch mostly generated with cocinnelle: @@ expression E1,E2; @@ - priv_check_cred(E1,E2,0) + priv_check_cred(E1,E2) Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341827
* Add const to input-only char * arguments.Brooks Davis2018-11-021-2/+4
| | | | | | | | | | | | | | | | These arguments are mostly paths handled by NAMEI*() macros which already take const char * arguments. This change improves the match between syscalls.master and the public declerations of system calls. Reviewed by: kib (prior version) Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D17812 Notes: svn path=/head/; revision=340080
* Fix some filemon path logging issues.Bryan Drewery2018-08-032-49/+36
| | | | | | | | | | | | | | | | | | | - Properly handle snprintf return value for truncation and avoid overflowing the later write with the bogus length. - Increase the msgbufr size to handle a rename of 2 full files. The larger allocation causes a slight performance hit which will be mitigated in the future. A rewrite with sbufs will likely be done as well. Reported by: Ilja Van Sprundel <ivansprundel@ioactive.com> MFC after: 2 weeks Approved by: so (gtetlow) Reviewed by: kib Sponsored by: Dell EMC Differential Revision: https://reviews.freebsd.org/D16098 Notes: svn path=/head/; revision=337272
* Eliminate the overhead of gratuitous repeated reinitialization of cap_rightsMatt Macy2018-05-091-2/+1
| | | | | | | | | | | | | | | - Add macros to allow preinitialization of cap_rights_t. - Convert most commonly used code paths to use preinitialized cap_rights_t. A 3.6% speedup in fstat was measured with this change. Reported by: mjg Reviewed by: oshogbo Approved by: sbruno MFC after: 1 month Notes: svn path=/head/; revision=333425
* Move most of the contents of opt_compat.h to opt_global.h.Brooks Davis2018-04-062-4/+0
| | | | | | | | | | | | | | | | | | | | | opt_compat.h is mentioned in nearly 180 files. In-progress network driver compabibility improvements may add over 100 more so this is closer to "just about everywhere" than "only some files" per the guidance in sys/conf/options. Keep COMPAT_LINUX32 in opt_compat.h as it is confined to a subset of sys/compat/linux/*.c. A fake _COMPAT_LINUX option ensure opt_compat.h is created on all architectures. Move COMPAT_LINUXKPI to opt_dontuse.h as it is only used to control the set of compiled files. Reviewed by: kib, cem, jhb, jtl Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D14941 Notes: svn path=/head/; revision=332122
* sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-273-0/+6
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326255
* Avoid taking PROC_LOCK in syscalls if not being traced.Bryan Drewery2016-08-121-0/+2
| | | | | | | | MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=304008
* Cleanup COMPAT_FREEBSD32 support.Bryan Drewery2016-06-052-14/+6
| | | | | | | | | | | | | | | | | This is a NOP. The COMPAT_IA32 was renamed in r205014 to COMPAT_FREEBSD32 and COMPAT_ARCH32 does not seem to have existed. Also remove some leftovers from the sysent rework in r301404. Include freebsd32_util.h for the freebsd32_sysent prototype. X-MFC-With: r301404 Reported by: kib MFC after: 3 days Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=301460
* Fix build after r301404.Bryan Drewery2016-06-041-0/+4
| | | | | | | | X-MFC-With: r301404 MFC after: 1 week Notes: svn path=/head/; revision=301414
* Support all architectures by just using sysent.Bryan Drewery2016-06-041-48/+35
| | | | | | | | | | | | PowerPC64 has two different ABIs, neither of which is elf64_freebsd_sysvec. Using sysent and freebsd32_sysent achieves the same effect. X-MFC-With: r301130 MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=301404
* Don't truncate existing error when writing the log.Bryan Drewery2016-05-271-1/+1
| | | | | | | | | Suggested by: markj MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=300893
* Rename function to be less generic.Bryan Drewery2016-05-271-2/+2
| | | | | | | | MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=300892
* Write to the log using the tracer's credentials.Bryan Drewery2016-05-271-1/+1
| | | | | | | | MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=300891
* exec: Cease tracing if credentials will change with the new image.Bryan Drewery2016-05-272-3/+29
| | | | | | | | | | | | | | | | This also prevents tracing to a P_INEXEC process since it could race with other processes attaching to it in filemon_event_process_exec() due to the filemon_get_proc() race of incrementing ref and then locking the filemon. With the no-P_INEXEC invariant in place the p_filemon may only be the same or NULL when trying to drop it in filemon_event_process_exec(). MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D6545 Notes: svn path=/head/; revision=300890
* filemon exec: Use imgp->execpath rather than vn_fullpath(9).Bryan Drewery2016-05-261-9/+2
| | | | | | | | | | | This will be more accurate as the actual name is provided if ran from an absolute path in do_execve(). MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=300809
* Remove unneeded return left from refactoring.Bryan Drewery2016-03-251-2/+0
| | | | | | | | MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297256
* Handle copyin failures.Bryan Drewery2016-03-221-22/+39
| | | | | | | | | | | | | | | | | Skip the log entry as there is nothing good to write out. Don't fail the syscall though since it already succeeded. There's no reason filemon's tracing failure should fail the already-succeeded syscall. Record the error for later to return from close(2) on the filemon devfs file descriptor. Discussed with: markj, sjg, kib (briefly with kib) Reported by: mjg MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297203
* Remove unused done argument to copyinstr(9).Bryan Drewery2016-03-221-9/+5
| | | | | | | | MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297202
* Return any log write failure encountered when closing the filemon fd.Bryan Drewery2016-03-222-3/+26
| | | | | | | | | | Discussed with: sjg, markj Reviewed by: sjg MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297201
* Follow-up r297156: Close the log in filemon_dtr rather than in the last ↵Bryan Drewery2016-03-221-19/+34
| | | | | | | | | | | | | | | | | reference. If the tracer has decided to the close the log then it should be fully written, not getting more entries, when close(2) returns. This was a regression in r297156 in that it allowed a traced process to continue a traced syscall and add more entries to the log while the tracer had already closed its fd or exited. This was only really part of the daemonized process case which is abnormal. MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297200
* Consolidate common link(2) logic.Bryan Drewery2016-03-211-55/+26
| | | | | | | | MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297172
* Attempt to use the namecache for openat(2) path resolution.Bryan Drewery2016-03-211-6/+30
| | | | | | | | | | This finishes the work done in D2810. MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297161
* Use curthread for vn_fullpath.Bryan Drewery2016-03-211-2/+1
| | | | | | | | | | No functional change. MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297159
* Consolidate open(2) and openat(2) code.Bryan Drewery2016-03-211-67/+44
| | | | | | | | MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297158
* Stop tracking stat(2).Bryan Drewery2016-03-211-59/+0
| | | | | | | | | | | | | | | | | None of lstat(2), fstat(2), fstatat(2) were tracked either. The other filemon implementations also do not track stat(2), nor does bmake utilize it. The act of opening a file for read should be enough to decide that a file is a dependency. There could be rare cases where just having a file would cause a dependency but it is unlikely. MFC after: 2 weeks Also noted by: sjg Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297157
* Track filemon usage via a proc.p_filemon pointer rather than its own lists.Bryan Drewery2016-03-213-212/+293
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - proc.p_filemon is added which is protected by PROC_LOCK. This improves performance and avoids double-fork issues, taking allproc_lock while in syscalls, and walking the process tree in syscalls. A particular proc.p_filemon can only be changed to NULL or another filemon, or the filemon inherited, while the filemon->lock is held. - Filemon are reference counted. On the last reference the log will be closed. - When closing the devfs file handle, the filemon will be detached from all processes and inheritance prevented. - Disallow attaching to a process already being traced since filemon is typically intended to be used on children only. This is allowed for curproc as bmake relies on this behavior for rare cases when combining .MAKE with .META. - Detach any previously tracked process on ioctl(FILEMON_SET_PID). - Handle error from devfs_set_cdevpriv() in filemon_open(). - The global filemon lock and lists are removed. - A free list is no longer kept. Previously this list was forever-expanding and never garbage cleaned. - No longer loses track of double-forks. If the process holding the filemon handle closes it will close the log rather than wait on a daemonized process, but it will log all activity until it closes its handle. The filemon will be removed from the process and not inherited. - A separate process count is kept only as an optimization for forced detachment to avoid taking allproc_lock and walking the entire process tree. - struct filemon access is protected by sx(9) filemon->lock as it was before. - Add more comments and KASSERTS. MFC after: 2 weeks Reviewed by: kib, mjg, markj (all on previous versions) Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D5520 Notes: svn path=/head/; revision=297156
* FILEMON_SET_FD: Disallow changing the fd.Bryan Drewery2016-03-091-2/+4
| | | | | | | | | MFC after: 1 week Suggested by: mjg Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=296575
* Add missing break for r296472.Bryan Drewery2016-03-071-0/+1
| | | | | | | | | | This was lost in git rebasing, though it has no functional change. X-MFC-With: r296472 MFC after: 1 week Notes: svn path=/head/; revision=296473
* Require kldunload -f to unload.Bryan Drewery2016-03-071-2/+7
| | | | | | | | | | | | | Code may still be executing from the wrappers at unload time and thus is not generally safe to unload. Converting the wrappers to use EVENTHANDLER(9) will allow this to safely drain on active threads in hooks. More work on EVENTHANDLER(9) is needed first. MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=296472
* Only call bwillwrite() for logging to vnodes, as other fo_write() calls do.Bryan Drewery2016-03-071-1/+2
| | | | | | | | MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=296470
* Remove filemon->lock wrappers.Bryan Drewery2016-03-023-45/+18
| | | | | | | | MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=296286
* Remove old compatibility checks.Bryan Drewery2016-02-272-39/+1
| | | | | | | | MFC after: 3 days Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=296148
* Filemon: Fix panic when fork1() is called from kproc_create().Bryan Drewery2016-02-161-1/+1
| | | | | | | | MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=295649
* filemon: Track the process pointer rather than a pid.Bryan Drewery2016-01-292-7/+6
| | | | | | | | | | | | The process is not held since the process_exit hook is called after the exithold. There is no need to hold the process since the hook will always see it exiting via the process_exit event. MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=295027
* filemon_open: Don't record a process to trace here.Bryan Drewery2016-01-291-2/+1
| | | | | | | | | | Only ioctl(FILEMON_SET_PID) should be setting the process-to-be-traced. MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=295026
* filemon: Use process_exec EVENTHANDLER to capture sys_execve.Bryan Drewery2016-01-281-51/+23
| | | | | | | | MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=295017
* Follow-up r294967: Mark flags unused.Bryan Drewery2016-01-281-1/+1
| | | | | | | | | X-MFC-With: r294967 MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=294968
* filemon: Trace fork via process_fork event.Bryan Drewery2016-01-281-47/+14
| | | | | | | | | | | This avoids needing ugly hooks and needing both a vfork and fork handler. MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=294967
* filemon: Use process_exit EVENTHANDLER to capture process exit.Bryan Drewery2016-01-281-11/+12
| | | | | | | | | | | | This fixes some cases where a process could exit without being untracked by filemon. Reported by: mjg MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=294965
* filemon_dtr: Lock the associated filemon handle before writing to it.Bryan Drewery2016-01-271-2/+5
| | | | | | | | | Reported by: mjg MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=294957
* filemon_comment has nothing to do with wrappers so move it out of ↵Bryan Drewery2016-01-272-16/+16
| | | | | | | | | | | | | filemon_wrapper.c. It only prints the header from filemon_ioctl. Keep the name though to stay closer to other implementations. MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=294953
* filemon_ioctl: Lock the associated filemon handle before writing to it.Bryan Drewery2016-01-272-7/+3
| | | | | | | | | Reported by: mjg MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=294952