From: Snild Dolkow <snild@sony.com>
To: <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@kernel.org>,
Jens Axboe <axboe@kernel.dk>,
Steven Rostedt <rostedt@goodmis.org>, Tejun Heo <tj@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Enderborg <peter.enderborg@sony.com>,
Yoshitaka Seto <yoshitaka.seto@sony.com>,
Oleksiy Avramchenko <oleksiy.avramchenko@sony.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
John Stultz <john.stultz@linaro.org>,
Snild Dolkow <snild@sony.com>
Subject: [PATCH RESEND] kthread, tracing: Don't expose half-written comm when creating kthreads
Date: Mon, 23 Jul 2018 15:42:10 +0200 [thread overview]
Message-ID: <20180723134210.54013-1-snild@sony.com> (raw)
There was a window for racing when task->comm was being written. The
vsnprintf function writes 16 bytes, then counts the rest, then null
terminates. In the meantime, other threads could see the non-terminated
comm value. In our case, it got into the trace system's saved cmdlines
and could cause stack corruption when strcpy'd out of there.
The workaround in e09e28671 (use strlcpy in __trace_find_cmdline) was
likely needed because of this bug.
Solved by vsnprintf:ing to a local buffer, then using set_task_comm().
Signed-off-by: Snild Dolkow <snild@sony.com>
---
kernel/kthread.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 481951bf091d..28874afbf747 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -319,8 +319,10 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
task = create->result;
if (!IS_ERR(task)) {
static const struct sched_param param = { .sched_priority = 0 };
+ char name[TASK_COMM_LEN];
- vsnprintf(task->comm, sizeof(task->comm), namefmt, args);
+ vsnprintf(name, sizeof(name), namefmt, args);
+ set_task_comm(task, name);
/*
* root may have changed our (kthreadd's) priority or CPU mask.
* The kernel thread should not inherit these properties.
--
2.15.1
next reply other threads:[~2018-07-23 13:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-23 13:42 Snild Dolkow [this message]
2018-07-23 13:55 ` [PATCH RESEND] kthread, tracing: Don't expose half-written comm when creating kthreads Steven Rostedt
2018-07-23 14:23 ` Snild Dolkow
2018-07-23 15:37 ` Steven Rostedt
2018-07-23 15:49 ` Snild Dolkow
2018-07-23 16:41 ` Steven Rostedt
2018-07-24 8:17 ` Snild Dolkow
2018-07-24 14:48 ` Steven Rostedt
2018-07-24 15:02 ` Snild Dolkow
-- strict thread matches above, loose matches on Subject: below --
2018-09-04 6:52 Snild Dolkow
2018-09-04 7:00 ` Snild Dolkow
2018-09-07 9:44 ` Greg KH
2018-09-07 9:51 ` Snild Dolkow
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=20180723134210.54013-1-snild@sony.com \
--to=snild@sony.com \
--cc=axboe@kernel.dk \
--cc=gregkh@linuxfoundation.org \
--cc=john.stultz@linaro.org \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=oleksiy.avramchenko@sony.com \
--cc=peter.enderborg@sony.com \
--cc=rostedt@goodmis.org \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=yoshitaka.seto@sony.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.