[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20100629171846.GA18440@redhat.com>
Date: Tue, 29 Jun 2010 19:18:46 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: "Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
Cc: Artem Bityutskiy <dedekind1@...il.com>,
john stultz <johnstul@...ibm.com>,
Kees Cook <kees.cook@...onical.com>,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
Alexander Viro <viro@...iv.linux.org.uk>,
Andrew Morton <akpm@...ux-foundation.org>,
KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>,
Neil Horman <nhorman@...driver.com>,
Roland McGrath <roland@...hat.com>,
Ingo Molnar <mingo@...e.hu>,
Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH] sanitize task->comm to avoid leaking escape codes
On 06/29, Paul E. McKenney wrote:
>
> On Tue, Jun 29, 2010 at 03:31:31PM +0200, Oleg Nesterov wrote:
>
> > 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)
>
> First, all of the implementations that I can see do task_lock(tsk), which
> should prevent readers from seeing any changes. So I am guessing that
> you guys want to allow readers to get at ->comm without having to acquire
> this lock.
Ah, sorry for confusion.
No, we are not trying to invent the lockless get_task_comm(). I'd say
it is not needed, if we really care about the precise ->comm we can
take task->alloc_lock.
The only problem is that I believe that set_task_comm() wrongly pretends
wmb() can help the lockless reader, it does:
task_lock(tsk);
/*
* Threads may access current->comm without holding
* the task lock, so write the string carefully.
* Readers without a lock may see incomplete new
* names but are safe from non-terminating string reads.
*/
memset(tsk->comm, 0, TASK_COMM_LEN);
wmb();
strlcpy(tsk->comm, buf, sizeof(tsk->comm));
task_unlock(tsk);
but afaics this wmb() buys absolutely nothing if we race with the
reader doing, say,
printk("my name is %s\n", current->comm);
Afaics, this wmb()
- can't prevent from printing the mixture of the old/new data
- is not needed to make strcpy(somewhere, task->comm) safe,
the final char is always '0', we never change it.
- adds the unnecessary confusion
> [... snip a lot of good ideas ...]
Thanks a lot, Paul ;)
Oleg.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists