Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7061884imm; Tue, 24 Jul 2018 07:50:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdux8p53pxgzY/SLYEF/vKjtjFAQHs/ma8pG/uyXlkOzahwVzcaGDn5SAoA0dWoKxMfUw0c X-Received: by 2002:a17:902:301:: with SMTP id 1-v6mr17171274pld.127.1532443812270; Tue, 24 Jul 2018 07:50:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532443812; cv=none; d=google.com; s=arc-20160816; b=pBf4k6CaIymeUGTzQqqrRPPYw0QK6Cbiw7LqfAI/LGKK9BVD81pim5bbPW7Wfzy638 WzsyyYABhyw122hnnwTP92xMYs6o8EqEtta+0JY+lVHiCUSWXMXtoDycCVA6W0TKhOcl sVNt3+PfoLN8dNb1CkGk0GiWEjR9bHzObts84eutHqiDuzbhayXwp79byKdUdwJWmeDw TIo34+XPJkiQRZkAAheZgyiJRxAHj3h1TRglFOl3G3qsTCAKZGCL2SiqN7m7ftFQhWtx BeeaApCdmIf6npQl8omKfn/6K83El0q3yeAQ0RAInocPw747tCSFlIgpR3Q6R8y5xYSB saNA== 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=aV1K0SNOk0yI6Z70ZEp6ad97o+b4O1kINmomf6Bs8/U=; b=AsC+piixW2YnmO+lBHe90IrA5cOuB7sRuNoMcFRC6TsGwToc1/QMRjpEndnJhkjaq5 vDbvxB/BYpIROGCRxXXOijbY2LSQtg2Uj9CftaUL9HuR74ZPIRIqQ3kkF/64+xEE4/K5 noc5OJuHQD/cNWmR2hseAre8vGnRcUcVbOdq9+iR0ecBroa/cF6zb/ASECx7rMji4vuF cTpclCyHxkAQe5vRbInYeW5vhV4UC7VJkXTgyLWHEImAaeBoAvmSNbBRpvqjxIQjcIJT uZUOWoT7epxjL+49w6ggSRqciedGdyurbgjE7D719MkjotZC0gJcV1WZ0PSlR4igmRw6 i2Ig== 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 f17-v6si11751834pgl.59.2018.07.24.07.49.57; Tue, 24 Jul 2018 07:50:12 -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 S2388639AbeGXPzI (ORCPT + 99 others); Tue, 24 Jul 2018 11:55:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:55670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388516AbeGXPzI (ORCPT ); Tue, 24 Jul 2018 11:55:08 -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 69FA52064D; Tue, 24 Jul 2018 14:48:17 +0000 (UTC) Date: Tue, 24 Jul 2018 10:48:15 -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: <20180724104815.05d2ac68@gandalf.local.home> In-Reply-To: <72573a9f-694e-fc4b-cfd1-d9cde504a480@sony.com> References: <20180723134210.54013-1-snild@sony.com> <20180723095550.08203a24@gandalf.local.home> <9d762b4e-20a7-578f-90c8-10a044921d67@sony.com> <20180723113741.66df3b50@gandalf.local.home> <7749ed7d-50d5-4b95-fbd2-b056a1fff957@sony.com> <20180723124154.14ef0679@gandalf.local.home> <72573a9f-694e-fc4b-cfd1-d9cde504a480@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 Tue, 24 Jul 2018 10:17:37 +0200 Snild Dolkow wrote: > On 07/23/2018 06:41 PM, Steven Rostedt wrote: > > On Mon, 23 Jul 2018 17:49:36 +0200 > > Snild Dolkow wrote: > >> Any issues with the commit message? Reading it back again now, it doesn't > >> seem quite as clear as when I wrote it. > > > > Yeah, I think it does need some updates: > > > >> There was a window for racing when task->comm was being written. The > > > > It would be nice to explain this race window in more detail. > > > I hope the following is more clear: > > kthread, tracing: Don't expose half-written comm when creating kthreads > > There is a window for racing when printing directly to task->comm, > allowing other threads to see a non-terminated string. The vsnprintf > function fills the buffer, counts the truncated chars, then finally > writes the \0 at the end. > > creator other > vsnprintf: > fill (not terminated) > count the rest read/use comm I think it would be better to state what was reading the comm. Like trace_sched_waking(p) memcpy(comm, p->comm, TASK_COMM_LEN) But the rest looks fine. -- Steve > write \0 > > The consequences depend on how 'other' uses the string. In our case, > it was copied into the tracing system's saved cmdlines, a buffer of > adjacent TASK_COMM_LEN-byte buffers (note the 'n' where 0 should be): > > crash-arm64> x/1024s savedcmd->saved_cmdlines | grep 'evenk' > 0xffffffd5b3818640: "irq/497-pwr_evenkworker/u16:12" > > ...and a strcpy out of there would cause stack corruption: > > [224761.522292] Kernel panic - not syncing: stack-protector: > Kernel stack is corrupted in: ffffff9bf9783c78 > > crash-arm64> kbt | grep 'comm\|trace_print_context' > #6 0xffffff9bf9783c78 in trace_print_context+0x18c(+396) > comm (char [16]) = "irq/497-pwr_even" > > crash-arm64> rd 0xffffffd4d0e17d14 8 > ffffffd4d0e17d14: 2f71726900000000 5f7277702d373934 ....irq/497-pwr_ > ffffffd4d0e17d24: 726f776b6e657665 3a3631752f72656b evenkworker/u16: > ffffffd4d0e17d34: f9780248ff003231 cede60e0ffffff9b 12..H.x......`.. > ffffffd4d0e17d44: cede60c8ffffffd4 00000fffffffffd4 .....`.......... > > The workaround in e09e28671 (use strlcpy in __trace_find_cmdline) was > likely needed because of this same bug. > > Solved by vsnprintf:ing to a local buffer, then using set_task_comm(). > This way, there won't be a window where comm is not terminated. > > > //Snild