Skip to content

Commit f0ec1aa

Browse files
Oleg NesterovLinus Torvalds
authored andcommitted
[PATCH] xacct_add_tsk: fix pure theoretical ->mm use-after-free
Paranoid fix. The task can free its ->mm after the 'if (p->mm)' check. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Cc: Shailabh Nagar <nagar@watson.ibm.com> Cc: Balbir Singh <balbir@in.ibm.com> Cc: Jay Lan <jlan@sgi.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent d45e44d commit f0ec1aa

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎kernel/tsacct.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,17 @@ void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
8080
*/
8181
void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
8282
{
83+
struct mm_struct *mm;
84+
8385
/* convert pages-jiffies to Mbyte-usec */
8486
stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
8587
stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
86-
if (p->mm) {
88+
mm = get_task_mm(p);
89+
if (mm) {
8790
/* adjust to KB unit */
88-
stats->hiwater_rss = p->mm->hiwater_rss * PAGE_SIZE / KB;
89-
stats->hiwater_vm = p->mm->hiwater_vm * PAGE_SIZE / KB;
91+
stats->hiwater_rss = mm->hiwater_rss * PAGE_SIZE / KB;
92+
stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB;
93+
mmput(mm);
9094
}
9195
stats->read_char = p->rchar;
9296
stats->write_char = p->wchar;

0 commit comments

Comments
 (0)