Re: [PATCH RESEND v2 44/51] proc: sysctl: resume readdir after the last name it returned
From: Christian Brauner
Date: Thu Nov 05 2026 - 03:44:01 EST
On Thu, 5 Nov 2026 01:08:36 +0100, Jann Horn wrote:
> sysctl_cursor_set() is called here, when the output buffer is too
> small; but not if the proc_sys_readdir() loop ends because the end of
> the table was reached and "h" is NULL?
It's the other way around. res is true when the entry went into the
buffer. The cursor moves with every entry that was emitted. That
includes the last entry of the table.
When the buffer is full, res is false, we stop, and the cursor leads us
to the last entry that we sent.
> Doesn't that mean that another getdents() after reaching end of the
> file would observe the last entries again?
No. After the last entry, cursor->pos == ctx->pos. So the next getdents
does entry_after(last_name). That doens't find anything. So h is NULL,
the loop doesn't run and it returns zero.
If an entry registered behind the name it would show up.