From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179173; b=v0oEZ/ykZjkVzgfIg8+YVouxvVldFCJNbTdn7mgXvE3VVMc3GYpPPHfdgudf9xxfpJVU vr+ky6Ourh5gE3FyGpoC1KBHrD2LuRGbXx0HdbGdcNCCWJfusq9iQklJLDp/WFnNhy5ik kpCtVV8NJ80sBQRRmoY9/vS86mH+PUgpO3S7SqY35TsNtbj0BNZ8zrRWLXRP78BvnPhY+ If21EtSpqWf3aUu258htYX/DzHifBpVyqzdECNT7/6zd/U37kEbuVwfBdY4apmQk3OumI Pr9grcd8fQownKuTqSwpKUn9sGdESLStk3kd7tvjBMBQwrsB7+93yTztnsNInfPaH/w== 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=3rd+OjNa5tUMLpSM0tfU59maqvfhSLCuwcfE9R7uq1vnZE0rEwBKSCCrTGZ5vJrenzqJ e04vUQyjKKKR2cKQNsrMEuYMi8v5H9k4yYB8Ru+WhU0GwQleh8CuAm/n2usZZe8yW+C2H OwIXqcMnEp3dWgUUvvsR28X7B9vVHLhfMjGsjyYdpYzoIDPdXGH02V6hWnfkHtaVQA/hL it5lJktfZJz3YLZrd+Nco4kfH5HLeOBzMq957Ynk4h7kIDt/mwzHquL78SPiR9jvFqc9Z WMYNxNOafRwwZV9Osjgn17TwgWryjFtyQf6VWoj28f5fMOLa8FgtFnGftTRuUtb/w6w== 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.199 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (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 9D20B606A33A for ; Wed, 2 Dec 2026 02:39:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9D20B606A33A 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-f199.google.com with SMTP id d9443c01a7336-2f0329e57eeso115371295ad.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=Vuezsx5ug5W0b8+RBGq/l12RmbKWe2NA8zuyCOrjyjErAMp4dUHsgiF22bP8kBhteG h3dq/9sHtQn1TSjixDfR03pzOqk2qor3VrcaQdyKG62AZ0+265kQUdtBw/uQrhSxnp20 ZNPBx9VuBrBKc/esKxyLSWXQwWZgGZ6L+YC32QPUBAAhLcYBzyY+k2zn+VpHklGeEidI rJXvFIFZubgfQOwr9AiHD4gHzHL20L8GVHd5nfeRBPQOgQF/sM1zYQbnMV0vovD5vKaD bWKqrd15K5tUkAHtcL7UlwAMtgkz22UWF33yiw6JUr9mKPACOxMmLj5XhurTFwVEisLq CymQ== X-Forwarded-Encrypted: i=1; AL+hErFqwwY3OsU+PZ9VnrNod09avITRqet7zR8FpUetaIP8Sikeiy9rWECWCLWp6Q4UIuCub0ZxQfDFU1EpWFez@vger.kernel.org X-Gm-Message-State: APuU4Z+5cceKNA+UVImork2cIKYDzwYoYOtCV0vIXP+MGN1YvhT/nKlI 5QuYKqvxQFq0p1YBrBr8ErkQ6OHGcyKyvJkQL+2WFRjkoyf/VQenmLpIb/a4g8gemCIh6kyXIoW Z5mWqqVLi5TxfzdfAmNWnsQ== 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-fsdevel@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