add task handling notifier: connector based proc events
Subsystems (5)
PATCH 3/4 add task handling notifier: connector based proc events
This has the additional benefit of allowing the code to now be built as a module (which made it necessary to add MODULE_xxx declarations).
Signed-off-by Jan Beulich <[email protected]>
Cc Matt Helsley <[email protected]>
--- drivers/connector/Kconfig | 5 +-- drivers/connector/cn_proc.c | 57 ++++++++++++++++++++++++++++++++++++++++---- fs/exec.c | 5 ++- include/linux/cn_proc.h | 21 ---------------- include/linux/sched.h | 4 +++ kernel/exit.c | 5 ++- kernel/fork.c | 2 - kernel/sys.c | 27 +++++++++++++------- 8 files changed, 83 insertions(+), 43 deletions(-)
drivers/connector/Kconfig +2 -3
@@ -12,9 +12,8 @@ menuconfig CONNECTOR if CONNECTOR config PROC_EVENTS - boolean "Report process events to userspace" - depends on CONNECTOR=y - default y + tristate "Report process events to userspace" + default CONNECTOR ---help--- Provide a connector that reports process events to userspace. Send events such as fork, exec, id change (uid, gid, suid, etc), and exit.
drivers/connector/cn_proc.c +53 -4
106 lines not on this page · raw message
fs/exec.c +3 -2
@@ -49,7 +49,7 @@#include <linux/syscalls.h> #include <linux/rmap.h> #include <linux/tsacct_kern.h> -#include <linux/cn_proc.h> +#include <linux/notifier.h> #include <linux/audit.h> #include <asm/uaccess.h>
@@ -1253,7 +1253,8 @@ int search_binary_handler(struct linux_bfput (bprm->file); bprm->file =NULL ; current->did_exec =1 ; -proc_exec_connector (current); +blocking_notifier_call_chain (&task_notifier_list, +TASK_EXEC , current);return retval; }read_lock (&binfmt_lock);
include/linux/cn_proc.h +0 -21
@@ -97,25 +97,4 @@ struct proc_event { } event_data; }; -#ifdef __KERNEL__ -#ifdef CONFIG_PROC_EVENTS -void proc_fork_connector (struct task_struct *task); -void proc_exec_connector (struct task_struct *task); -void proc_id_connector (struct task_struct *task,int which_id); -void proc_exit_connector (struct task_struct *task); -#else -static inline void proc_fork_connector (struct task_struct *task) -{} - -static inline void proc_exec_connector (struct task_struct *task) -{} - -static inline void proc_id_connector (struct task_struct *task, -int which_id) -{} - -static inline void proc_exit_connector (struct task_struct *task) -{} -#endif /* CONFIG_PROC_EVENTS */ -#endif /* __KERNEL__ */ #endif /* CN_PROC_H */
include/linux/sched.h +4 -0
@@ -1702,6 +1702,10 @@ struct task_struct *fork_idle(int);#define TASK_NEW 1#define TASK_DELETE 2 +#define TASK_EXEC 3 +#define TASK_EXIT 4 +#define TASK_UID_CHANGE 5 +#define TASK_GID_CHANGE 6extern struct blocking_notifier_head task_notifier_list;extern struct atomic_notifier_head atomic_task_notifier_list;
kernel/exit.c +3 -2
@@ -35,7 +35,7 @@#include <linux/syscalls.h> #include <linux/signal.h> #include <linux/posix-timers.h> -#include <linux/cn_proc.h> +#include <linux/notifier.h> #include <linux/mutex.h> #include <linux/futex.h> #include <linux/compat.h>
@@ -747,6 +747,8 @@ static void exit_notify(struct task_strustruct task_struct *t;struct pid *pgrp; +blocking_notifier_call_chain (&task_notifier_list,TASK_EXIT , tsk); +if (signal_pending (tsk) && !(tsk->signal->flags &SIGNAL_GROUP_EXIT ) && !thread_group_empty (tsk)) {/*
@@ -1009,7 +1011,6 @@ fastcall NORET_TYPE void do_exit(long coif (tsk->binfmt)module_put (tsk->binfmt->module); -proc_exit_connector (tsk);exit_notify (tsk);#ifdef CONFIG_NUMA mpol_free (tsk->mempolicy);
kernel/fork.c +0 -2
@@ -44,7 +44,6 @@#include <linux/rmap.h> #include <linux/acct.h> #include <linux/tsacct_kern.h> -#include <linux/cn_proc.h> #include <linux/freezer.h> #include <linux/notifier.h> #include <linux/taskstats_kern.h>
@@ -1316,7 +1315,6 @@ static struct task_struct *copy_process( total_forks++;spin_unlock (¤t->sighand->siglock);write_unlock_irq (&tasklist_lock); -proc_fork_connector (p);cgroup_post_fork (p);return p;
kernel/sys.c +18 -9
@@ -28,7 +28,6 @@#include <linux/suspend.h> #include <linux/tty.h> #include <linux/signal.h> -#include <linux/cn_proc.h> #include <linux/getcpu.h> #include <linux/task_io_accounting_ops.h> #include <linux/seccomp.h>
@@ -519,7 +518,9 @@ asmlinkage long sys_setregid(gid_t rgid, current->egid = new_egid; current->gid = new_rgid;key_fsgid_changed (current); -proc_id_connector (current,PROC_EVENT_GID ); +blocking_notifier_call_chain (&task_notifier_list, +TASK_GID_CHANGE , current); +return 0 ; }
@@ -554,7 +555,9 @@ asmlinkage long sys_setgid(gid_t gid)return -EPERM ;key_fsgid_changed (current); -proc_id_connector (current,PROC_EVENT_GID ); +blocking_notifier_call_chain (&task_notifier_list, +TASK_GID_CHANGE , current); +return 0 ; }
@@ -642,7 +645,8 @@ asmlinkage long sys_setreuid(uid_t ruid, current->fsuid = current->euid;key_fsuid_changed (current); -proc_id_connector (current,PROC_EVENT_UID ); +blocking_notifier_call_chain (&task_notifier_list, +TASK_UID_CHANGE , current);return security_task_post_setuid (old_ruid, old_euid, old_suid,LSM_SETID_RE ); }
@@ -689,7 +693,8 @@ asmlinkage long sys_setuid(uid_t uid) current->suid = new_suid;key_fsuid_changed (current); -proc_id_connector (current,PROC_EVENT_UID ); +blocking_notifier_call_chain (&task_notifier_list, +TASK_UID_CHANGE , current);return security_task_post_setuid (old_ruid, old_euid, old_suid,LSM_SETID_ID ); }
@@ -737,7 +742,8 @@ asmlinkage long sys_setresuid(uid_t ruid current->suid = suid;key_fsuid_changed (current); -proc_id_connector (current,PROC_EVENT_UID ); +blocking_notifier_call_chain (&task_notifier_list, +TASK_UID_CHANGE , current);return security_task_post_setuid (old_ruid, old_euid, old_suid,LSM_SETID_RES ); }
@@ -789,7 +795,8 @@ asmlinkage long sys_setresgid(gid_t rgid current->sgid = sgid;key_fsgid_changed (current); -proc_id_connector (current,PROC_EVENT_GID ); +blocking_notifier_call_chain (&task_notifier_list, +TASK_GID_CHANGE , current);return 0 ; }
@@ -830,7 +837,8 @@ asmlinkage long sys_setfsuid(uid_t uid) }key_fsuid_changed (current); -proc_id_connector (current,PROC_EVENT_UID ); +blocking_notifier_call_chain (&task_notifier_list, +TASK_UID_CHANGE , current);security_task_post_setuid (old_fsuid, (uid_t)-1 , (uid_t)-1 ,LSM_SETID_FS );
@@ -857,7 +865,8 @@ asmlinkage long sys_setfsgid(gid_t gid) } current->fsgid = gid;key_fsgid_changed (current); -proc_id_connector (current,PROC_EVENT_GID ); +blocking_notifier_call_chain (&task_notifier_list, +TASK_GID_CHANGE , current); }return old_fsgid; }