From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793051572; b=a7zoYKNAjxZUrhuaT7YCCLHfezh3R7Ur2+y52sHEqWbYHWsFtlxcxX38gktt16Us/OzC vBcDNfeg4EJwvJcqFGOV3SgDk4koGfhPl0YPrfrljBVWiWZsjVCJW7xpT598DgpXYMFEs sSCp+kk7eB/GLSA7f9ixYH+9JCSMiNk3mk1RnwVVgngBZQ+ELLQedVQ4rBVbC1ivh+mhm ensxne79dhW/dBiGjae+L44bb7ECtCsqUXkXiUYwnDKKMgWZZnnI6N9Ics6VmGz1Evg/C Q2z8vKqTbJ3rtDGVhTmGEBbGlRXe9D3VX3Vy+nohIfS8mq4X6weHX5i06Zj3Z/qlaIA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793051572; 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=0zQfCS+xbNCI3ecGYMw9q9f4jA1EzYR8/pz81vPbgxA=; b=byTUKhpmsehfVkm9rsOtWwtjh0Uboo+UrgpY0Iq/UErrqKmJDC+V0vG+IKrnILiS4f4n ofaqmKihKtrvhSnxHDhgnJaTVDYFvgiRDZRo3wr+ox2TCU3Om76EmKLh1vwsb67o8rnOe Oi3e0IMRhRDio01mz6YpT1ynyXdbh4jTsiWyx/zjlpZfY9QVVhvJjra1naAml65JcJMXh NsbxdCrSCOv5Jm9JBG3wPvjtl4DjjM4uxl5H8eyA68EPeH5uYBfb3UA2Ch2Hd2FNZfJmu 3zjQGtWnmLCa5mXHoIgsJQUPralkB0hZWWle/uY/Uqvyen7/0fLwLAFd9v3YEoRN+tA== 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=20251104 header.b=RC8kMmU1; arc=none smtp.remote-ip=209.85.210.199 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.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 4DAD560A260B for ; Mon, 26 Oct 2026 21:52:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4DAD560A260B 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, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20251104 header.b=RC8kMmU1 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-8a0688a43d3so2443947b3a.0 for ; Mon, 26 Oct 2026 14:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1793051572; x=1793656372; 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=0zQfCS+xbNCI3ecGYMw9q9f4jA1EzYR8/pz81vPbgxA=; b=RC8kMmU1ng9PI0xVDUVB9y4b2qkHrIc62PNyX4CzWbIdDe/vbucy2fxbMQVvz5M/xe IO7bs505etfgEHNsbXHOq1v8h8HofxMyo+PKPU+my9lhsGvDArvAYhYz55zgEC2MkyOf J46ym8a3S5Jp5fu3b7pIzq3ZgvKG/BWDa77DRrlIIXA6EMPsQpKBLv7/sbzdO6/CUcKe Hm4Zk7JL4UbMt2ax+X6noxQGwVuFhcvfgX+0jyCFIlr0T4a+inqsYhiXD0iuHZueewf4 BhOxnojGjwJATQ35C5SS63tXVQxqgWO4TEgqnfuB0+6qy3MHnLM2dV3exIa8s5AQ+XD5 5Lxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793051572; x=1793656372; 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=0zQfCS+xbNCI3ecGYMw9q9f4jA1EzYR8/pz81vPbgxA=; b=ONryq/pN2Rti1n6QBlvYoVLIR6LYEqS9sqW703+FNQ3jNDzsv4W/ZxAs/vzeEDQ9sP lp/dkedeV4AXPv1eojHEa1T+cAHuYpBGrMUYHafvnNM3ENmxGwbYC1u9CTxvB9JucCf/ h3jPgs+HwI03wFPWAIt2BYigBoeiEbWD0GdzafzeGh2/bMQUjdvk2WvwQXzbX6TKFoGn 8RZLPdGvB6OLtriQmbCi9kaXIrnzo4WcfngHcWnHo7pm2y9l+jsajVRH9FAi0YW4YoIP ovSKsZWI5GOTXoRRu4/tMwulbWIy9jH1TJBqINtMqHvOHfWPdiI2EaAc+32TJcbDFm8o FzmA== X-Forwarded-Encrypted: i=1; AKwUvBx9fpi7pN33Eu5pQfqh3ezjGxE9uRu1UB7BuJq14k3rPcjFKrKzIHUm2wtP3jJCbO8rtLx7LY18Vseseg==@vger.kernel.org X-Gm-Message-State: AFq9FYJ4lFJkxxzJ2sJMy6A4b7JqZ9Mxej6tUW4eIXa9szeGnvAvR/dm pooRgsYqLSUW3xXwcFVaVkwEaEbhGuQOvHo/Yb8ecJ3jGpLYO5Bxy5J7O/7virHeLhEyLZCjxAJ auQLDvScUkwlhGKiEKWbz4Q== X-Received: from pfbho14.prod.google.com ([2002:a05:6a00:880e:b0:8a0:6a08:e927]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:bd81:b0:87c:e44e:5694 with SMTP id d2e1a72fcca58-8a366b88ce9mr5902881b3a.21.1793051571129; Mon, 26 Oct 2026 14:52:51 -0700 (PDT) Date: Mon, 26 Oct 2026 21:52:20 +0000 In-Reply-To: <20261026215226.3713941-1-jthoughton@google.com> X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261026215226.3713941-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.0.307.g5fe7bd680c-goog Message-ID: <20261026215226.3713941-5-jthoughton@google.com> Subject: [RFC PATCH 04/10] stacktrace: Don't unwind the user stack without an mm From: James Houghton To: Andrew Morton , Alexander Viro Cc: Thomas Gleixner , Peter Zijlstra , Kees Cook , Arnd Bergmann , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Sean Christopherson , Paolo Bonzini , Jim Mattson , Jens Axboe , Pavel Begunkov , "James E.J. Bottomley" , "Martin K. Petersen" , David Sterba , Chris Mason , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Josh Poimboeuf , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, kvm@vger.kernel.org, io-uring@vger.kernel.org, linux-scsi@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-kernel@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. 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: 214d8ca6ee85 ("stacktrace: Provide common infrastructure") 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.0.307.g5fe7bd680c-goog