bsd_acct: using task_struct->tgid is not right in pid-namespaces

In case we're accounting from a sub-namespace, the tgids reported will not
refer to the right namespace.

Save the pid_namespace we're accounting in on the acct_glbs and use it in
do_acct_process.

Two less :) places using the task_struct.tgid member.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Pavel Emelyanov and committed by Linus Torvalds 5f7b703f a846a195

+15 -6
+15 -6
kernel/acct.c
··· 58 58 #include <asm/uaccess.h> 59 59 #include <asm/div64.h> 60 60 #include <linux/blkdev.h> /* sector_div */ 61 + #include <linux/pid_namespace.h> 61 62 62 63 /* 63 64 * These constants control the amount of freespace that suspend and ··· 75 74 /* 76 75 * External references and all of the globals. 77 76 */ 78 - static void do_acct_process(struct file *); 77 + static void do_acct_process(struct pid_namespace *ns, struct file *); 79 78 80 79 /* 81 80 * This structure is used so that all the data protected by lock ··· 87 86 volatile int active; 88 87 volatile int needcheck; 89 88 struct file *file; 89 + struct pid_namespace *ns; 90 90 struct timer_list timer; 91 91 }; 92 92 ··· 177 175 static void acct_file_reopen(struct file *file) 178 176 { 179 177 struct file *old_acct = NULL; 178 + struct pid_namespace *old_ns = NULL; 180 179 181 180 if (acct_globals.file) { 182 181 old_acct = acct_globals.file; 182 + old_ns = acct_globals.ns; 183 183 del_timer(&acct_globals.timer); 184 184 acct_globals.active = 0; 185 185 acct_globals.needcheck = 0; ··· 189 185 } 190 186 if (file) { 191 187 acct_globals.file = file; 188 + acct_globals.ns = get_pid_ns(task_active_pid_ns(current)); 192 189 acct_globals.needcheck = 0; 193 190 acct_globals.active = 1; 194 191 /* It's been deleted if it was used before so this is safe */ ··· 201 196 if (old_acct) { 202 197 mnt_unpin(old_acct->f_path.mnt); 203 198 spin_unlock(&acct_globals.lock); 204 - do_acct_process(old_acct); 199 + do_acct_process(old_ns, old_acct); 205 200 filp_close(old_acct, NULL); 201 + put_pid_ns(old_ns); 206 202 spin_lock(&acct_globals.lock); 207 203 } 208 204 } ··· 425 419 /* 426 420 * do_acct_process does all actual work. Caller holds the reference to file. 427 421 */ 428 - static void do_acct_process(struct file *file) 422 + static void do_acct_process(struct pid_namespace *ns, struct file *file) 429 423 { 430 424 struct pacct_struct *pacct = &current->signal->pacct; 431 425 acct_t ac; ··· 487 481 ac.ac_gid16 = current->gid; 488 482 #endif 489 483 #if ACCT_VERSION==3 490 - ac.ac_pid = current->tgid; 484 + ac.ac_pid = task_tgid_nr_ns(current, ns); 491 485 rcu_read_lock(); 492 - ac.ac_ppid = rcu_dereference(current->real_parent)->tgid; 486 + ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent), ns); 493 487 rcu_read_unlock(); 494 488 #endif 495 489 ··· 586 580 void acct_process(void) 587 581 { 588 582 struct file *file = NULL; 583 + struct pid_namespace *ns; 589 584 590 585 /* 591 586 * accelerate the common fastpath: ··· 601 594 return; 602 595 } 603 596 get_file(file); 597 + ns = get_pid_ns(acct_globals.ns); 604 598 spin_unlock(&acct_globals.lock); 605 599 606 - do_acct_process(file); 600 + do_acct_process(ns, file); 607 601 fput(file); 602 + put_pid_ns(ns); 608 603 }