[PATCH RESEND v2 16/23] proc: let procfs copy out reads that don't go through seq_file
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Thu Nov 5 11:35:45 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] proc: define and initialize __free(kvfree) variable buf in pde_read_buf()
--
commit 19cf278eb9fee57b90ee19764f6b076d9cab553d
Author: Christian Brauner <brauner at kernel.org>
proc: let procfs copy out reads that don't go through seq_file
This commit adds ->proc_read_buf() and PROC_ENTRY_FULL_READS to proc_ops so
that non-seq_file procfs entries can fill a kernel buffer while pinned and
let procfs copy it to userspace after unpinning the entry.
> diff --git a/fs/proc/inode.c b/fs/proc/inode.c
> index df1caa0f238df..caa47933c233d 100644
> --- a/fs/proc/inode.c
> +++ b/fs/proc/inode.c
[ ... ]
> @@ -377,11 +379,67 @@ static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence)
> return rv;
> }
>
> +/*
> + * The entry fills a kernel buffer and procfs copies that to userspace after
> + * unpinning the entry. A reader that faults on its buffer then doesn't hold
> + * up remove_proc_entry().
> + */
> +static ssize_t pde_read_buf(struct proc_dir_entry *pde, struct kiocb *iocb,
> + struct iov_iter *iter)
> +{
> + struct file *file = iocb->ki_filp;
> + char *buf __free(kvfree) = NULL;
> + ssize_t rv, done = 0;
> + size_t len, count;
> + loff_t pos;
> +
> + if (!iov_iter_count(iter))
> + return 0;
> + /* neither the allocation nor the entry can honor IOCB_NOWAIT */
> + if ((iocb->ki_flags & IOCB_NOWAIT) && !(file->f_flags & O_NONBLOCK))
> + return -EAGAIN;
> + len = min_t(size_t, iov_iter_count(iter), pde->read_size);
> + buf = kvmalloc(len, GFP_KERNEL);
[Severity: Low]
As reported by Sashiko on RFC [1], this isn't a bug, but in pde_read_buf()
in fs/proc/inode.c, buf is declared with __free(kvfree) = NULL at the top
of the function before the early returns and then assigned later at the
kvmalloc() call. Could buf be defined and initialized in a single statement
at the allocation site:
char *buf __free(kvfree) = kvmalloc(len, GFP_KERNEL);
to follow the cleanup.h conventions?
[1] https://lore.kernel.org/r/sashiko-outbox-195540@kernel.org
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261104-work-procfs-core-v2-0-76ace653a773@kernel.org?part=16
More information about the kexec
mailing list