From: Oleg Nesterov <oleg@redhat.com>
To: Artem Bityutskiy <dedekind1@gmail.com>
Cc: john stultz <johnstul@us.ibm.com>,
Kees Cook <kees.cook@canonical.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Neil Horman <nhorman@tuxdriver.com>,
Roland McGrath <roland@redhat.com>, Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH] sanitize task->comm to avoid leaking escape codes
Date: Tue, 29 Jun 2010 15:31:31 +0200 [thread overview]
Message-ID: <20100629133131.GB5237@redhat.com> (raw)
In-Reply-To: <1277787505.3599.25.camel@localhost.localdomain>
On 06/29, Artem Bityutskiy wrote:
>
> On Wed, 2010-06-23 at 21:41 +0200, Oleg Nesterov wrote:
> > On 06/23, Kees Cook wrote:
> > >
> > > @@ -956,7 +957,15 @@ void set_task_comm(struct task_struct *tsk, char *buf)
> > > */
> > > memset(tsk->comm, 0, TASK_COMM_LEN);
> > > wmb();
> >
> > Off-topic. I'd wish I could understand this barrier. Since the lockless
> > reader doesn't do rmb() I don't see how this can help.
>
> This wmb() looks wrong to me as well. To achieve what the comment in
> this function says, it should be smp_wmb() and we should have smp_rmb()
> in the reading side, AFAIU.
>
> > OTOH, I don't
> > understand why it is needed, we never change ->comm[TASK_COMM_LEN-1] == '0'.
>
> I think the idea was that readers can see incomplete names, but not
> messed up names, consisting of old and new ones.
OK, agreed, comm[TASK_COMM_LEN-1] == '0' can't help to avoid the
messed names.
But nether can help smp_rmb() in the reading (lockless) side?
Say,
printk("comm=%s\n", current->comm);
if we add rmb() before printk, it can't make any difference. The lockless
code should do something like
get_comm_lockless(char *to, char *comm)
{
while (*comm++ = *to++)
rmb();
}
to ensure it sees the result of
memset(tsk->comm, 0, TASK_COMM_LEN);
wmb();
strcpy(tsk->comm, buf);
in the right order.
otherwise printk("comm=%s\n", current->comm) can read, say, comm[1]
before set_task_comm->memset(), and comm[0] after set_task_comm->strcpy().
So, afaics, set_task_comm()->wmb() buys nothing and should be removed.
The last zero char in task_struct->comm[] is always here, at least this
guarantees that strcpy(char *dest, tsk->comm) is always safe.
(I cc'ed the expert, Paul can correct me)
Oleg.
next prev parent reply other threads:[~2010-06-29 13:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-23 18:11 [PATCH] sanitize task->comm to avoid leaking escape codes Kees Cook
2010-06-23 19:41 ` Oleg Nesterov
2010-06-23 20:23 ` Alexey Dobriyan
2010-06-23 21:28 ` Kees Cook
2010-06-28 20:00 ` Andrew Morton
2010-06-28 21:03 ` Kees Cook
2010-06-29 8:45 ` Alexey Dobriyan
2010-06-29 15:09 ` Kees Cook
2010-06-29 18:59 ` Andrew Morton
2010-06-29 19:13 ` Kees Cook
2010-06-29 4:58 ` Artem Bityutskiy
2010-06-29 13:31 ` Oleg Nesterov [this message]
2010-06-29 16:23 ` Paul E. McKenney
2010-06-29 17:18 ` Oleg Nesterov
2010-06-29 17:33 ` Paul E. McKenney
2010-06-29 22:32 ` john stultz
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=20100629133131.GB5237@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dedekind1@gmail.com \
--cc=johnstul@us.ibm.com \
--cc=kees.cook@canonical.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=nhorman@tuxdriver.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=roland@redhat.com \
--cc=tglx@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).