Re: [PATCH RESEND v2 14/23] proc: let procfs copy in writes before pinning the entry

From
sashiko-bot@kernel.org
Date
2026-11-05 19:35:55
Also in
dri-devel, kexec, linux-ext4, linux-hwmon, linux-input, linux-m68k, linux-mm, linux-pci, linux-raid, linux-s390, linux-scsi, linux-serial, linux-sound, linux-usb, sparclinux
Reply to
Christian Brauner, 2026-11-04
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] proc: split __free(kvfree) declaration and initialization in pde_write_buf()
--

commit e52627c4b4d80d32822781f143a8c1245bd64a2c
Author: Christian Brauner [off-list ref]

proc: let procfs copy in writes before pinning the entry

This commit introduces a ->proc_write_buf() callback in struct proc_ops so
that procfs can copy write data from userspace into a NUL-terminated kernel
buffer before pinning the proc_dir_entry. This prevents userspace page
faults during write copies from blocking remove_proc_entry().
quoted hunk ↗ jump to hunk
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index d51ab7548b117..df1caa0f238df 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -417,11 +417,44 @@ static ssize_t pde_write(struct proc_dir_entry *pde, struct file *file, const ch
 	return -EIO;
 }
 
+/*
+ * procfs copies in what is written before it pins the entry. A writer that
+ * faults on its buffer then doesn't hold up remove_proc_entry().
+ */
+static ssize_t pde_write_buf(struct proc_dir_entry *pde, struct file *file,
+			     const char __user *ubuf, size_t count, loff_t *ppos)
+{
+	char *buf __free(kvfree) = NULL;
+	size_t size;
+	ssize_t rv;
+
+	size = pde->write_size;
+	if (count > size) {
+		if (!pde_has_short_writes(pde))
+			return -EINVAL;
+		count = size;
+	}
+	buf = kvmalloc(count + 1, GFP_KERNEL);
[Severity: Low]
As reported by Sashiko on RFC [1], this isn't a bug, but in pde_write_buf()
(called from proc_reg_write()), buf is declared with __free(kvfree) = NULL
at the top of the function and assigned later with kvmalloc() after the
count > size check.

Per the Cleanup API conventions in include/linux/cleanup.h, should buf be
defined and initialized in a single statement at the allocation site:

	char *buf __free(kvfree) = kvmalloc(count + 1, GFP_KERNEL);

after validating count?

[1] https://lore.kernel.org/r/sashiko-outbox-195538@kernel.org (local)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104-work-procfs-core-v2-0-76ace653a773@kernel.org?part=14
Thread (209 messages) 209 messages, 9 authors, last reply 23d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help