Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5834788imm; Mon, 23 Jul 2018 06:57:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdrC5p46K1A1i4esLKvX3EQDlEdVftxtrd6bWNqMcGmHyudfIQ5qIhiFc4iMQQjfmbR3rpZ X-Received: by 2002:a62:1089:: with SMTP id 9-v6mr13097814pfq.30.1532354220264; Mon, 23 Jul 2018 06:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532354220; cv=none; d=google.com; s=arc-20160816; b=YQl6EmiqAaNh3aF643UxRLsUsH7Hk9Ve6LeMEE5334h5DDyZ34WWI4ORimJUzWo8oA j7/jwirvec+wDkwUpUkPM+Q80FUER4/czH2vEmahWYmftPFjuEUjLeW7DeljOLsPu7is AEjITgimEwMxQIRXxPxw0Uq2j6Hw15NbB2Ej8dg76BedFLGVZ14Ocs115JoMXM/K5va+ 8tsqKXGUOQgx6M+Wd24xwDSr+aYWl5EzEpV1ips5kqZ3xtPHPTdet2u6Bm7fZEPzlyJK uhf1SkQC8GbU/91i8IxUWwKc9sheqOO31MpnTFJVvHoa6TqSCTfu+csRrf8mkAYve/7U d+3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=FicgOAnFPbMJiXj1HCZNVn76gebW16cJ4v8q3pf/23s=; b=RdZAakSPFtqmP45cVUsi+jXVKhb+tPvl5BosoAKElF25ojLzbzlysXiAg5F/Lvqr3H NB7l70eI/D1NyyJCBHS3bTUd4EG/N8rPvnooH2qJ9QyyBqqvGZCl2J+SQ9kOQUmCudBP yLhGU8kxzKgOwIm1YqmxTfAiexqILzLbIh3PZuUKjB1a6ViR6uc187tULDRQ4QZye6ns pLnXsuFjwo12ZfEtHgo2PY/6uHRtIlLKc9iszf87giMg4vKIoHeen+U9Ozc2UHwhYWLK kJFu92tb40DUt9K8jmu/63j73yndLtSDDWJUfDLFGspGQqSzhtaUgVz5OFdGgADw5I1l YSZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t21-v6si9096624pgb.553.2018.07.23.06.56.45; Mon, 23 Jul 2018 06:57:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388096AbeGWO5R (ORCPT + 99 others); Mon, 23 Jul 2018 10:57:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:57340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387801AbeGWO5Q (ORCPT ); Mon, 23 Jul 2018 10:57:16 -0400 Received: from gandalf.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7AF0C20852; Mon, 23 Jul 2018 13:55:52 +0000 (UTC) Date: Mon, 23 Jul 2018 09:55:50 -0400 From: Steven Rostedt To: Snild Dolkow Cc: , Ingo Molnar , Jens Axboe , Tejun Heo , Greg Kroah-Hartman , Linus Torvalds , Peter Enderborg , Yoshitaka Seto , Oleksiy Avramchenko , KOSAKI Motohiro , John Stultz Subject: Re: [PATCH RESEND] kthread, tracing: Don't expose half-written comm when creating kthreads Message-ID: <20180723095550.08203a24@gandalf.local.home> In-Reply-To: <20180723134210.54013-1-snild@sony.com> References: <20180723134210.54013-1-snild@sony.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 23 Jul 2018 15:42:10 +0200 Snild Dolkow wrote: > 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 > --- > 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); Can you add a comment here stating something to the affect of: /* task is now visible to other tasks */ -- Steve > + 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.