lkml.org 
[lkml]   [2009]   [Nov]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Allow threads to rename siblings via /proc/pid/tasks/tid/comm
On Sat, 07 Nov 2009 23:52:20 +0100
Andi Kleen <andi@firstfloor.org> wrote:

> john stultz <johnstul@us.ibm.com> writes:
> > - strlcpy(tsk->comm, buf, sizeof(tsk->comm));
> > +
> > + /*
> > + * Threads may access current->comm without holding
> > + * the task lock, so write the string carefully
> > + * to avoid non-terminating reads. Readers without a lock
> > + * will get the oldname, the newname or an empty string.
> > + */
> > + tsk->comm[0] = 0;
> > + wmb();
> > + strlcpy(tsk->comm+1, buf+1, sizeof(tsk->comm)-1);
> > + wmb();
> > + tsk->comm[0] = buf[0];
>
> Is this really safe?
>
> reader writer
>
>
> read comm[0]
> set comm[0] to 0
> overwrites comm[1]
> read comm[1]
> read comm[2]
> writes comm[2] to 0
> read comm[3]
>
> ...
> goes beyond the end
>
> Better way probably is to replace tsk->comm with a pointer
> and exchange that using xchg. Drawback: 4-8 bytes more per task.
>
> Or perhaps make comm one byte longer and make sure the last
> byte is always 0, but the drawback is that a reader can
> read random (but at least safe) junk then.

another option is to memset the whole thing to 0's.
might sound like overkill, but we're talking 16 bytes here... cheap
enough to do for such a rare case.


--
Arjan van de Ven Intel Open Source Technology Centre
For development, discussion and tips for power savings,
visit http://www.lesswatts.org


\
 
 \ /
  Last update: 2009-11-08 21:47    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site