Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 327259
b: refs/heads/master
c: 4bd6e32
h: refs/heads/master
i:
  327257: 3e2e091
  327255: 8182b9e
v: v3
  • Loading branch information
Eric W. Biederman committed Sep 18, 2012
1 parent 5404a15 commit 6b46ce7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cca080d9b622094831672a136e5ee4f702d116b1
refs/heads/master: 4bd6e32acec66c55c6c1af4672f3216b2ac88e35
8 changes: 6 additions & 2 deletions trunk/include/linux/tsacct_kern.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
#include <linux/taskstats.h>

#ifdef CONFIG_TASKSTATS
extern void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk);
extern void bacct_add_tsk(struct user_namespace *user_ns,
struct pid_namespace *pid_ns,
struct taskstats *stats, struct task_struct *tsk);
#else
static inline void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
static inline void bacct_add_tsk(struct user_namespace *user_ns,
struct pid_namespace *pid_ns,
struct taskstats *stats, struct task_struct *tsk)
{}
#endif /* CONFIG_TASKSTATS */

Expand Down
1 change: 0 additions & 1 deletion trunk/init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,6 @@ config UIDGID_CONVERTED
# Features
depends on IMA = n
depends on EVM = n
depends on TASKSTATS = n
depends on TRACING = n
depends on FS_POSIX_ACL = n
depends on QUOTA = n
Expand Down
23 changes: 17 additions & 6 deletions trunk/kernel/taskstats.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <linux/cgroup.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/pid_namespace.h>
#include <net/genetlink.h>
#include <linux/atomic.h>

Expand Down Expand Up @@ -174,7 +175,9 @@ static void send_cpu_listeners(struct sk_buff *skb,
up_write(&listeners->sem);
}

static void fill_stats(struct task_struct *tsk, struct taskstats *stats)
static void fill_stats(struct user_namespace *user_ns,
struct pid_namespace *pid_ns,
struct task_struct *tsk, struct taskstats *stats)
{
memset(stats, 0, sizeof(*stats));
/*
Expand All @@ -190,7 +193,7 @@ static void fill_stats(struct task_struct *tsk, struct taskstats *stats)
stats->version = TASKSTATS_VERSION;
stats->nvcsw = tsk->nvcsw;
stats->nivcsw = tsk->nivcsw;
bacct_add_tsk(stats, tsk);
bacct_add_tsk(user_ns, pid_ns, stats, tsk);

/* fill in extended acct fields */
xacct_add_tsk(stats, tsk);
Expand All @@ -207,7 +210,7 @@ static int fill_stats_for_pid(pid_t pid, struct taskstats *stats)
rcu_read_unlock();
if (!tsk)
return -ESRCH;
fill_stats(tsk, stats);
fill_stats(current_user_ns(), task_active_pid_ns(current), tsk, stats);
put_task_struct(tsk);
return 0;
}
Expand Down Expand Up @@ -291,6 +294,12 @@ static int add_del_listener(pid_t pid, const struct cpumask *mask, int isadd)
if (!cpumask_subset(mask, cpu_possible_mask))
return -EINVAL;

if (current_user_ns() != &init_user_ns)
return -EINVAL;

if (task_active_pid_ns(current) != &init_pid_ns)
return -EINVAL;

if (isadd == REGISTER) {
for_each_cpu(cpu, mask) {
s = kmalloc_node(sizeof(struct listener),
Expand Down Expand Up @@ -631,19 +640,21 @@ void taskstats_exit(struct task_struct *tsk, int group_dead)
if (rc < 0)
return;

stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, tsk->pid);
stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID,
task_pid_nr_ns(tsk, &init_pid_ns));
if (!stats)
goto err;

fill_stats(tsk, stats);
fill_stats(&init_user_ns, &init_pid_ns, tsk, stats);

/*
* Doesn't matter if tsk is the leader or the last group member leaving
*/
if (!is_thread_group || !group_dead)
goto send;

stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tsk->tgid);
stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID,
task_tgid_nr_ns(tsk, &init_pid_ns));
if (!stats)
goto err;

Expand Down
12 changes: 7 additions & 5 deletions trunk/kernel/tsacct.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
/*
* fill in basic accounting fields
*/
void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
void bacct_add_tsk(struct user_namespace *user_ns,
struct pid_namespace *pid_ns,
struct taskstats *stats, struct task_struct *tsk)
{
const struct cred *tcred;
struct timespec uptime, ts;
Expand Down Expand Up @@ -55,13 +57,13 @@ void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
stats->ac_flag |= AXSIG;
stats->ac_nice = task_nice(tsk);
stats->ac_sched = tsk->policy;
stats->ac_pid = tsk->pid;
stats->ac_pid = task_pid_nr_ns(tsk, pid_ns);
rcu_read_lock();
tcred = __task_cred(tsk);
stats->ac_uid = tcred->uid;
stats->ac_gid = tcred->gid;
stats->ac_uid = from_kuid_munged(user_ns, tcred->uid);
stats->ac_gid = from_kgid_munged(user_ns, tcred->gid);
stats->ac_ppid = pid_alive(tsk) ?
rcu_dereference(tsk->real_parent)->tgid : 0;
task_tgid_nr_ns(rcu_dereference(tsk->real_parent), pid_ns) : 0;
rcu_read_unlock();
stats->ac_utime = cputime_to_usecs(tsk->utime);
stats->ac_stime = cputime_to_usecs(tsk->stime);
Expand Down

0 comments on commit 6b46ce7

Please sign in to comment.