[Bug 240573] sysctl() does not return ENOMEM but silently truncate returned data

From: <bugzilla-noreply_at_freebsd.org>
Date: Sun, 16 Jan 2022 22:15:30 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=240573

Mark Johnston <markj@FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|New                         |Open

--- Comment #2 from Mark Johnston <markj@FreeBSD.org> ---
For kern_proc_vmmap_out(), we have:

                /* Halt filling and truncate rather than exceeding maxlen */
                if (maxlen != -1 && maxlen < kve->kve_structsize) {
                        error = 0;
                        vm_map_lock_read(map);
                        break;
                } else if (maxlen != -1)
                        maxlen -= kve->kve_structsize;

                if (sbuf_bcat(sb, kve, kve->kve_structsize) != 0)
                        error = ENOMEM;

Note that when filling out info for the KERN_PROC_VMMAP sysctl, we have maxlen
== -1.  So we just end up calling sbuf_bcat(), which will indeed return an
error if the output buffer is too small.  I think there is no bug there.

I think you are right about sysctl_posix_shm_list(), we should return an error
if req->oldptr is non-NULL and the buffer is truncated.  I believe it would be
sufficient to just remove the referenced check, sbuf_bcat() will signal an
error.

-- 
You are receiving this mail because:
You are the assignee for the bug.