From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793633679; b=03hmakEJ1Nc07s1AzyyFfjSdckXJOYVHszGvXPlpd2aL0wgRb1zvRfF+5kdlBO2SNIyZ +hi3WLE3xwc/npcpGwnlEM3OS+9ddynE4Q8uzP9fdS2TlFcvYoJ8hoH6q57glG4ch6k9j 9CvzrWLILTV9l2JtLUUBPb8S/WkDpdU9tEmdrux7K/A4lQ0mFsg+bQuTHJNNdtCqh29qI ysdntxwck9WCIyqIQxNCKLdCvJOa+GLVB3aRfKMQpgVkeFOSqXeP6ozbjzZiN0B4OEbva U6uhF48ELO9TaDL3GNQZJN2b68r3VcVkU08asMZ3EWmkNAj+B2qE8ZFVrSNwbIlKP0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793633679; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=pmnFGMOE2v1+F0PJGOHw4Gdli7q7gPuktrXwX9LNfoQ=; b=Ntl6lvG3+Fdabvv3E56DNikwuBnyR0rxzryI2AG96JczJEq1pjvStmchKRdrxjEUJEwf iatIv72eNkT2UMjb+nYkeO/afhMtpWS9+qd5JyUZCDI/1frTOvmeoofdsHKldkeCxZs+N WI5sO0LJXvmi3cuDfb7drMCl+ou2hge55YSlfS/3/Kra3C0g1OIXZonbskoNAibfM+pwa iUpw/Ae43L3eywo9tdKiPNdW9QU97CUMOVPQxveA/rWieS+oUaZ1ejBylgdZj3l/vSsUF 7P8UqgU0JPLjhltSmJTVgEvvLzH/SPkfxh6lxu0MsdX16LoxWM+YgzeVhFcw2dqcmUQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=d9QGwQro; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4FDF608B060; Mon, 2 Nov 2026 15:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=d9QGwQro Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCFFB1F00A17; Mon, 2 Nov 2026 15:34:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793633678; bh=pmnFGMOE2v1+F0PJGOHw4Gdli7q7gPuktrXwX9LNfoQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=d9QGwQrotLscF4xo8DU9S109UjfAgcN4a46hjwVSf3SjqQgEaO4Rv1AEyP5dT4O5y xhGnDHnb/jFSk8D7qKuO+39L5VOpMdQp+GEPoALOWTv2sAj3bbh7bn9Ca6T4Zctpcj fNImnpjl37D5rGo6ytZAGYcvcU7Hs6e2nTEg5V2aQ/mC4G0yjxmcpG1Hu5e0aBYP77 YqqQjJjSh1N4cnNNEz/pCqHHyFFMtbDFf9uvFYMyEZgjLi1JBmongPZBS4PXj3B4fR cGUqecnhkpX6QHjYWkx5oNKUT3XrFn+eoX8EGZYKiM0ZGpeR++e3aBl28Ylp4YaymR Z4/Or8kbU/uIg== From: Christian Brauner Date: Mon, 02 Nov 2026 16:07:24 +0100 Subject: [PATCH RFC 10/11] samples/kfifo: let procfs copy in writes X-Mailing-List: linux-modules@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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261102-work-procfs-net-v1-10-982104a4f592@kernel.org> References: <20261102-work-procfs-net-v1-0-982104a4f592@kernel.org> In-Reply-To: <20261102-work-procfs-net-v1-0-982104a4f592@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Jann Horn , Josef Bacik , Chris Mason , Jeff Layton , NeilBrown , Eric Dumazet , Thomas Gleixner , Al Viro , Jonathan Corbet , Christoph Hellwig , Greg Kroah-Hartman , Joel Granados , Kees Cook , Jan Kara , Jan Kara , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-um@lists.infradead.org, linux-wireless@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org, ntfs3@lists.linux.dev, platform-driver-x86@vger.kernel.org, coreteam@netfilter.org, kexec@lists.infradead.org, linux-pci@vger.kernel.org, linux-sound@vger.kernel.org, netfilter-devel@vger.kernel.org, dri-devel@lists.freedesktop.org, ibm-acpi-devel@lists.sourceforge.net, jfs-discussion@lists.sourceforge.net, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-cifs@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-mm@kvack.org, linux-sh@vger.kernel.org, linux-usb@vger.kernel.org, samba-technical@lists.samba.org, sparclinux@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-doc@vger.kernel.org, linux-serial@vger.kernel.org, linux-atm-general@lists.sourceforge.net, Takashi Iwai , linux-input@vger.kernel.org, linux-raid@vger.kernel.org, linux-ext4@vger.kernel.org, linux-modules@vger.kernel.org, linux-debuggers@vger.kernel.org, "Christian Brauner (Amutable)" , Chuck Lever X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3950; i=brauner@kernel.org; h=from:subject:message-id; bh=wqPh89nrehb8eXTwTved41pSSj+cx0NGgazKeJSdQJg=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWS9WG5SKeDGcNhJw++9Z7LY3JTfuwQ+VK2efenXodN77 51lStK62FHKwiDGxSArpsji0G4SLrecp2KzUaYGzBxWJpAhDFycAjCRuBCG/z6xtYb3b823yGzs EFIryW+ZU83Lc9Vb497sqedPcyic+MvwP/CknED65Xe3rd5zTJCoDZgg+Puey5sJtRciovqzWZV mcQMA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and put that copy into the fifo with kfifo_in() instead of kfifo_from_user(). Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now. kfifo_from_user() cut a record to 255 bytes, what the one byte that holds its length can say, so the record sample keeps doing that with PROC_ENTRY_SHORT_WRITES. Signed-off-by: Christian Brauner (Amutable) --- samples/kfifo/bytestream-example.c | 9 +++------ samples/kfifo/inttype-example.c | 10 ++++------ samples/kfifo/record-example.c | 12 ++++++------ 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c index 4ae29a12cc8a..8c58fb46a2bf 100644 --- a/samples/kfifo/bytestream-example.c +++ b/samples/kfifo/bytestream-example.c @@ -110,20 +110,17 @@ static int __init testfunc(void) return 0; } -static ssize_t fifo_write(struct file *file, const char __user *buf, +static ssize_t fifo_write(struct file *file, char *buf, size_t count, loff_t *ppos) { - int ret; unsigned int copied; if (mutex_lock_interruptible(&write_access)) return -ERESTARTSYS; - ret = kfifo_from_user(&test, buf, count, &copied); + copied = kfifo_in(&test, buf, count); mutex_unlock(&write_access); - if (ret) - return ret; return copied; } @@ -148,7 +145,7 @@ static ssize_t fifo_read(struct file *file, char __user *buf, static const struct proc_ops fifo_proc_ops = { .proc_read = fifo_read, - .proc_write = fifo_write, + .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, }; diff --git a/samples/kfifo/inttype-example.c b/samples/kfifo/inttype-example.c index e4f93317c5d0..c5d16b815e73 100644 --- a/samples/kfifo/inttype-example.c +++ b/samples/kfifo/inttype-example.c @@ -103,20 +103,18 @@ static int __init testfunc(void) return 0; } -static ssize_t fifo_write(struct file *file, const char __user *buf, +static ssize_t fifo_write(struct file *file, char *buf, size_t count, loff_t *ppos) { - int ret; unsigned int copied; if (mutex_lock_interruptible(&write_access)) return -ERESTARTSYS; - ret = kfifo_from_user(&test, buf, count, &copied); + copied = kfifo_in(&test, (const int *)buf, count / sizeof(int)) * + sizeof(int); mutex_unlock(&write_access); - if (ret) - return ret; return copied; } @@ -141,7 +139,7 @@ static ssize_t fifo_read(struct file *file, char __user *buf, static const struct proc_ops fifo_proc_ops = { .proc_read = fifo_read, - .proc_write = fifo_write, + .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, }; diff --git a/samples/kfifo/record-example.c b/samples/kfifo/record-example.c index e4d1a2d7983c..dcc749247c64 100644 --- a/samples/kfifo/record-example.c +++ b/samples/kfifo/record-example.c @@ -117,20 +117,17 @@ static int __init testfunc(void) return 0; } -static ssize_t fifo_write(struct file *file, const char __user *buf, +static ssize_t fifo_write(struct file *file, char *buf, size_t count, loff_t *ppos) { - int ret; unsigned int copied; if (mutex_lock_interruptible(&write_access)) return -ERESTARTSYS; - ret = kfifo_from_user(&test, buf, count, &copied); + copied = kfifo_in(&test, buf, count); mutex_unlock(&write_access); - if (ret) - return ret; return copied; } @@ -155,8 +152,11 @@ static ssize_t fifo_read(struct file *file, char __user *buf, static const struct proc_ops fifo_proc_ops = { .proc_read = fifo_read, - .proc_write = fifo_write, + .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, + /* kfifo_from_user() cut a record to what its length byte holds */ + .proc_flags = PROC_ENTRY_SHORT_WRITES, + .proc_write_size = U8_MAX, }; static int __init example_init(void) -- 2.53.0