From: Andi Kleen <andi@firstfloor.org>
To: john stultz <johnstul@us.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Arjan van de Ven <arjan@infradead.org>,
lkml <linux-kernel@vger.kernel.org>,
Mike Fulton <fultonm@ca.ibm.com>,
Sean Foley <Sean_Foley@ca.ibm.com>,
Darren Hart <dvhltc@us.ibm.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Subject: Re: [PATCH] Allow threads to rename siblings via /proc/pid/tasks/tid/comm
Date: Sat, 07 Nov 2009 23:52:20 +0100 [thread overview]
Message-ID: <87aayy6j8b.fsf@basil.nowhere.org> (raw)
In-Reply-To: <1257557918.3298.21.camel@localhost.localdomain> (john stultz's message of "Fri, 06 Nov 2009 17:38:38 -0800")
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.
-Andi
--
ak@linux.intel.com -- Speaking for myself only.
next prev parent reply other threads:[~2009-11-07 22:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-24 1:21 [RFC][PATCH] Add prctl to set sibling thread names (take two) john stultz
2009-10-24 3:45 ` Darren Hart
2009-10-30 19:54 ` john stultz
2009-10-30 20:06 ` [RFC][PATCH] Allow threads to rename siblings via /proc/pid/tasks/tid/comm john stultz
2009-11-07 1:38 ` [PATCH] " john stultz
2009-11-07 22:52 ` Andi Kleen [this message]
2009-11-08 20:45 ` Arjan van de Ven
2009-11-10 1:26 ` john stultz
2009-11-16 21:11 ` john stultz
2009-11-18 21:54 ` Andrew Morton
2009-11-19 1:04 ` KOSAKI Motohiro
2009-11-21 0:33 ` 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=87aayy6j8b.fsf@basil.nowhere.org \
--to=andi@firstfloor.org \
--cc=Sean_Foley@ca.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=arjan@infradead.org \
--cc=dvhltc@us.ibm.com \
--cc=fultonm@ca.ibm.com \
--cc=johnstul@us.ibm.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
/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