From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179173; b=nN/nW9qjQGmT1VYQqyqYMZy308+h4qucY5yqxPfCk792Dej1hIREVpGWcupzakT5bMOU xFaseitvEvhvMj9xbwwEmMwbxEvllViNvQxma6mGOlOMG78GPzjAQP0L8YAXrTtPP68Oo 79j5kjFYxKmXWeIAu2rX6e63BMT5GtJWp1dbpa3U6fKs6WXSwYtfG11dQeyoPEIybXNwe bRkMreIHA4Z4bU5mx7tZSkCyvz4MWYh8C6XhS+opd+a2kmBgMkTdYAAssSquke+Fz0usT AMZ3b49wjYXP1XVj/UuaUMWz6KwuaM/M0gS/Esh/4Do+l8aBNObFTclsqiZcSU7/lOA== 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=qlr+7APMVUhumVgOb+AaUmDDPHAN4QBOxI6+nP01HCRrB+l8hLZB1Pvh/PdpxHE+P2YZ 2pYl3huo4CfGCdJkyiTse8rtceHBXRR5OoNR9IheOmyPron0zLvh2q08AxBcojfajSEKG LEFGDq1Jc3oXsuQh/FudbdsPA8xyQ1RY37y32s1HTRlend/QxX3Kh/7L9oyaPschAArjB lp248Oqxx0GWiDOw/3ZdguD8VluynKHlaMm8g+n5vmtmfs4mVKO5lUQiR2SyKtDmxs4i1 bMQtfpDpmmkHobHsYXb08ZEExeeeu7y560P0CkkFF9s7jkRi6POm39JgNKATgj2hxpw== 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.214.197 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 BEFE160A383C for ; Wed, 2 Dec 2026 02:39:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BEFE160A383C 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-pl1-f197.google.com with SMTP id d9443c01a7336-2f0329e57eeso115371315ad.3 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=uDLcqz/V2nhAwM+DApxHOhKNvibLJ3Y0WkmGGFhwcaQKCUdW49ZtwmsLCFmKmEBr31 jRghYIsdi4uMIY5caenzyFtGEFQNJQ5rxXaavIB8bnXsPxtaYY3fVAy/vL6LlO3W18s7 WcMcgoHfs6skX4ZR0xRhpLBLkGU6iHsIsgNQSWOVmxl0XKJ3q+EZU1UeRZ7t84D2tqGG 9pULOqdcA9zcfWSP+rv6ZbRh3Irqqul05jO9px/klHenUnA2vlHPnErk093jKC0soQ8B omijYs74Ske5raODHHAtyLYfhgP5KTHhu5iX1wDyLxmn3BiAUcuUnAipI+/haEErJyhc hdbA== X-Forwarded-Encrypted: i=1; AL+hErHI8lk2ZgUobs2N/zG+e/0FritMqAqs8BeuG/2A0G+dYkO0o0EOEjqsFFILiXpcGeL0ixw=@vger.kernel.org X-Gm-Message-State: APuU4Z/xvmlSmOhyd6pHCRB0x/VirbLWk+Qo93EERXoEcr15Wu1Vcunv nTtSRrhSZaHQj4pP9JHC5CuM1K27Tu3MH2tJdmCnVT/bvrqsi1FgSZar5ahyKi1mxftUqi/f8oD R+a/TpSJS3L1IkGvnFL3W7g== 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: kvm@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