From: Matt Helsley <matthltc@us.ibm.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Linux-Kernel <linux-kernel@vger.kernel.org>,
Jes Sorensen <jes@sgi.com>,
LSE-Tech <lse-tech@lists.sourceforge.net>,
Chandra S Seetharaman <sekharan@us.ibm.com>,
Alan Stern <stern@rowland.harvard.edu>,
John T Kohl <jtk@us.ibm.com>, Balbir Singh <balbir@in.ibm.com>,
Shailabh Nagar <nagar@watson.ibm.com>,
Guillaume Thouvenin <guillaume.thouvenin@bull.net>
Subject: [PATCH 02/11] Task watchers: Register process events task watcher
Date: Tue, 13 Jun 2006 16:54:33 -0700 [thread overview]
Message-ID: <1150242874.21787.142.camel@stark> (raw)
In-Reply-To: 20060613235122.130021000@localhost.localdomain
This patch makes process events utilize task watchers instead of calling from
fork, exec, exit, and [re][ug]id changes directly.
Signed-off-by: Matt Helsley <matthltc@us.ibm.com>
Cc: Guillaume Thouvenin <guillaume.thouvenin@bull.net>
--
drivers/connector/cn_proc.c | 65 +++++++++++++++++++++++++++++++++++++-------
fs/exec.c | 2 -
include/linux/cn_proc.h | 22 --------------
kernel/exit.c | 2 -
kernel/fork.c | 7 +---
kernel/sys.c | 8 -----
6 files changed, 57 insertions(+), 49 deletions(-)
Index: linux-2.6.17-rc6-mm2/drivers/connector/cn_proc.c
===================================================================
--- linux-2.6.17-rc6-mm2.orig/drivers/connector/cn_proc.c
+++ linux-2.6.17-rc6-mm2/drivers/connector/cn_proc.c
@@ -25,10 +25,11 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/ktime.h>
#include <linux/init.h>
#include <linux/connector.h>
+#include <linux/notifier.h>
#include <asm/atomic.h>
#include <linux/cn_proc.h>
#define CN_PROC_MSG_SIZE (sizeof(struct cn_msg) + sizeof(struct proc_event))
@@ -44,11 +45,11 @@ static inline void get_seq(__u32 *ts, in
*ts = get_cpu_var(proc_event_counts)++;
*cpu = smp_processor_id();
put_cpu_var(proc_event_counts);
}
-void proc_fork_connector(struct task_struct *task)
+static void proc_fork_connector(struct task_struct *task)
{
struct cn_msg *msg;
struct proc_event *ev;
__u8 buffer[CN_PROC_MSG_SIZE];
@@ -67,14 +68,14 @@ void proc_fork_connector(struct task_str
memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
msg->ack = 0; /* not used */
msg->len = sizeof(*ev);
/* If cn_netlink_send() failed, the data is not sent */
- cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
+ cn_netlink_send(msg, CN_IDX_PROC, GFP_ATOMIC);
}
-void proc_exec_connector(struct task_struct *task)
+static void proc_exec_connector(struct task_struct *task)
{
struct cn_msg *msg;
struct proc_event *ev;
__u8 buffer[CN_PROC_MSG_SIZE];
@@ -90,14 +91,14 @@ void proc_exec_connector(struct task_str
ev->event_data.exec.process_tgid = task->tgid;
memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
msg->ack = 0; /* not used */
msg->len = sizeof(*ev);
- cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
+ cn_netlink_send(msg, CN_IDX_PROC, GFP_ATOMIC);
}
-void proc_id_connector(struct task_struct *task, int which_id)
+static void proc_id_connector(struct task_struct *task, int which_id)
{
struct cn_msg *msg;
struct proc_event *ev;
__u8 buffer[CN_PROC_MSG_SIZE];
@@ -121,14 +122,14 @@ void proc_id_connector(struct task_struc
ktime_get_ts(&ev->timestamp);
memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
msg->ack = 0; /* not used */
msg->len = sizeof(*ev);
- cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
+ cn_netlink_send(msg, CN_IDX_PROC, GFP_ATOMIC);
}
-void proc_exit_connector(struct task_struct *task)
+static void proc_exit_connector(struct task_struct *task)
{
struct cn_msg *msg;
struct proc_event *ev;
__u8 buffer[CN_PROC_MSG_SIZE];
@@ -146,11 +147,11 @@ void proc_exit_connector(struct task_str
ev->event_data.exit.exit_signal = task->exit_signal;
memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
msg->ack = 0; /* not used */
msg->len = sizeof(*ev);
- cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
+ cn_netlink_send(msg, CN_IDX_PROC, GFP_ATOMIC);
}
/*
* Send an acknowledgement message to userspace
*
@@ -207,10 +208,49 @@ static void cn_proc_mcast_ctl(void *data
break;
}
cn_proc_ack(err, msg->seq, msg->ack);
}
+
+/*
+ * Dispatch task watcher events to the appropriate process event
+ * generation function.
+ */
+static int cn_proc_watch_task(struct notifier_block *nb, unsigned long val,
+ void *t)
+{
+ struct task_struct *task = t;
+ int rc = NOTIFY_OK;
+
+ switch (get_watch_event(val)) {
+ case WATCH_TASK_CLONE:
+ proc_fork_connector(task);
+ break;
+ case WATCH_TASK_EXEC:
+ proc_exec_connector(task);
+ break;
+ case WATCH_TASK_UID:
+ proc_id_connector(task, PROC_EVENT_UID);
+ break;
+ case WATCH_TASK_GID:
+ proc_id_connector(task, PROC_EVENT_GID);
+ break;
+ case WATCH_TASK_EXIT:
+ proc_exit_connector(task);
+ break;
+ default: /* we don't care about WATCH_TASK_INIT|FREE because we
+ don't keep per-task info */
+ rc = NOTIFY_DONE; /* ignore all other notifications */
+ break;
+ }
+ return rc;
+}
+
+static struct notifier_block __read_mostly cn_proc_nb = {
+ .notifier_call = cn_proc_watch_task,
+};
+
/*
* cn_proc_init - initialization entry point
*
* Adds the connector callback to the connector driver.
*/
@@ -219,11 +259,16 @@ static int __init cn_proc_init(void)
int err;
if ((err = cn_add_callback(&cn_proc_event_id, "cn_proc",
&cn_proc_mcast_ctl))) {
printk(KERN_WARNING "cn_proc failed to register\n");
- return err;
+ goto out;
}
- return 0;
+
+ err = register_task_watcher(&cn_proc_nb);
+ if (err != 0)
+ cn_del_callback(&cn_proc_event_id);
+out:
+ return err;
}
module_init(cn_proc_init);
Index: linux-2.6.17-rc6-mm2/include/linux/cn_proc.h
===================================================================
--- linux-2.6.17-rc6-mm2.orig/include/linux/cn_proc.h
+++ linux-2.6.17-rc6-mm2/include/linux/cn_proc.h
@@ -93,28 +93,6 @@ struct proc_event {
pid_t process_tgid;
__u32 exit_code, exit_signal;
} exit;
} 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 */
Index: linux-2.6.17-rc6-mm2/kernel/exit.c
===================================================================
--- linux-2.6.17-rc6-mm2.orig/kernel/exit.c
+++ linux-2.6.17-rc6-mm2/kernel/exit.c
@@ -31,11 +31,10 @@
#include <linux/delayacct.h>
#include <linux/cpuset.h>
#include <linux/syscalls.h>
#include <linux/signal.h>
#include <linux/posix-timers.h>
-#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
@@ -941,11 +940,10 @@ fastcall NORET_TYPE void do_exit(long co
module_put(task_thread_info(tsk)->exec_domain->module);
if (tsk->binfmt)
module_put(tsk->binfmt->module);
- proc_exit_connector(tsk);
exit_notify(tsk);
#ifdef CONFIG_NUMA
mpol_free(tsk->mempolicy);
tsk->mempolicy = NULL;
#endif
Index: linux-2.6.17-rc6-mm2/kernel/fork.c
===================================================================
--- linux-2.6.17-rc6-mm2.orig/kernel/fork.c
+++ linux-2.6.17-rc6-mm2/kernel/fork.c
@@ -42,11 +42,10 @@
#include <linux/mount.h>
#include <linux/audit.h>
#include <linux/profile.h>
#include <linux/rmap.h>
#include <linux/acct.h>
-#include <linux/cn_proc.h>
#include <linux/delayacct.h>
#include <linux/notifier.h>
#include <asm/pgtable.h>
#include <asm/pgalloc.h>
@@ -1251,14 +1250,12 @@ static task_t *copy_process(unsigned lon
total_forks++;
spin_unlock(¤t->sighand->siglock);
write_unlock_irq(&tasklist_lock);
notify_result = notify_watchers(WATCH_TASK_CLONE, p);
- if (notify_result & NOTIFY_STOP_MASK)
- goto bad_fork_cleanup_namespaces;
- proc_fork_connector(p);
- return p;
+ if (!(notify_result & NOTIFY_STOP_MASK))
+ return p;
bad_fork_cleanup_namespaces:
exit_task_namespaces(p);
bad_fork_cleanup_keys:
exit_keys(p);
Index: linux-2.6.17-rc6-mm2/fs/exec.c
===================================================================
--- linux-2.6.17-rc6-mm2.orig/fs/exec.c
+++ linux-2.6.17-rc6-mm2/fs/exec.c
@@ -46,11 +46,10 @@
#include <linux/mount.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/rmap.h>
#include <linux/acct.h>
-#include <linux/cn_proc.h>
#include <linux/audit.h>
#include <linux/notifier.h>
#include <asm/uaccess.h>
#include <asm/mmu_context.h>
@@ -1097,11 +1096,10 @@ int search_binary_handler(struct linux_b
if (bprm->file)
fput(bprm->file);
bprm->file = NULL;
current->did_exec = 1;
notify_watchers(WATCH_TASK_EXEC, current);
- proc_exec_connector(current);
return retval;
}
read_lock(&binfmt_lock);
put_binfmt(fmt);
if (retval != -ENOEXEC || bprm->mm == NULL)
Index: linux-2.6.17-rc6-mm2/kernel/sys.c
===================================================================
--- linux-2.6.17-rc6-mm2.orig/kernel/sys.c
+++ linux-2.6.17-rc6-mm2/kernel/sys.c
@@ -862,11 +862,10 @@ asmlinkage long sys_setregid(gid_t rgid,
current->fsgid = new_egid;
current->egid = new_egid;
current->gid = new_rgid;
key_fsgid_changed(current);
notify_watchers(WATCH_TASK_GID, current);
- proc_id_connector(current, PROC_EVENT_GID);
return 0;
}
/*
* setgid() is implemented like SysV w/ SAVED_IDS
@@ -903,11 +902,10 @@ asmlinkage long sys_setgid(gid_t gid)
else
return -EPERM;
key_fsgid_changed(current);
notify_watchers(WATCH_TASK_GID, current);
- proc_id_connector(current, PROC_EVENT_GID);
return 0;
}
static int set_user(uid_t new_ruid, int dumpclear)
{
@@ -994,11 +992,10 @@ asmlinkage long sys_setreuid(uid_t ruid,
current->suid = current->euid;
current->fsuid = current->euid;
key_fsuid_changed(current);
notify_watchers(WATCH_TASK_UID, current);
- proc_id_connector(current, PROC_EVENT_UID);
return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RE);
}
@@ -1043,11 +1040,10 @@ asmlinkage long sys_setuid(uid_t uid)
current->fsuid = current->euid = uid;
current->suid = new_suid;
key_fsuid_changed(current);
notify_watchers(WATCH_TASK_UID, current);
- proc_id_connector(current, PROC_EVENT_UID);
return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID);
}
@@ -1093,11 +1089,10 @@ asmlinkage long sys_setresuid(uid_t ruid
if (suid != (uid_t) -1)
current->suid = suid;
key_fsuid_changed(current);
notify_watchers(WATCH_TASK_UID, current);
- proc_id_connector(current, PROC_EVENT_UID);
return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES);
}
asmlinkage long sys_getresuid(uid_t __user *ruid, uid_t __user *euid, uid_t __user *suid)
@@ -1147,11 +1142,10 @@ asmlinkage long sys_setresgid(gid_t rgid
if (sgid != (gid_t) -1)
current->sgid = sgid;
key_fsgid_changed(current);
notify_watchers(WATCH_TASK_GID, current);
- proc_id_connector(current, PROC_EVENT_GID);
return 0;
}
asmlinkage long sys_getresgid(gid_t __user *rgid, gid_t __user *egid, gid_t __user *sgid)
{
@@ -1191,11 +1185,10 @@ asmlinkage long sys_setfsuid(uid_t uid)
current->fsuid = uid;
}
key_fsuid_changed(current);
notify_watchers(WATCH_TASK_UID, current);
- proc_id_connector(current, PROC_EVENT_UID);
security_task_post_setuid(old_fsuid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS);
return old_fsuid;
}
@@ -1221,11 +1214,10 @@ asmlinkage long sys_setfsgid(gid_t gid)
smp_wmb();
}
current->fsgid = gid;
key_fsgid_changed(current);
notify_watchers(WATCH_TASK_GID, current);
- proc_id_connector(current, PROC_EVENT_GID);
}
return old_fsgid;
}
asmlinkage long sys_times(struct tms __user * tbuf)
--
next prev parent reply other threads:[~2006-06-14 0:01 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20060613235122.130021000@localhost.localdomain>
2006-06-13 23:53 ` [PATCH 01/11] Task watchers: Task Watchers Matt Helsley
2006-06-14 0:19 ` Chase Venters
2006-06-14 0:55 ` Matt Helsley
2006-06-13 23:54 ` Matt Helsley [this message]
2006-06-14 0:39 ` [PATCH 02/11] Task watchers: Register process events task watcher Chase Venters
2006-06-14 0:52 ` Matt Helsley
2006-06-13 23:54 ` [PATCH 03/11] Task watchers: Refactor process events Matt Helsley
2006-06-14 0:43 ` Chase Venters
2006-06-14 1:11 ` Matt Helsley
2006-06-14 8:09 ` Chase Venters
2006-06-13 23:54 ` [PATCH 04/11] Task watchers: Make process events configurable as a module Matt Helsley
2006-06-14 0:54 ` Chase Venters
2006-06-14 1:18 ` [Lse-tech] " Matt Helsley
2006-06-13 23:54 ` [PATCH 05/11] Task watchers: Allow task watchers to block Matt Helsley
2006-06-13 23:54 ` [PATCH 06/11] Task watchers: Register audit task watcher Matt Helsley
2006-06-13 23:54 ` Matt Helsley
2006-06-14 14:46 ` Alexander Viro
2006-06-14 14:46 ` Alexander Viro
2006-06-14 23:28 ` Matt Helsley
2006-06-14 23:28 ` Matt Helsley
2006-06-13 23:54 ` [PATCH 07/11] Task watchers: Register per-task delay accounting " Matt Helsley
2006-06-14 3:31 ` Shailabh Nagar
2006-06-14 22:52 ` Matt Helsley
2006-06-13 23:54 ` [PATCH 08/11] Task watchers: Register profile as a " Matt Helsley
2006-06-14 0:59 ` Chase Venters
2006-06-14 1:16 ` [Lse-tech] " Matt Helsley
2006-06-13 23:55 ` [PATCH 09/11] Task watchers: Add support for per-task watchers Matt Helsley
2006-06-20 5:28 ` Peter Williams
2006-06-20 22:56 ` [Lse-tech] " Matt Helsley
2006-06-20 23:15 ` Andrew Morton
2006-06-20 23:23 ` Peter Williams
2006-06-21 1:20 ` Matt Helsley
2006-06-21 1:46 ` Andrew Morton
2006-06-21 1:55 ` Peter Williams
2006-06-21 13:01 ` Peter Williams
2006-06-21 13:23 ` Peter Williams
2006-06-21 2:28 ` Matt Helsley
2006-06-20 23:21 ` Peter Williams
2006-06-13 23:55 ` [PATCH 10/11] Task watchers: Register semundo task watcher Matt Helsley
2006-06-13 23:55 ` [PATCH 11/11] Task watchers: Register per-task semundo watcher Matt Helsley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1150242874.21787.142.camel@stark \
--to=matthltc@us.ibm.com \
--cc=akpm@osdl.org \
--cc=balbir@in.ibm.com \
--cc=guillaume.thouvenin@bull.net \
--cc=jes@sgi.com \
--cc=jtk@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lse-tech@lists.sourceforge.net \
--cc=nagar@watson.ibm.com \
--cc=sekharan@us.ibm.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.