From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796232541; b=N6ILgr2zFuD977J9wZASOSEOEXcw0BRA3cttoSk5gXqf0DXV+4VxvWkWLXpHFDfNXGyQ vzGeudFS+6tUYo/tZGSo4/tgni89vdaWu592ooMzeEgH6JhwBB76V4WEDO6lBJvG5FWF4 VA/MyAGUHafxyFnHN34Mrw0ZwB/4AMQbfnI747yjyeWW9IqeoKVPZF/YcTfqHVOG32poI w6WCvL+APQ/N2JnyML8dEZqWJ/9c/617aRr1v+kCJWCao41WDaQGJzb4xUvj3a0l0kdP9 ZG3P9pdqFtbuxvE+b2GOgXgFxkSp/C64E8HijjPIeSCODyJC2MIeOoB2A07wr4ZZn9Q== 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=BwxIqZUfvVIBbuS1Vn6fPrzW4MxmfbyxVCvFmP6c/AFnv3ejkf9b4J7NcX6sSu8l5f+8 wBhy6lKx2mEUbnGmNKHTom8zK0Y87zqioTMgstws4Em2qiFIO8KkZSsGbcX6t2HAYbKg/ 0KV04maBy+Dj0TKVTolyDJGZ/Fg2/CGN1OTVByE4oe8JVhLE1KNQP2tYXWpHSkHUGNZJ2 wD2mspOh4U1FLup9aGmPus3TVIKWz205TFUSHr0oQu9Z+7CiBU5LvL/KQ93OMRPsez6Lo TJv9Ecs/kWb/w7pYADGK6Yb7SX2XMoiepnFK6piWyj573KFyMSDRHcHXZKwP1Uvopgw== 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.43 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 AE626606A32E for ; Wed, 2 Dec 2026 17:29:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AE626606A32E 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-f43.google.com with SMTP id 5b1f17b1804b1-4bb72b44a97so116090325e9.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=yV4MkEW9o0g2NeH5tKk/eHbNT+HyHdCBXUetAIQEJ76mh22LfbAM8o9U51PDBB1f1O a70iCRiTDXaJdIewYq235e8D/3uu/lypkE0Wp6AnmMz8w8d7UMd2Gpyk475/S4kl3LaS Zy7nlwzUHiybnfwR+8CiS4kzczVyxisKnom5wy0ID3zrFQjSyJkaXjD0lPcRtwXuRplL DdBKCO2tO2dmThOqTFUn3tGBrNBiEbnw+3dNrehHjFw2HJbTvKCauRBoy0wEfDp1xvzi EtAua6eJvd904qhH1nLy8atDN5M4eJzz6QYY/qD2r3Timo5iOTMbplqBAwzgQJP5vWnE 3hDQ== X-Forwarded-Encrypted: i=1; AL+hErHuqQd8eLwIOZuqU7QmKKRXY+17BMrlAZNbsW+gsHFTugOXLAGDduDDbW+SqbekZuP6zGZ0PlsaCImSDHGpSbKb@vger.kernel.org X-Gm-Message-State: APuU4Z8IDm2LR4GBVGlP6gnZsHNDT2bXI+9Fq0tfxo9op6YGbSCMyL2B p0ujHh4jWxXS5EAsPVe8JQ8U9nUCsVhe0wcQJR5lC8Kbecn0F+X3i4U5 X-Gm-Gg: AZFdTZfstTL4ZmLthscAKAriniTEy36ffRzZ7S9hf0O6oQ/TLnK4anLtxo6wzmN0sVW A8DuzXkeC25cY3iP/OQQa3LXG+PhCjU20VmlAx2BAQh822Db3zeJnC2IvgJQpFt3ZZ5GPYqMUIq M1ljpsSBbQa9Jq1zcpQM/Q3CE2i/jhMKqLSv//HfobUy+VKMfBGAE7Soel8yQxrvzoP51sPmtFd UAlPW70hBElJjIe6Xe1Xw+n/1MI+uRhuGDSSMFigd+QG7hx6VwEspBcJe9AK/vXKnyX2h05U0EC 06uZSHta2wnLZvup5+aoxiDNQrWyLtGkc2RnoltQmlQ6SZT6xJeNkV+HYtdYNa9PCoMTjiBrnAO Ru1S9h/b2VFG+c7I0Wx8GtUIgB5GKkAbZIXYVSlt3xHimhQlg2RFZv4Br4GDFj1RjZKnU8zG0K5 qFSJUissVtbFAdQKpdDyJolLRHr4Ho+87y/N+RhTI5UhaqKf+D1Mo+kdb3AwX4l5CVY++45jt4I dosbShc2E+mysco0wHUQSIiKlcIP6oSX3W+BVihHCGnYA3HnKLiniDAqZIgxF8g63cdazpVRasl f8EL5/iN2Nfxj7TCQ8ggs/a/HpsbeiP51zAIXQ1Q4yocbvcbNkKalXej59RCHPc0 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-perf-users@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 >