Created attachment 193626 [details] patch fixing the issue `man 3 sysctl` states: "If the amount of data available is greater than the size of the buffer supplied, the call supplies as much data as fits in the buffer provided and returns with the error code ENOMEM." This is not true in the case of `KERN_PROC_CWD`, in which case `sysctl` returns 0, indicating success.
I think this change is right. Note that export_kinfo_to_sb() is used in other contexts, but in most of them the return value isn't checked anyway.
I also meant to point out that we don't seem to have any applications relying on the current behaviour, which seems to have been introduced relatively recently: r249487.
This is my first patch to FreeBSD so forgive my ignorance -- what are the next steps? Can you land the change for me Mark? Or do I need to find someone else to review it, and if so who?
(In reply to Brennan Vincent from comment #3) I'll take care of getting it reviewed and committed.
https://reviews.freebsd.org/D15607
Ping: Mark, is there any good reason your fix in D15607 never landed?
(In reply to Brennan Vincent from comment #6) I thought I had found some problem with the patch, but didn't have time to revisit it and it slipped from my todo list. I'll revisit it shortly, apologies for the delay.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=36bd49ac4db8c62a3b354094646cbd8547ad2c51 commit 36bd49ac4db8c62a3b354094646cbd8547ad2c51 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2021-12-16 21:07:04 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2021-12-17 18:10:23 +0000 fd: Avoid truncating output buffers for KERN_PROC_{CWD,FILEDESC} These sysctls failed to return an error if the caller had provided too short an output buffer. Change them to return ENOMEM instead, to ensure that callers can detect truncation in the face of a concurrently changing fd table. PR: 228432 Discussed with: cem, jhb MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D15607 sys/kern/kern_descrip.c | 54 ++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 25 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=af30714ff433bad84b9d5e72740991fee7cb1414 commit af30714ff433bad84b9d5e72740991fee7cb1414 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2021-12-16 21:07:04 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2022-01-16 15:40:25 +0000 fd: Avoid truncating output buffers for KERN_PROC_{CWD,FILEDESC} These sysctls failed to return an error if the caller had provided too short an output buffer. Change them to return ENOMEM instead, to ensure that callers can detect truncation in the face of a concurrently changing fd table. PR: 228432 Discussed with: cem, jhb (cherry picked from commit 36bd49ac4db8c62a3b354094646cbd8547ad2c51) sys/kern/kern_descrip.c | 54 ++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 25 deletions(-)