From nobody Sun Feb 8 04:31:00 2026 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39D9030C61B for ; Mon, 12 Jan 2026 07:31:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203113; cv=none; b=OFLXi4qDihKFwHMJNi4bUHkELKssoT+VWq7cyPd/JkMYMkzHiXuM/gBmiPe2EMje+NgGQf40LDIPjaAxgiHuXDH5Ww1/aIqFoPNAFzCCxu/2g2afc/QPImZ83a6DLeyYzkt3iU8yMTK5UpTjQtazYrSmAF097CPpPyvQnrWaoSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203113; c=relaxed/simple; bh=0w8glGv5zehTU8mYqRipHl0MsH4jVNl2Z7VDxD4FQoc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EP70GTOxs9GjyaAxquHKh4+kUODp7Jti5+H4DzWbDRxsgXmDQ2wAY57XUBvDXMT6NZ1GugjD7pdqCaa23qjsyfyMUFErcd9XhwyRta//aeelVxQSTck5j5DrverOwO6Hoq0ZxML/A4xIAO5EEFbdBpHZ3Zk+CL4IW4RGFFPfdwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=phie3JAT; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="phie3JAT" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768203109; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RVzCy4in+NcnK6/nhRnifh8d5UAeV3WaYJGZ0fRZrUk=; b=phie3JATXRtHR8qqfJ1kMcrZDQ5Rbzu7BArH8wdeNaW8ggrVtzX9ioBSiFPL8Q9ojxBo5n CyPvTA1tMXk5zHbrObIyWAG8nTFNN88TOv88pBLXRyfj3rsjm3cNT4z7JDBHah3I1ESa42 w4YBmXmv/doUmbkeZzFzvvmwhtqC6R0= From: Fushuai Wang To: tglx@kernel.org, peterz@infradead.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, aliceryhl@google.com, yury.norov@gmail.com, vmalik@redhat.com, kees@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rostedt@goodmis.org, mhiramat@kernel.org, brauner@kernel.org, jack@suse.cz, cyphar@cyphar.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-trace-kernel@vger.kernel.org, wangfushuai@baidu.com Subject: [PATCH v2 1/6] uaccess: Add copy_from_user_nul helper Date: Mon, 12 Jan 2026 15:30:34 +0800 Message-Id: <20260112073039.1185-2-fushuai.wang@linux.dev> In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev> References: <20260112073039.1185-1-fushuai.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Fushuai Wang Many places call copy_from_user() to copy a buffer from user space, and then manually add a NULL terminator to the destination buffer, e.g.: if (copy_from_user(dest, src, len)) return -EFAULT; dest[len] =3D '\0'; This is repetitive and error-prone. Add a copy_from_user_nul() helper to simplify such patterns. It copied n bytes from user space to kernel space, and NUL-terminates the destination buffer. Signed-off-by: Fushuai Wang --- include/linux/uaccess.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 1f3804245c06..fe9a1db600c7 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -224,6 +224,25 @@ copy_from_user(void *to, const void __user *from, unsi= gned long n) #endif } =20 +/* + * copy_from_user_nul - Copy a block of data from user space and NUL-termi= nate + * + * @to: Destination address, in kernel space. This buffer must be at lea= st + * @n+1 bytes long! + * @from: Source address, in user space. + * @n: Number of bytes to copy. + * + * Return: 0 on success, -EFAULT on failure. + */ +static __always_inline int __must_check +copy_from_user_nul(void *to, const void __user *from, unsigned long n) +{ + if (copy_from_user(to, from, n)) + return -EFAULT; + ((char *)to)[n] =3D '\0'; + return 0; +} + static __always_inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n) { --=20 2.36.1 From nobody Sun Feb 8 04:31:00 2026 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 837B8330B0E for ; Mon, 12 Jan 2026 07:31:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203121; cv=none; b=Q/0i0bwJEISuWnnb4vdFbBNrempRkidtAu+6EtOecQfHDra7tq/iuT11RKX0EjJB6ikPhGw0CSNUUkEeBsBDhucJuLca8oEx1q5iL9FgfbrF3M9vXgwndbyHY9FmGSudAzpJVUHPwJkRxkgvrB876MHpmUL2Z6VvgfEshz9o33E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203121; c=relaxed/simple; bh=dalNA0BxdWJLQHtJZnm34WkI5gbCzurqkKSSozGr3Z8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UhZVopxYykHoXLSm3NSjiBvR8gANLcQEbLto8ixK2TcfNu58+dtaxu/mkvfdsi67oBjBRj60YygaJW/RwIRy5HuNtYO5MyyVskQSkncda01UEygszBxDjZWTfZYo+IaLhXusbvgW/nrX6S2vTugJ+BcmxhL7WrXdlKwTsqgDtAU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jE7S1QL7; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jE7S1QL7" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768203114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RW/CePLfpA2cGIbxlZCaBzT9qs/BsPWVBCiDlhNUjWo=; b=jE7S1QL7faF8pM+PQ3qz7/gONZwLuf22VH7YNNseR6jXXdqtKxNBogGlV4nqM3wPpeSAPD eQwJGXWmgaXqtAgLzd06r41dY4j74XFyLyzr0lj6KlKa9d/+tQ6YWI2mKCpf2ihDi4SRQp tz6xHlGi1cjtwYfx4OvbNHsV7sXfWDQ= From: Fushuai Wang To: tglx@kernel.org, peterz@infradead.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, aliceryhl@google.com, yury.norov@gmail.com, vmalik@redhat.com, kees@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rostedt@goodmis.org, mhiramat@kernel.org, brauner@kernel.org, jack@suse.cz, cyphar@cyphar.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-trace-kernel@vger.kernel.org, wangfushuai@baidu.com Subject: [PATCH v2 2/6] x86/tlb: Use copy_from_user_nul() instead of copy_from_user() Date: Mon, 12 Jan 2026 15:30:35 +0800 Message-Id: <20260112073039.1185-3-fushuai.wang@linux.dev> In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev> References: <20260112073039.1185-1-fushuai.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Fushuai Wang Use copy_from_user_nul() instead of copy_from_user() to simplify the code. No functional change. Signed-off-by: Fushuai Wang --- arch/x86/mm/tlb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index f5b93e01e347..ae81e5cb510e 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -1807,10 +1807,9 @@ static ssize_t tlbflush_write_file(struct file *file, int ceiling; =20 len =3D min(count, sizeof(buf) - 1); - if (copy_from_user(buf, user_buf, len)) + if (copy_from_user_nul(buf, user_buf, len)) return -EFAULT; =20 - buf[len] =3D '\0'; if (kstrtoint(buf, 0, &ceiling)) return -EINVAL; =20 --=20 2.36.1 From nobody Sun Feb 8 04:31:00 2026 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4F18330678 for ; Mon, 12 Jan 2026 07:32:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203125; cv=none; b=WODnfJFI+zk6V5IQ5VhcJATS7Dvkz6hoNBvXeJp+8h8RVlHKKY/zzageLMDHD8EH6iP121qhLDUcM8K9p04vuxG0n3CykVAsijludErzVLKzRS6j3Y4OUapnMD1JWe5DMtMoGZkH8M6CHpjlYLdH/LYu94j8qWHywW7mivKoJkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203125; c=relaxed/simple; bh=eHRTYFWu9aM7ya+jZzDKgChWnn9WNk9AfvsQ4P4sh00=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qjagQhcnIRnv11S7y1fL6S7buGYmZIZoB/g6FDMbdxD1PPFza+ia9msjLoIEMnqJ7rNN/H7WgEekdYwqvrJCu3vOpxZD59lnHV262/NZiL/vIUNbJI1PSLLDEO3vUqRaY4d087Xhiycb94Y9+hVO/BGwezYyMjZsnkCknixzZQE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=u50Wkj6l; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="u50Wkj6l" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768203121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dmoiTseSNktfLj4CfwRlR/i2JM/XKf2Hh9f07dEccSc=; b=u50Wkj6lO5c1Lvizbeft3JcTB6QajgqhaTsRTW6t+3Xe5wyfj1zQ2LdgwjXdoYmP7fd5kf 0cPRfbHuEP+l5Cc+ttVmqCmWOkp4+x+oS/GadCVbfxvzlEZUHXKk9EXJlCE96cTlqPTTId meqRDVkC+tlgZby4pgZXur9o36hyepc= From: Fushuai Wang To: tglx@kernel.org, peterz@infradead.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, aliceryhl@google.com, yury.norov@gmail.com, vmalik@redhat.com, kees@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rostedt@goodmis.org, mhiramat@kernel.org, brauner@kernel.org, jack@suse.cz, cyphar@cyphar.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-trace-kernel@vger.kernel.org, wangfushuai@baidu.com Subject: [PATCH v2 3/6] tracing: Use copy_from_user_nul() instead of copy_from_user() Date: Mon, 12 Jan 2026 15:30:36 +0800 Message-Id: <20260112073039.1185-4-fushuai.wang@linux.dev> In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev> References: <20260112073039.1185-1-fushuai.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Fushuai Wang Use copy_from_user_nul() instead of copy_from_user() to simplify the code. No functional change. Signed-off-by: Fushuai Wang Acked-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index baec63134ab6..b6ffd006fcf9 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -11266,10 +11266,9 @@ ssize_t trace_parse_run_command(struct file *file,= const char __user *buffer, if (size >=3D WRITE_BUFSIZE) size =3D WRITE_BUFSIZE - 1; =20 - if (copy_from_user(kbuf, buffer + done, size)) + if (copy_from_user_nul(kbuf, buffer + done, size)) return -EFAULT; =20 - kbuf[size] =3D '\0'; buf =3D kbuf; do { tmp =3D strchr(buf, '\n'); --=20 2.36.1 From nobody Sun Feb 8 04:31:00 2026 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A002331A5D for ; Mon, 12 Jan 2026 07:32:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203135; cv=none; b=Gk3gn1mndGfC33sgLAdWz4ufdlvtj2JccxMeEPRxKQaH/c5PO5Svlju8M6gCB3bca5tBqf/rcKfxihmpqdBxfQu5JIm7Ir+CE7csJ3p3Vq+U70VR33KtxmgFuBYrpcGXXI4q71ySnolB4s+VE9hAmNHBLN6/FYtNgQiQvZ5WULA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203135; c=relaxed/simple; bh=OnqAbUWVy7D0WXGNVBkrLwkuw9vg94fN5udfoCsYN8g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XV0p3USB/VH/Vwj15yzMN2DmtMWk/ymtnS+VErnVo3s3mMzJHGoed69G1MTYToMlNCWJ15rqDplYtnERVxx2qKxRfQUZXcZWdgULqhr09vzoqih8l9RbDrRX6vLrSdbnHhsCJF4eO0LjDuhyh0l72FGo0qaWmNnJ2sVTG/eDkic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=QQzgX29E; arc=none smtp.client-ip=91.218.175.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QQzgX29E" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768203126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AwRqj4wTYeIgUDX0xZiGWFeCRQeFcAPC39VTqib2tBs=; b=QQzgX29EQmy4am2md5KjS0HuRT47z1dVNL4CH+BM0JYJb/YmzU4y/+lWkgxufMtBChEJ9G VcJND5bpCED/8yd1po0iwV4o93eczOgcIUlhgDMVZOGrhCqSQwJn8BqLoguJloK/x6VmCU bWhz9AVqeugOgV5pVfu2xggICKU01BI= From: Fushuai Wang To: tglx@kernel.org, peterz@infradead.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, aliceryhl@google.com, yury.norov@gmail.com, vmalik@redhat.com, kees@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rostedt@goodmis.org, mhiramat@kernel.org, brauner@kernel.org, jack@suse.cz, cyphar@cyphar.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-trace-kernel@vger.kernel.org, wangfushuai@baidu.com Subject: [PATCH v2 4/6] userns: Use copy_from_user_nul() instead of copy_from_user() Date: Mon, 12 Jan 2026 15:30:37 +0800 Message-Id: <20260112073039.1185-5-fushuai.wang@linux.dev> In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev> References: <20260112073039.1185-1-fushuai.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Fushuai Wang Use copy_from_user_nul() instead of copy_from_user() to simplify the code. No functional change. Signed-off-by: Fushuai Wang --- kernel/user_namespace.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 03cb63883d04..881a05a3502c 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -1239,9 +1239,8 @@ ssize_t proc_setgroups_write(struct file *file, const= char __user *buf, =20 /* What was written? */ ret =3D -EFAULT; - if (copy_from_user(kbuf, buf, count)) + if (copy_from_user_nul(kbuf, buf, count)) goto out; - kbuf[count] =3D '\0'; pos =3D kbuf; =20 /* What is being requested? */ --=20 2.36.1 From nobody Sun Feb 8 04:31:00 2026 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68889332901 for ; Mon, 12 Jan 2026 07:32:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203137; cv=none; b=HJ7x550m3sZt6uxmSKDLYzNAU6nrSyGLVbK51YBqcF75cxGsLgBpXNZhHm9mnauyYCoSLiXMf6g55eGtGCN0iyKgUCIoeG4USQlr43+pRMzbY2N7XH9w+VL8a+3l3/g6BImz+BqrmqZRlEz27m+ShdgsZhThYRL10ztrrFsCHiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203137; c=relaxed/simple; bh=/Pe3//9w7IjRlZ5PxKu63g76brGyRa5s21C2q9PEXSY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fau91L7yPHq334MfM1p0D6SQbg9HIDfMFXW2ct2sVvxJ9x2/Eo2rTS9G9rAVhOJVSBPhw2LwlnNAerkv6uInXQ7j1DYZ7qe/uBtBkOxzoI691fKSkzGFV7m5n0GDWAwYGhRfE19nJzs6zdutY3OUntcgVrMLBaakjgU4OcXLlOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=NkQ4kSRY; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="NkQ4kSRY" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768203131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dey/oVwL655ps/UccfLJszueXjmKm4iUYtixNmkF++Q=; b=NkQ4kSRYHQKog9dolagfPy1l0wY9hoVzmEFzdXdqH4dPhXxiyjiZiuHb5gP5imP5m1h/6k N49ll2G027dYaf1RuzrZDTzgdaiJkDyMdPxGz/D7J56gEF5JvM5WeYE7hOM6PE43uGmMv9 DTzCtcwOQfKAOFrNlm2dc1KTu2B+chw= From: Fushuai Wang To: tglx@kernel.org, peterz@infradead.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, aliceryhl@google.com, yury.norov@gmail.com, vmalik@redhat.com, kees@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rostedt@goodmis.org, mhiramat@kernel.org, brauner@kernel.org, jack@suse.cz, cyphar@cyphar.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-trace-kernel@vger.kernel.org, wangfushuai@baidu.com Subject: [PATCH v2 5/6] time: Use copy_from_user_nul() instead of copy_from_user() Date: Mon, 12 Jan 2026 15:30:38 +0800 Message-Id: <20260112073039.1185-6-fushuai.wang@linux.dev> In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev> References: <20260112073039.1185-1-fushuai.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Fushuai Wang Use copy_from_user_nul() instead of copy_from_user() to simplify the code. No functional change. Signed-off-by: Fushuai Wang --- kernel/time/test_udelay.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/time/test_udelay.c b/kernel/time/test_udelay.c index 783f2297111b..08ff8fd43471 100644 --- a/kernel/time/test_udelay.c +++ b/kernel/time/test_udelay.c @@ -107,9 +107,8 @@ static ssize_t udelay_test_write(struct file *file, con= st char __user *buf, if (count >=3D sizeof(lbuf)) return -EINVAL; =20 - if (copy_from_user(lbuf, buf, count)) + if (copy_from_user_nul(lbuf, buf, count)) return -EFAULT; - lbuf[count] =3D '\0'; =20 ret =3D sscanf(lbuf, "%d %d", &usecs, &iters); if (ret < 1) --=20 2.36.1 From nobody Sun Feb 8 04:31:00 2026 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56CCE335086; Mon, 12 Jan 2026 07:32:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203146; cv=none; b=nIOSt0ijXHk7t7ogcX3fm1r8dMzMPtJ5FrIiAKy9OC4YQvmVMdvmIZlq+s/LGearsWGEMQ5Wf3FKl1myMy3qkNKyRFTqBxpK766WGIyRjBZpfU4o0T9vIX1LYjGEwQfeHPVJPXjHlkJpAYOI57o+90jxLhyL/J1XeRpaFjVO/CU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203146; c=relaxed/simple; bh=G2quA3UBKlwpYY71RTQx6NE5SE7yumQOCJBy7zLmjpU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xj18kZgCmgr8YU2s7tKFyNHN3jnNPGvs+e9syuj0qqX+Lsk5YifQH/qMhP3ju5rmVSflmMLKlaraiKdJBVFaC48gZ6srj0r5xbvWo3WF7p36B51qaw3k6knOVjCZhj2+Y/9BeUn0sJND996kWXBALVmNcp0UE1hvsehRySKVSUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=KNGH0pA7; arc=none smtp.client-ip=91.218.175.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="KNGH0pA7" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768203136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3IpOD+fYnrmJo+nD4L+qv9mFJmsh9VjP1W57JkVYRpI=; b=KNGH0pA7/xGz3mSnPL31Ffup/QPkvTuWKM4JcoLs2fFdZCWfR/+5YxMD9feCUV1OkJZEtP SWwpG3pJUoluYQYgfdU/WeT4arVkg+mWfvtLO7ii7+4KQRjJFu0B08kNmGF0HuT+X2im18 77bOETKhd+BI/LKrEacbyrb+p307ojY= From: Fushuai Wang To: tglx@kernel.org, peterz@infradead.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, aliceryhl@google.com, yury.norov@gmail.com, vmalik@redhat.com, kees@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rostedt@goodmis.org, mhiramat@kernel.org, brauner@kernel.org, jack@suse.cz, cyphar@cyphar.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-trace-kernel@vger.kernel.org, wangfushuai@baidu.com Subject: [PATCH v2 6/6] kstrtox: Use copy_from_user_nul() instead of copy_from_user() Date: Mon, 12 Jan 2026 15:30:39 +0800 Message-Id: <20260112073039.1185-7-fushuai.wang@linux.dev> In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev> References: <20260112073039.1185-1-fushuai.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Fushuai Wang Use copy_from_user_nul() instead of copy_from_user() to simplify the code. No functional change. Signed-off-by: Fushuai Wang --- lib/kstrtox.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/kstrtox.c b/lib/kstrtox.c index bdde40cd69d7..e4ee72b75e09 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c @@ -402,9 +402,8 @@ int kstrtobool_from_user(const char __user *s, size_t c= ount, bool *res) char buf[4]; =20 count =3D min(count, sizeof(buf) - 1); - if (copy_from_user(buf, s, count)) + if (copy_from_user_nul(buf, s, count)) return -EFAULT; - buf[count] =3D '\0'; return kstrtobool(buf, res); } EXPORT_SYMBOL(kstrtobool_from_user); @@ -416,9 +415,8 @@ int f(const char __user *s, size_t count, unsigned int = base, type *res) \ char buf[1 + sizeof(type) * 8 + 1 + 1]; \ \ count =3D min(count, sizeof(buf) - 1); \ - if (copy_from_user(buf, s, count)) \ + if (copy_from_user_nul(buf, s, count)) \ return -EFAULT; \ - buf[count] =3D '\0'; \ return g(buf, base, res); \ } \ EXPORT_SYMBOL(f) --=20 2.36.1