From: Jay Lan <jlan@engr.sgi.com>
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Andrew Morton <akpm@osdl.org>,
Shailabh Nagar <nagar@watson.ibm.com>,
Balbir Singh <balbir@in.ibm.com>, Jay Lan <jlan@sgi.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] xacct_add_tsk: fix pure theoretical ->mm use-after-free
Date: Mon, 30 Oct 2006 10:51:58 -0800 [thread overview]
Message-ID: <454649CE.80804@engr.sgi.com> (raw)
In-Reply-To: <20061029185826.GA1619@oleg>
Oleg Nesterov wrote:
> Paranoid fix. The task can free its ->mm after the 'if (p->mm)' check.
Why this change is necessary? This routine is indirectly invoked by
taskstats_exit_send() routine called inside do_exit():
do_exit()
{
...
taskstats_exit_send(tsk, tidstats, group_dead, mycpu);
taskstats_exit_free(tidstats);
delayacct_tsk_exit(tsk);
exit_mm(tsk);
...
}
The mm is freed in exit_mm(), right?
- jay
>
> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
>
> --- STATS/kernel/tsacct.c~3_mm 2006-10-27 01:03:26.000000000 +0400
> +++ STATS/kernel/tsacct.c 2006-10-29 21:46:12.000000000 +0300
> @@ -80,13 +80,17 @@ void bacct_add_tsk(struct taskstats *sta
> */
> void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
> {
> + struct mm_struct *mm;
> +
> /* convert pages-jiffies to Mbyte-usec */
> stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
> stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
> - if (p->mm) {
> + mm = get_task_mm(p);
> + if (mm) {
> /* adjust to KB unit */
> - stats->hiwater_rss = p->mm->hiwater_rss * PAGE_SIZE / KB;
> - stats->hiwater_vm = p->mm->hiwater_vm * PAGE_SIZE / KB;
> + stats->hiwater_rss = mm->hiwater_rss * PAGE_SIZE / KB;
> + stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB;
> + mmput(mm);
> }
> stats->read_char = p->rchar;
> stats->write_char = p->wchar;
>
next prev parent reply other threads:[~2006-10-30 18:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-29 18:58 [PATCH] xacct_add_tsk: fix pure theoretical ->mm use-after-free Oleg Nesterov
2006-10-30 18:51 ` Jay Lan [this message]
2006-10-30 20:41 ` Oleg Nesterov
2006-10-31 3:08 ` Jay Lan
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=454649CE.80804@engr.sgi.com \
--to=jlan@engr.sgi.com \
--cc=akpm@osdl.org \
--cc=balbir@in.ibm.com \
--cc=jlan@sgi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nagar@watson.ibm.com \
--cc=oleg@tv-sign.ru \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox