From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796232541; b=o2mBWJHZsYukF+2bL+O7sCBnVmBo+0jdomzAvLrppR2BvfXNluJ6ovj1AKK8MzOazI7W V9GlCZOpYi0RXnizw8so+pO+okBBE3btIhlIM66eFjTXPjSzLQ3k0gGMckSyBeDAalDgg RJkDYfU3+yVLGXaeNnmp1GGkvTdxPRE/gc9n7oVEVFXdYM1inJsc59XaB9yzOlFJi1RMc QlBhhJUk8uxr86lS6gh50in/0iaCQYjybw+vMbj696BdcCZxXO3UyhEOn9cC3+r3U3229 Nt04997crqBb/NHLjNo0npWpmPidJXwdQ3kDE5cCh0qIg2JVL+GYyisPHLGTtZta6DA== 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=IhhkTv24ua3Tqvw/vP/ld3nBlw8JWRwZ/TlS/56BrX56IpyxF6bDQ0JyEBYby3ZEYKYp IlMCMZs7MZ5/eibtjQA2VaNQcVglHj4+FQ+1pOUN+K6yF/0vvI8oOBJwvI68leEImNKpF fbbWcj1mna2tLIP+6G5LwlfNEDTmhtQfe07JLP81ioP40Ove3jeFAwVPoOuLRus9G1Ga1 1UcIgappTJwaaeIMNJvWIWuzL3c4+tF6oJdXFtp/XVKkoZ5r440wZTxuLJ+nlJHycpLqG 2YLkSn8GeeiSfyXS5MnjEv8qrt6i7KMv+PilmUYn0+ncRN5tFqXQ0xJ0RGRzmlgkTLw== 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.44 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 BB48C606A333 for ; Wed, 2 Dec 2026 17:29:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BB48C606A333 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-f44.google.com with SMTP id 5b1f17b1804b1-4b79502c27aso135947935e9.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=vsZO98LyyiqX84/jTXOLqHEPs/2zgTFFsWCUZajeMZJ3NOi8eCShlM+65hmHgwKPjx CMZYUlPL4JUEkSWnoSqTSLRPYvhsbh1wA27K0mY1AwvZeLuKfH3IC0UcVX0gjlJpfoJC +LqyXE5MxPvDGczmyLbgWJhLZkLVTXO8PtLxyANRTN6g6gadVK7ONi5gc+MtSK5VaJIe iLZ+nq+UyJP8QjSLUwkL7TsFH/bumy5pQc4C4nrNRk0aLWrdbZuj7LCzpEbO7pHYmRtX O9gjV9TcHOWcHuthKg0QHkg+6T/27pZ9ERXXrCp1uhf2gcFm5rl5P0wldJYRTEo15jt4 NpCQ== X-Forwarded-Encrypted: i=1; AL+hErG5hy+6/abhDtLNKb8BEvTxCHIykP0Qk6MufmldRO0z+BxYpYq+xXJhmxgM15R0wopMCNT9I68Mog==@vger.kernel.org X-Gm-Message-State: APuU4Z8Jx2Cu84VlGw3RVBX0t2IamWlxYJEtqcxPJ23Q/fPkybQ0Sd85 GOhfzuw2LsFmdlxFaHB4/Mlw2ZMdLIYvd/NiwOOTAFMk5rK/a0agkreI X-Gm-Gg: AZFdTZfVCldvnRV/mzA/6dq8ofvcyEdmi1Dr81zUXfJ6T+jSsXF18wWvJQac+wdBpVe QQnK8SLDPctAyNwRt4Q9DXwAt7i/yfa74t53bimxFKTAfNPjCWP31Me4LOiSYk3vCfLWbsoZEOL Hmn+087XnVydFNFTqQhNURvZLcx6oGuR4Msb0pDxq9Xe+PgvKxmWDV/Id2UdqKhIPtYIUIMslYF B6tVvhiT6Fus3uqv9VcxDv7alCnXtVKZ2SSzJ2qOJ89Xm+UJHoHSE7Y+Fu9sTEVkrNalQ/BOWmO pGLAyXDNStqr2Qe+hHNloaBUVT5Qx0f35HUkJoj1hXH1Dds27n+qMLcBs7ObzBIg639KFDxNqbX YdSLM9fwCEXmF95JfVLiXMebvwkVtaQocLHwroSSrAfmYUwQh3Nb5sm7F8AOguSdL8kTFRYUsvZ JV9P2LC0iChxwhxcGtIVgtXxesEcWYw452p2wFVMu35Al7xlLozFg73Vrkw/tpk1GMgDRAF2WT0 57js6Koo0ouIW3AAlOOE1wiD3HXedAkwdHmX5x6+NcB7q3P8F4xvlSw/Oj5uJYi9qjRqyJAMagA xbXtMHQeeiK2H3DXAO5GyCKRofaIRyY+dEBI8VVXdMlY5g+VzqPAurfuTKn+KpoI 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: io-uring@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 >