From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179173; b=YemGS6j6eDk/PMjjLYTdRvjF/QwjALsUyZXZtRWgAHqoX9Ph88a1C54hCkqKwqP31tDd k5Uliwt68z5yo1cAb+G9gJ/sdQBASpRFlygjBx6b5vMksfQfxVfq0x9mt7owoibaMsXCZ I9MZHMKu6QQW57yqPB+h4+TUvTo2mFiS1UfdtQF5qRpuY+KQswmzCtztl3I7+MaanZvQu TYgFZ9rUMSDdcIWTJl4J8hcebAsxBIkbmZXnFhs6nbXc/BwrRWNzJfqckZwHFLpaivAqO 8JoUO8ru2MfJZXFbw4EDPbkp2Zuv8aPa9mjk0VarzILRUuY1TeefqXQMXdUyUCp+T2A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179173; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=07DNobY33VZaSbTxdp80jhubPI2w45YNR/JgVYA6NIs=; b=nG8PYbf7oVicdrwsrGIszsVtVwvE/5dvJ6lUFnE+HnOiDbrxfOspJeIhlhw4MRIezVzk JxVdi5WJHZcySN4WoCceFUX4XyrvUhp5UbZ/8moUQ3q3nMZzpkkj+/HLBlP+NHOQXD3LN fBn5U1VE9Iiq4XV3rZ6XnCYiHtaxv4TGxZ9+tiv3PAiikwo3rkN5PiwN+ekhZkJbBzCPg t3nDKJK0pp8frzh2sfb+b9AKKkUbV2cPpQfBVIdXmBJ0RbEe9iOR41I/NYz4OmOn0F348 BoqV4/eFUYm+1EhT+mu8aD4yXCR5Tevk05yISnv94aY21jAghvuXznus7oKNVS6OzHw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=F2mqJLFT; arc=none smtp.remote-ip=209.85.215.200 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8AB960A383E for ; Wed, 2 Dec 2026 02:39:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C8AB960A383E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=F2mqJLFT Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cdb8c46e240so7473871a12.1 for ; Tue, 01 Dec 2026 18:39:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796179172; x=1796783972; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=07DNobY33VZaSbTxdp80jhubPI2w45YNR/JgVYA6NIs=; b=F2mqJLFTlBi+RiHdOoy22Na4C6dw8beg6+nk7+kLd5lhsl0rxIj2yOODTEQIRFsEzQ EzbiE/xSrV0qQ8R84LdJtgjPK4q6OQjXwaVxLuZw7buYbTF8lZwcjh40EVyLPRSFEprr GSlEEuxERIM0zga69+hS65t4KphGHFAbv34dYhn27p4BN8nPIaYwTlYclhJabW8BZqk+ zxHjgiu/BqCz68Fje7gOASfuZ3fJ2D0vJsfQNcECEljyBwgqtCQDhJtcmI3OEkv708pi a5nIzQGBsv+oJh/sLSJ00jf9DAFPkEDNSZIkWyKKsLH8yawW95ZO1jcn77XmR0ZHzhmU oM2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796179172; x=1796783972; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=07DNobY33VZaSbTxdp80jhubPI2w45YNR/JgVYA6NIs=; b=Xis2NJ6aP3K/u2TF0rVQLum73R2LbhFOqC8VGaTOn+9JVy4mV0/qBvTMe1Bg1EHplO AObvdBoqNxzvg/4Ptc3KGu4gFTPWlrtXUWrneGy8fFz8/uFyzj/nfgRpsCiDN4uYQZBc S2dOBzkep67IG0bMDwodBgksfma8x2hBx9qABTTnu0Kje2RluJdGNJkRGgJe9hwxxl+Z DR78yyJMsE1m9X82BCLpdd33HwlJh5u72Ns61oiuDHf+lrAgRwigQRAfrOCGeHoKZzsd ymt+4YgTI429PuekoVgVfaPsatBgCyntNmL5CKYZm9pCg7DSFJvBesYq9jMFQEH505U0 yFbg== X-Forwarded-Encrypted: i=1; AL+hErHOS2UXNuz4t3BKVo5bd3t5XeP+MQIZH5A0VyC/yTz7K362+A3RWH6/RAyQvp8oURHNE++qq2Efamo1Qg==@vger.kernel.org X-Gm-Message-State: APuU4Z/Ca4zwIeiejk6J3kCps2u+MPV0pQZcbw5qdaMod5K9vHjDT/iD uNzXM+coBalMF9fiQqxCLWI8PKFU3Xgnv09+1Pey/LWLuE2UFtAwtttNbYgDSRZUjHxT2h5SxSU l7731AZppr68vFIcRjWYRGQ== X-Received: from plbaz1.prod.google.com ([2002:a17:902:a581:b0:2ef:d0d7:afa3]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:c942:b0:2ed:4456:fb2a with SMTP id d9443c01a7336-2f03f1bfa64mr384086535ad.36.1796179171595; Tue, 01 Dec 2026 18:39:31 -0800 (PST) Date: Wed, 2 Dec 2026 02:39:11 +0000 In-Reply-To: <20261202023920.595207-1-jthoughton@google.com> X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261202023920.595207-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202023920.595207-5-jthoughton@google.com> Subject: [PATCH v2 04/12] stacktrace: Don't unwind the user stack without an mm From: James Houghton To: Andrew Morton , Alexander Viro , Arnd Bergmann Cc: Sean Christopherson , Paolo Bonzini , Jim Mattson , Jens Axboe , David Hildenbrand , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Madhavan Srinivasan , Chris Zankel , Max Filippov , Dinh Nguyen , Simon Schuster , David Sterba , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , KP Singh , Matt Bobrowski , Peter Zijlstra , Arnaldo Carvalho de Melo , Namhyung Kim , Steven Rostedt , Masami Hiramatsu , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, io-uring@vger.kernel.org, James Houghton Content-Type: text/plain; charset="UTF-8" stack_trace_save_user() only refuses to unwind the user stack of tasks with PF_KTHREAD set. It used to check for !current->mm, but commit 7e8e6816c649 ("stacktrace: Use PF_KTHREAD to check for kernel threads") switched to PF_KTHREAD, as kernel threads can temporarily use a user mm. However, that doesn't cover all tasks without an mm: - A user task that has already gone through exit_mm(), e.g. when an event fires from exit_files(), exit_task_work() or the final context switch in do_exit(). - PID 1 before it execs init, and usermode helper children before they exec, which are created with user_mode_thread() and don't have PF_KTHREAD set. E.g. booting with trace_options=userstacktrace and an event enabled with trace_event= unwinds PID 1's "user stack" during initcalls. With the ftrace userstacktrace option enabled, the architecture unwinders then read the user stack without an mm. That access does not reliably fail: the user half of the address space belongs to whatever mm happens to be lazily loaded, if any, so the unwinder may read another task's memory. Use is_user_task() instead, which also checks current->mm, as perf already does for the same reason since commit 76ed27608f7d ("perf: sched: Fix perf crash with new is_user_task() helper"). This also stops unwinding the user stack of PF_USER_WORKER threads, which never run in user space, matching perf. Fixes: 7e8e6816c649 ("stacktrace: Use PF_KTHREAD to check for kernel threads") Signed-off-by: James Houghton --- kernel/stacktrace.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/stacktrace.c b/kernel/stacktrace.c index afb3c116da91..f96a5ec12f6c 100644 --- a/kernel/stacktrace.c +++ b/kernel/stacktrace.c @@ -228,8 +228,12 @@ unsigned int stack_trace_save_user(unsigned long *store, unsigned int size) .size = size, }; - /* Trace user stack if not a kernel thread */ - if (current->flags & PF_KTHREAD) + /* + * Trace user stack only if this is a user task that still has an mm, + * i.e. not a kernel thread or user worker, and not a task that has + * already gone through exit_mm(). + */ + if (!is_user_task(current)) return 0; arch_stack_walk_user(consume_entry, &c, task_pt_regs(current)); -- 2.56.1.911.g883d8bcb20-goog