Disable connectat/bindat with AT_FDCWD in capmodePreviously it was possible to connect a socket (which had theCAP_CONNECT right) by calling "connectat(AT_FDCWD, ...)" even incapabilties mode. Th
Disable connectat/bindat with AT_FDCWD in capmodePreviously it was possible to connect a socket (which had theCAP_CONNECT right) by calling "connectat(AT_FDCWD, ...)" even incapabilties mode. This combination should be treated the same as a callto connect (i.e. forbidden in capabilities mode). Similarly for bindat.Disable connectat/bindat with AT_FDCWD in capabilities mode, fix up thedocumentation and add tests.PR: 222632Submitted by: Jan Kokemüller <[email protected]>Reviewed by: Domagoj StolfaMFC after: 1 weekRelnotes: YesDifferential Revision: https://reviews.freebsd.org/D15221
show more ...
Properly do a deep copy of the ioctls capability array for fget_cap().fget_cap() tries to do a cheaper snapshot of a file descriptor withoutholding the file descriptor lock. This snapshot does no
Properly do a deep copy of the ioctls capability array for fget_cap().fget_cap() tries to do a cheaper snapshot of a file descriptor withoutholding the file descriptor lock. This snapshot does not do a deepcopy of the ioctls capability array, but instead uses a differentreturn value to inform the caller to retry the copy with the lockheld. However, filecaps_copy() was returning 1 to indicate that aretry was required, and fget_cap() was checking for 0 (actually'!filecaps_copy()'). As a result, fget_cap() did not do a deep copyof the ioctls array and just reused the original pointer. This causemultiple file descriptor entries to think they owned the same pointerand eventually resulted in duplicate frees.The only code path that I'm aware of that triggers this is to create alisten socket that has a restricted list of ioctls and then callaccept() which calls fget_cap() with a valid filecaps structure fromgetsock_cap().To fix, change the return value of filecaps_copy() to return true ifit succeeds in copying the caps and false if it fails because the lockis required. I find this more intuitive than fixing the caller inthis case. While here, change the return type from 'int' to 'bool'.Finally, make filecaps_copy() more robust in the failure case by notcopying any of the source filecaps structure over. This avoids thepossibility of leaking a pointer into a structure if a similar futurecaller doesn't properly handle the return value from filecaps_copy()at the expense of one more branch.I also added a test case that panics before this change and now passes.Reviewed by: kibDiscussed with: mjg (not a fan of the extra branch)MFC after: 1 weekDifferential Revision: https://reviews.freebsd.org/D15047