From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796232541; b=htbph0kSp0Ns0z/afIKgPeshDi+iRUnuGd4BNxIuP3AiA0IabLuwtf5Sd0xXx8DUN2Ix +416RIdeEqYRtz+OnratuMlCfRPKidWHdbRl94Bkbpr4Ph+BE437NomcP8N7k3VBWC0s4 3hmZFiVCKPDIXg4+o/fILhBQQmlR3lm8T3rqMDmysNbtkprfbwPvfMUa5qjQFMhJBVtI5 qoRhgM9SeQEsrkVtyXCnHEz3TruQmh31NofAsvoi8x/ROgbwex0Fve1JOYCW/1E22CKf5 1EvYR4KUFZ11NWtIw7Jb1/ZSP2nAEel7Xhfu/hmxfMPV9oUsgcIM9vMtCOQ81kfCWXA== 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=cWbnkyRgifSYsBnB83pL7Ot52eZr72XOvuz5OXPnPFVJVSLwPVNGPsn0QM5HmzSBmsFl nH+0JTDRAOBfvvsrsEoyqhxciHintLHILFo7JuPL1/gVnPF0hly05AHr6/kEnD22kavcE Y/4htJWfo4F40jPIJqTCvdtFH8976lc8HXwouusWaGYboSIwCyHJvMoU1zSfDeYR3n29N 3/utMZrt+VO5pS6E90gAl7ilPibkN/C9AvnyRg1bxoAmpsHeVpbqfKmHkcd6QIlH+EQ32 IuwZaZ9u3ZkT+FrHZHmRRhoVFEMU8mBZrENHnPmslGIoBTr4XIy9uT9UmDjiUTFWJbw== 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.46 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 B12AB606A32F for ; Wed, 2 Dec 2026 17:29:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B12AB606A32F 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-f46.google.com with SMTP id 5b1f17b1804b1-4bb72b44a97so116090375e9.0 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=PaPjqJbhimhpylEo2wDPK42rkNKJuDZ1teCC7LXs1aeqAHtNPZFUxPJbVUTuBJtiwR LBR313czVna2FHsrsC5yDZqzO3ZT0y6RGz07aUzHY07kj6SNaRxIiAp5fiPYXwCr1RG3 20qFEYFqWCyq+ChXUj+kqkgrJGTKZvBKEmApPgeBpkCd76QSjxfitCiLxZ67xQyklxUn Kh2rUUItKP/Xx4nLGPiYT5b2sx6zPWxBbSIm/bbveG8XMmpqPTUDb0BbKlaZm5QK5V4p wL7PiEiHW3/XpctkMYlL46q48H3fPB5ouM7J0yYaEKnwHZ/m8DRdIsXxAzee5mDemO9/ cCHA== X-Forwarded-Encrypted: i=1; AL+hErH3JBaLozl2dUBEbEa9xzjH2l5JiFliMkR7+6F/UiLgz+kUUlxTFEffCNw64wfHdYJe1H2wBX7ARQ5o0Ia2LQimqTg=@vger.kernel.org X-Gm-Message-State: APuU4Z/PL5Bmvgkk30C4lZ24KgRo3hC9KynSk0GhhdhO5M2HoG6EQB0p tQFy6w5cIVUWPOUWgAgIjDVxIIrg9C/ZUhdStTMxQPURG+OdYzLbCvQ7 X-Gm-Gg: AZFdTZfqbYqe4/4tQuXoMSNWGTD72yF6E+tiyHID2AShorugpERM7eh7m3xb7uciDrj 0xXSAVGcIjTZw6J0GvVRpcIWA1xhqxyJEgxZhE9dnM6lonY3n3GYlCdm6JnoD9zS31qUIaROIWU RgzTDi3EdEwmRSzhVe5U6jnZp6ohlvUI7xLOD5O7EqGMlS8ovRrx3If35j2CBYSFSFeXTRwec8X T6UdJtvyKfxMzgP+W+64DEGlTekTilEsTx/1qOJRLNX4VF3+Ddi3iox5E27OPfqoMzj159htS4f GBoo4PBKQ8uba+5AyFbsj/B2ZNvrFo3jfyE4RsGALAOYcWQoS9KqnIeB1vt0yT8kCl3aj6TMG8w NMkIK0gnQvI3ZAj3Jwi1jz9y1MZ/7WZnzgTL977Y4lXe23ZNEWwLrtYt8/NaOK+3fuoLYL1n6Cu zhB7YAvj2ZZpLGx5S7kghlRYnemP3HrOvC0BjEWH/QiXpDN0xQLJluavV+Z8uMtVswzq2pFGv/A jSd0mgK2zy14niMoYdbpccxmC33+qruIN4Zmk0m+vh0ICjs6boGpRaH0SLSABYwsPA9L6Gl3xnn JlSkIrclisX7q3aSJrUWcIg1qB2Grhoyil47j8sktbE+Lq7sKxOMuI6J0J0u2nZ3 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-trace-kernel@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 >