From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796232541; b=ySdjGRTJSWXa/6qyuMrqOY32g0psJ3aYMV767q0Yncebit++tmrrnFDq2UKKkwZz9FjT dMUFlXOXvTAMRqEPXtgOvLEXWEP7unmLw+DZdv8ENVfr6uM9EFDNYmRvLgSdGXFrsMhzn ohJ5Aq300iXck4388sfnItbGTWexSWfu2ZxQEaqFM6pNOV6bbHybADB18SHEp9hWgHcBl RJmoNj77JAjD4NmLqtlT0QpLJqSDiUR+NB+xoiHU/euUoN5W4J0DymHWAgj63N64L89Ma w/Kp60hmEkZQJzt9Fv732sGcoIZpfhbwKW/ern4s7deEA/1Ho6/l8hoqXsr69L0itPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796232541; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=yZSoTVHN/Pi1Ab+vqq+A8ChSxn9Jqwmgx3qN8Pp8pZM=; b=GxqEY6rVtfO990i8t85CeFey35TVTG77JdDt7NkAvpjQfJHB4V84uz5FDULicZoyKNZb ujow5n7QbgUc6vssGc5P87q0fQz8ry22q0SwkN3e3i8EfzlOF3Ztku1B+ejbNMdc3UQKO +aPHywckUblnNAKUlP7/8VMSrb7G60XdOomq3bohX3Skec+nSK4LhWXmh0pkr/nnqx7o9 1VWnq5GZ+xZSDH64PEy93rmuFR5qREqr0C1K7cvz71qpLlNxXQ4Pv4fDDpm4ZAuktqnbT yMzPD6jY+tT0nzvrMNNDMVCPOsfAUH4CNkM5HyVBft0KeS8kcIMC/qfbDnQh1qOEJGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lZe+Z9Qr; arc=none smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 B9A90606A332 for ; Wed, 2 Dec 2026 17:29:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B9A90606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lZe+Z9Qr Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4b79502c27aso135948015e9.1 for ; Wed, 02 Dec 2026 09:29:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796232539; x=1796837339; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=yZSoTVHN/Pi1Ab+vqq+A8ChSxn9Jqwmgx3qN8Pp8pZM=; b=lZe+Z9QrfWMHDz2WR08hVnH7JqNFQBSaVWmKMhfJhsKIklw8TzYpI0MNSM52p2OkGr vjUgqybW9YTWiNtb1+K3F1002QiZuNRUrWv/wxwg+0t9D7ojQSgvHrZh8Cz/OVPu6mNf QPFM0YhEuHljGo3GOjOKGlTn/r66k61qFDzm75mDOZEUy5MX8xbHxHM71NEpBbM6jbv8 Vn73VUrG4mh0khOSqTSFyArRDrrncN8vPBJRqV5w53eB2ME0dL/xUbDlyMpDyLdGajcS FBNUghLtxXCIgyPBlSFzPBsqmLpBZyyxl2HuZrrM6+H715WH3OP6M6RS02YJE52LMH2h jZXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796232539; x=1796837339; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=yZSoTVHN/Pi1Ab+vqq+A8ChSxn9Jqwmgx3qN8Pp8pZM=; b=uJSbZznOtG2oVrNPmsrpLduip1HDLGqbsNr/2kWOIHSMCAwiS0YRS11EfVFjW8C+jr kOZ467Xp+3eNDZDAEcd9KT28o49hQBzeg9qHEvuQowxWoUNCzbV2a686I8y5MUNY5EeR 2wwZGGXDklCjlNLSbflp/NKEbHJuSaCGaSegT9V7heLnKeU0n8l6kgdFJBjboHoCZwlT 2Zv33q2ZQsYyIQrikGZZYslC3kaH+1J+fi7lk2ihSdfW+3hsUbTDo0M5us5znmfsK3zo XPPLsQSB7HJqR/eAiMWtlCKKTw4FZ/B3ji1Ulg1Jerz0NOl9CKHez0SfXKrxVzJ4U051 yZAg== X-Forwarded-Encrypted: i=1; AL+hErGhursZpo5ciKooGlvjdKEl3PtKFnXfr5RHf8KLIWxMIDv9VoRpZIh0I0bTg+XL7vIiHoixn146f6Nzw1S3@vger.kernel.org X-Gm-Message-State: APuU4Z+CEFZx3NifkhL/OuMhwtjcqPx+S6RX0ePNt2UPS3aKmTqjYusS BL0iodVTPM+O221PsQZpkaOJGPpCdGv5I1uNojDHbN/UfjjR6puZeFgC X-Gm-Gg: AZFdTZdjcyEtBEN+t3EjdlgjmHRqYM35xMdRrAuLE2YZv/sfUOSsfoMjZcWhlbDYuPU lAhwcTDdMDlPurDWlW7FfTsSHmJ28Fov/8JUjxtaXo5EoNjvuWN3PNyoNlRNM1Bpo9kdgO4OxWE csFFg9hc86aOiLgA6VccmIEDBsQBzOVE01jilR30E+FgUi0cnf/83gknA4bp2lj4s5IyqjPvnax ITjaD4r/ioWhynMPX9jQCm8dM8FXXyWbAT/ix2k0hRWy9qax129JmJPiDr6BqfToMjUSCLeJFLg UyZLOOfYXYH5EKws8ECVTOZiuIKkMBBGLFHPQKTNk7PARqBpOvisAtVpj22YJGPprKGyjBqMEmy R8YqSvXJeC3lJSLR1+m1Nk5ZAU/SbMjmfApKBrx29PKoduiSSKIRsu9yDy2kXL7OR23AjQVNMjG sEMmV9RhskWahfNV4/oXxaPCYR1mE684P8d96+qhcd76pKP+nfZzYwfGPUrtuwhTW1q0RBWl82Z RswCu/ePazvikuR9u7tUkT37wBCD61Uth9unnqGWfqbNc06XyncXJmwkifrC1OJiXva4BhIg3Qt +Utx4DzDhqQQkBE20MBUeu4KjZatIJTPnP5FL7uRoyTQ/W2H50fxX4LXn8wqhW0W X-Received: by 2002:a05:600c:1389:b0:4bb:6519:477e with SMTP id 5b1f17b1804b1-4bb88813b35mr834255755e9.17.1796232538885; Wed, 02 Dec 2026 09:28:58 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe00a30absm1882605e9.10.2026.12.02.09.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 09:28:58 -0800 (PST) Date: Wed, 2 Dec 2026 17:28:52 +0000 From: David Laight To: Steven Rostedt Cc: James Houghton , Andrew Morton , Alexander Viro , Arnd Bergmann , 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 , 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 Subject: Re: [PATCH v2 07/12] tracing: Don't read user memory without an mm Message-ID: <20261202172852.4b1c5227@pumpkin> In-Reply-To: <20261202083259.6a20484c@gandalf.local.home> References: <20261202023920.595207-1-jthoughton@google.com> <20261202023920.595207-8-jthoughton@google.com> <20261202083259.6a20484c@gandalf.local.home> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 2 Dec 2026 08:32:59 -0500 Steven Rostedt wrote: > On Wed, 2 Dec 2026 02:39:14 +0000 > James Houghton wrote: > > > #ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE > > - if ((unsigned long)str_val < TASK_SIZE) > > - ret = strncpy_from_user_nofault(str_field, (const void __user *)str_val, STR_VAR_LEN_MAX); > > - else > > + if ((unsigned long)str_val < TASK_SIZE) { > > + /* > > + * Synthetic events may fire in any context, including > > + * kernel threads, which have no user memory to read. > > + */ > > + if (unlikely(!current->mm)) > > + ret = -EFAULT; > > + else > > + ret = strncpy_from_user_nofault(str_field, > > + (const void __user *)str_val, > > + STR_VAR_LEN_MAX); > > + } else > > #endif > > Instead of adding all these crazy checks, and then we need to play > whack-a-mole when we add a new one that triggers the warning, can't you add > a helper function for this? > > strncpy_from_user_trace_nofault()? > > Where it can be used by places that do not care if there's an current->mm or not. > > If you are reading user space for tracing purposes, it may be done from a > kernel thread too, and that's not a bug. It should simply return -EFAULT. Is there anywhere where it is valid to call strncpy_from_user_nofault() when current->mm is NULL? So the check could be moved inside. Unlike access_ok() (and friends) this is a slow function and no one will notice the extra check. Thinks more... I'd also have thought that kernel threads won't have anything mapped for user addresses, so the access will fault, the fault handler will see the flag that 'nofault' sets (or itself check current->mm) and return -EFAULT instead of trying to fault-in the missing page. So the extra check only affects threads that have mapped user addresses but don't have current->mm. David > > -- Steve >