Skip to content

RFC Task watchers v2 Introduction

Matt Helsley linux-audit lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest10 patches 10 repliesIn review

Changes in v1 from the cover letter

Added ability to cause fork to fail with NOTIFY_STOP_MASK Added WARN_ON() when watchers cause WATCH_TASK_FREE to stop early Moved fork invocation
Moved exec invocation
Added current as argument to exec invocation
Moved exit code assignment
Added id change invocations

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10Task watchers v2 Task watchers v2fs/exec.c include/asm-generic/vmlinux.lds.h include/linux/task_watchers.h +5 more+114 -50 replies
2/10Task watchers v2 Benchmarkkernel/Makefile kernel/twbench.c lib/Kconfig.debug+116 -05 replies
3/10Task watchers v2 Register audit task watcherinclude/linux/audit.h kernel/auditsc.c kernel/exit.c +1 more+8 -160 replies
4/10Task watchers v2 Register semundo task watcherinclude/linux/sem.h ipc/sem.c kernel/exit.c +1 more+9 -270 replies
5/10Task watchers v2 Register cpuset task watcherinclude/linux/cpuset.h kernel/cpuset.c kernel/exit.c +1 more+6 -133 replies
6/10Task watchers v2 Register NUMA mempolicy task watcherkernel/exit.c kernel/fork.c mm/mempolicy.c+25 -180 replies
7/10Task watchers v2 Register IRQ flag tracing task watcherkernel/fork.c kernel/irq/handle.c+24 -190 replies
8/10Task watchers v2 Register lockdep task watcherkernel/fork.c kernel/lockdep.c+9 -50 replies
9/10Task watchers v2 Register process keyrings task watcherinclude/linux/key.h kernel/exit.c kernel/fork.c +2 more+13 -300 replies
10/10Task watchers v2 Register process events connectordrivers/connector/cn_proc.c fs/exec.c include/linux/cn_proc.h +3 more+37 -500 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC][PATCH 00/10] Task watchers v2 Introduction

This is version 2 of my Task Watchers patches.

Task watchers calls functions whenever a task forks, execs, changes its [re][ug]id, or exits.

Task watchers is primarily useful to existing kernel code as a means making the code in fork and exit more readable. Kernel code uses these paths by marking a function as a task watcher much like modules mark their init functions with module_init(). This reduces the code length and complexity of copy_process().

The first patch adds the basic infrastructure of task watchers: notification function calls in the various paths and a table of function pointers to be called. It uses an ELF section because parts of the table must be gathered from all over the kernel code and using the linker is easier than resolving and maintaining complex header interdependencies. An ELF table is also ideal because its read-only nature means that no locking nor list traversal are required.

Subsequent patches adapt existing parts of the kernel to use a task watcher
-- typically in the fork, clone, and exit paths:
audit
semundo
cpusets
mempolicy
trace irqflags
lockdep
keys (for processes -- not for thread groups)
process events connector

I'm working on three more patches that add support for creating a task watcher from within a module using an ELF section. I've not posted that work because it hasn't successfully booted much less completed the small selection of smoke tests I ran on these.

TODO:
Mark the task watcher table ELF section read-only. I've googled, read man pages, navigated the info pages, tried using PHDR, and according to the output of objdump, had no success. I'd really appreciate a pointer to an example showing what makes ld mark a kernel ELF section read-only.

Changes:
v2:
Dropped use of notifier chains
Dropped per-task watchers
Can be implemented on top of this
Still requires notifier chains
Dropped taskstats conversion
Parts of taskstats had to move away from the regions of copy_process() and do_exit() where task_watchers are notified
Used linker script mechanism suggested by Al Viro
Created one "list" of watchers per event as requested by Andrew Morton
No need to multiplex a single function call
Easier to static register/unregister watchers: 1 line of code val param now used for:
WATCH_TASK_INIT: clone_flags
WATCH_TASK_CLONE: clone_flags
WATCH_TASK_EXIT: exit code
WATCH_TASK_*: <unused>
Renamed notify_watchers() to notify_task_watchers()
Replaced: if (err != 0) --> if (err)
Added patches converting more "features" to use task watchers Added return code handling to WATCH_TASK_INIT
Return code handling elsewhere didn't seem appropriate since there was generally no response necessary
Fixed process keys free to handle failure in fork as originally coded
in copy_process
Added process keys code to watch for [er][ug]id changes

v1:
Added ability to cause fork to fail with NOTIFY_STOP_MASK Added WARN_ON() when watchers cause WATCH_TASK_FREE to stop early Moved fork invocation
Moved exec invocation
Added current as argument to exec invocation
Moved exit code assignment
Added id change invocations
v0:
Based on Jes Sorensen's Task Notifiers patches

Cheers,
-Matt Helsley
--

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV