Re: [PATCH] sysfs: clamp show() return value in sysfs_kf_read()

From: Tejun Heo

Date: Thu May 21 2026 - 12:36:51 EST


Hello,

On Thu, May 21, 2026 at 08:18:32AM +0200, Greg Kroah-Hartman wrote:
> On Wed, May 20, 2026 at 08:19:34AM -1000, Tejun Heo wrote:
> > Hello,
> >
> > Two nits:
> >
> > - Buffer is atomic_write_len ?: PAGE_SIZE, so probably better to clamp
> > to that than hardcode PAGE_SIZE.
>
> Where is that check at? And sysfs_kf_seq_show() doesn't check it this
> way, should that change?

In kernfs_fop_open(), if ops->prealloc, we allocate of->prealloc_buf to the
size of of->atomic_write_len ?: PAGE_SIZE. Maybe we should just update
of->atomic_write_len. I think the intention was to allow >PAGE_SIZE atomic
content. seq_file now does dynamic buffer resizing, so this may not be
necessary. There's no clean interface to preemptly set the minimum buffer
size right now but that probably is the better direction. Then, we can just
always go through seq_file.

Thanks.

--
tejun