From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A87253612D2 for ; Mon, 12 Jan 2026 15:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768232459; cv=none; b=cOMRsrloTKJBf59+68Fmjnq0c1qwpCQucnyVxaS85PSzEy7TQigayGs0JhjH5a2m48bTwEErNpORVibqJUxUhitsJMoIjzAPY0ldnqSx8s9/HkTvU6ivPfeBZU1T9H2glh69JxpbnKlGrP5rXRkzugwoEwVQXoM4c3wKYmp/M8U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768232459; c=relaxed/simple; bh=Gumagb2Kelv1gToIkJNxiJ7CnRF5JhGc9vpKxcqq6gI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R3Q+QxEntnDvk/cLQ82lmkzAE9PPpV+ZXOay6K/H09xaFg6kFXhc0GpUG6IlJQhol9p88GOxxJVF+02OHFvYjUmU9X8c9aVOKGxLhnyngqqIVmAq23NNJZqEyGCEZqml+EciadwdHBCMQPKcY5JoCTmz2tbvReGiRj1pVAtJu3I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FMwMQsSc; arc=none smtp.client-ip=209.85.218.74 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--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FMwMQsSc" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-b8704795d25so184601766b.2 for ; Mon, 12 Jan 2026 07:40:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768232454; x=1768837254; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2qapUBTgVNiqcTXmWdBy92/Srtil3uAAM7XaJAm2tpE=; b=FMwMQsScvMFMXyu+pC4UFVIiyDewS5BPwcDiO7oQ3hiesiytsPTNch0V7ECa94XaCU rUVqEetlyjOevNThuZvhSewoPxyM8LYEmU5+/UBTtQr+vRhbIZ1PdhfHaFGqX30P7QTy fYSJhLrn+uZ2bKHnz/OMNnzCrtRi6kwAqDTMPny9B6cdnVHVRdKvP7mQ0aYOIEIW3jCo LhbiHaoQwy38Wi8TLcxnGPVScbtUPmT5ZVN8/YDvFaDmPlPaOV+vUyiXNibUb7Fl0Bnp Sdve6YFtMtMp7Fzcj+zHlY0gliWEjz5Y7UdKLDzstxCxyjH/3lJjhKgsdq+pXttHpP38 jMqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768232454; x=1768837254; h=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; bh=2qapUBTgVNiqcTXmWdBy92/Srtil3uAAM7XaJAm2tpE=; b=L/qN0I0AwQCLhhrZq3nfmIR9btZeaMlMHbo3z7B7MVp5EvWA9UA1I7hU1OXehq2mNt czAm+5xtSa9/d1niETi0VR4D2j58q5zaKz+p+6Z59BJsU3Zm0XpkbiLRtkllO4/Z60C6 741Xiricb2S38wUc79OYEoqrEqDAwLvM17mFwCXuoZOMeWLX3fsrFJxCZMFr2zh+ynCI c8Zx6FZaU4WXY8JmUYUWYbuIsZUPluEIKlMSavAXWBuOQ51k/Qa4KBcfXooAu2rRKWsa e8sM5J5hNkYvhOwADpSvWCwMbGmiXj4lZiqFL7J6NaqNcuI4C8jdG2GCvsTAW+JjH7a/ c3OQ== X-Forwarded-Encrypted: i=1; AJvYcCWV1uubOy8eEcm1hJNgIJ9cUdV86tj+JxTUlAe9ohwCRYwYwKNDwY1psGKFJ4BEkTpy3od/Iibu0kuX4cc=@vger.kernel.org X-Gm-Message-State: AOJu0YwzY2csGXbQRCmeiDdM6tM9MqGoIk5gs3QxVkK7Iqf3Ef2SHaYd o7c2Cj2i755F3eLEeeLZxqYoyXVYc+sNHsIEPgsSrB1iBTKl8MgMekdLEZ64RBPiP4zkJeZSxMC dEAbHr3psXJ58b0RX7Q== X-Google-Smtp-Source: AGHT+IHYpJ+ANWMsEPYGdlwYlVceaIe7xjP0Mb8XSqLVAMvUK02djlwbBFkmzuZ0j6VKF7A3vEi+XuD+bATUtIk= X-Received: from ejchw19.prod.google.com ([2002:a17:907:a0d3:b0:b76:da45:a7c3]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:fe0b:b0:b73:6d56:f3ff with SMTP id a640c23a62f3a-b84451d416cmr1924364766b.20.1768232454411; Mon, 12 Jan 2026 07:40:54 -0800 (PST) Date: Mon, 12 Jan 2026 15:40:53 +0000 In-Reply-To: <20260112132238.GDaWT1ntPxY8VD1hlH@fat_crate.local> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260112122236.22214-1-fushuai.wang@linux.dev> <20260112132238.GDaWT1ntPxY8VD1hlH@fat_crate.local> Message-ID: Subject: Re: [PATCH v2 1/6] uaccess: Add copy_from_user_nul helper From: Alice Ryhl To: Borislav Petkov Cc: Fushuai Wang , akpm@linux-foundation.org, brauner@kernel.org, cyphar@cyphar.com, dave.hansen@linux.intel.com, hpa@zytor.com, jack@suse.cz, kees@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, luto@kernel.org, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, tglx@kernel.org, vmalik@redhat.com, wangfushuai@baidu.com, x86@kernel.org, yury.norov@gmail.com Content-Type: text/plain; charset="utf-8" On Mon, Jan 12, 2026 at 02:22:38PM +0100, Borislav Petkov wrote: > On Mon, Jan 12, 2026 at 08:22:36PM +0800, Fushuai Wang wrote: > > > strncpy_from_user() succeeds even if userspace data does not contain a > > > nul. Then it reads length bytes. > > > > Yes, but if there is no NUL byte in the user buf, whether you use > > strncpy_from_user() or copy_from_user(), you need to manually add > > a '\0' in the kernel buf to ensure it is properly NUL-terminated. > > This looks like a bunch of churn to save a "= \0" line. > > The more important question, IMO, would be whether there are cases in the > kernel which *miss* a NUL termination, audit them and fix them. > > That'll give you a better idea whether such a *_nul() helper is even needed. > > Because converting only a handful of obvious places in the face of thousands > of copy_from_user() invocations in the kernel is not doing anything useful. I'm getting the impression that strncpy_from_user() is the real problem here. It should append a nul byte. That would also be a lot less error-prone than the suggested new API. Requiring a length of N+1 is not the most immediately-obvious API. Alice