opnsense-src/tests/sys
John Baldwin 8ce99bb405 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 without
holding the file descriptor lock.  This snapshot does not do a deep
copy of the ioctls capability array, but instead uses a different
return value to inform the caller to retry the copy with the lock
held.  However, filecaps_copy() was returning 1 to indicate that a
retry was required, and fget_cap() was checking for 0 (actually
'!filecaps_copy()').  As a result, fget_cap() did not do a deep copy
of the ioctls array and just reused the original pointer.  This cause
multiple file descriptor entries to think they owned the same pointer
and eventually resulted in duplicate frees.

The only code path that I'm aware of that triggers this is to create a
listen socket that has a restricted list of ioctls and then call
accept() which calls fget_cap() with a valid filecaps structure from
getsock_cap().

To fix, change the return value of filecaps_copy() to return true if
it succeeds in copying the caps and false if it fails because the lock
is required.  I find this more intuitive than fixing the caller in
this case.  While here, change the return type from 'int' to 'bool'.

Finally, make filecaps_copy() more robust in the failure case by not
copying any of the source filecaps structure over.  This avoids the
possibility of leaking a pointer into a structure if a similar future
caller 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:	kib
Discussed with:	mjg (not a fan of the extra branch)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D15047
2018-04-17 18:07:40 +00:00
..
acl [tests] change tests/sys/acl/run to run on perl 5.26 2018-04-11 07:15:30 +00:00
aio lio_listio: return EAGAIN instead of EIO when out of resources 2018-04-16 18:12:15 +00:00
capsicum Properly do a deep copy of the ioctls capability array for fget_cap(). 2018-04-17 18:07:40 +00:00
cddl ZFS test suite: fix uses of illumos /dev/[r]dsk/ and /dev/zvol/[r]dsk/ 2018-03-27 11:49:15 +00:00
fifo other: Fix several typos and minor errors 2017-12-27 03:23:58 +00:00
file DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
fs DIRDEPS_BUILD: Connect new directories. 2017-10-31 00:04:07 +00:00
geom gpart: append partition name to the underlying provider's physical path 2018-02-14 20:26:09 +00:00
kern Appease GCC 4.2 2018-03-21 04:44:19 +00:00
kqueue DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
mac DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
mqueue DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
net Add tests for lagg(4) and other cloned network interfaces 2018-02-23 18:18:42 +00:00
netinet DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
netipsec tests: ipsec: Don't load/unload aesni.ko in the test header 2017-12-03 18:35:07 +00:00
netpfil pf tests: Do not build or install if pf is not enabled 2018-04-10 12:45:34 +00:00
opencrypto Import Blake2 algorithms (blake2b, blake2s) from libb2 2018-03-21 16:18:14 +00:00
pjdfstest DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
posixshm DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
sys DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
vfs vfs_lookup: Allow PATH_MAX-1 symlinks 2017-11-17 19:25:39 +00:00
vm DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
Makefile Properly do a deep copy of the ioctls capability array for fget_cap(). 2018-04-17 18:07:40 +00:00
Makefile.depend DIRDEPS_BUILD: Connect MK_TESTS. 2016-03-09 22:46:01 +00:00
Makefile.inc Use MK_CHECK_USE_SANDBOX in tests/..., to deal with the fact that 2017-08-02 22:24:08 +00:00