freebsd-dev/etc
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
..
autofs etc: clean up trailing whitespace in autofs 2018-02-15 11:41:38 +00:00
bluetooth
cron.d Conditionally handle the crontab entry for atrun(8) 2017-05-18 06:33:55 +00:00
defaults Turn devmatch on by default. 2018-02-12 06:51:20 +00:00
devd Invoke devmatch rc.d script directly instead of depending on "service" 2018-02-17 13:13:55 +00:00
etc.aarch64 Update the arm64 ttys file to enable the correct uart based on which device 2015-10-01 09:36:18 +00:00
etc.amd64 Enable all callin ttys if the tty is an available console. 2015-10-20 16:10:46 +00:00
etc.arm Enable ttyu1, ttyu2, ttyu3 for arm installations. 2015-06-21 19:50:02 +00:00
etc.i386 Enable all callin ttys if the tty is an available console. 2015-10-20 16:10:46 +00:00
etc.mips Enable all callin ttys if the tty is an available console. 2015-10-20 16:10:46 +00:00
etc.powerpc Enable all callin ttys if the tty is an available console. 2015-10-20 16:10:46 +00:00
etc.riscv Start support for the RISC-V 64-bit architecture developed by UC Berkeley. 2015-12-11 22:55:23 +00:00
etc.sparc64 Enable all callin ttys if the tty is an available console. 2015-10-20 16:10:46 +00:00
gss
mail Replace send-mail with the more standarized sendmail, we do not create 2017-12-27 06:23:50 +00:00
mtree Properly do a deep copy of the ioctls capability array for fget_cap(). 2018-04-17 18:07:40 +00:00
newsyslog.conf.d Handle the logfiles in newsyslog and syslogd conditionally, based on 2017-05-13 03:10:50 +00:00
ntp Replace the leap-seconds file in r320242 from USNO - 2017-06-23 01:05:49 +00:00
pam.d various: general adoption of SPDX licensing ID tags. 2017-11-27 15:37:16 +00:00
periodic filter all passwords (not only changed) from periodic passwd backup 2017-11-21 20:31:54 +00:00
pkg
rc.d pf: reload and resync do the same thing 2018-03-26 09:36:22 +00:00
root Fix typo introduced in r320672 - check for existence of the right file. 2017-07-05 15:42:33 +00:00
sendmail Move /etc/ to SRCTOP 2017-03-12 18:58:55 +00:00
syslog.d Handle the logfiles in newsyslog and syslogd conditionally, based on 2017-05-13 03:10:50 +00:00
amd.map
apmd.conf
auto_master Stop appending "noatime" in the autofs -media map, and instead add it 2016-09-20 04:52:01 +00:00
blacklistd.conf Add basic blacklist build support 2016-06-02 19:06:04 +00:00
crontab Conditionally handle the crontab entry for atrun(8) 2017-05-18 06:33:55 +00:00
csh.cshrc
csh.login
csh.logout
ddb.conf
devd.conf Add example devd.conf(5) entry for notifying init(8) about new USB ttys. 2018-03-06 21:05:34 +00:00
devfs.conf
dhclient.conf
disktab
fbtab
freebsd-update.conf
ftpusers
gettytab
group Fix regression introduced on r293801. 2016-01-27 06:28:56 +00:00
hosts
hosts.allow Allow info to display correctly in for varying tabstop settings 2014-12-24 01:50:44 +00:00
hosts.equiv
hosts.lpd
inetd.conf Remove rcmds. 2017-10-06 08:43:14 +00:00
libalias.conf Fix a regression: let natd load libalias modules before /usr is mounted 2006-10-08 14:02:00 +00:00
libmap.conf
login.access
login.conf Fix handling of umtxp resource limit in sh(1)/ulimit(1), limits(1), add 2016-03-12 14:54:34 +00:00
mac.conf Spelling fixes for etc/ 2012-01-07 16:10:32 +00:00
Makefile Add /boot/overlays to runtime pkg, fix distrib-dirs METALOG generation 2018-01-23 17:59:06 +00:00
Makefile.depend META MODE: Update dependencies with 'the-lot' and add missing directories. 2015-12-01 05:23:19 +00:00
master.passwd Capitalize "LDAP" in the description field of the _ypldap entry. 2016-05-10 12:47:36 +00:00
minfree
motd Add the less-ambiguous freebsd-version command. 2014-11-02 19:25:31 +00:00
netconfig
netstart Remove NATM configuration bits and assorted NATM and ATM remnants. 2017-04-25 21:59:34 +00:00
network.subr Reduce code duplication for wlan(4) interface creation in network.subr. 2017-11-19 20:18:21 +00:00
networks
newsyslog.conf Handle the logfiles in newsyslog and syslogd conditionally, based on 2017-05-13 03:10:50 +00:00
nls.alias
nscd.conf
nsmb.conf Remove IPX support. 2014-03-14 02:58:48 +00:00
nsswitch.conf Implement an NSS backend for netgroups and add getnetgrent_r(3). 2016-06-09 01:28:44 +00:00
ntp.conf Update ntp.conf to use the ntpd pool feature. 2017-01-02 15:19:22 +00:00
opieaccess Back out previous commit now that pam_opieaccess(8) has an allow_local 2003-02-16 13:04:27 +00:00
pccard_ether Do not try to recreate wlan(4) interface if it already exists. 2016-12-04 15:58:34 +00:00
pf.os pf.os: Add OpenBSD:6.1 2017-12-02 06:23:02 +00:00
phones
portsnap.conf userland: Fix several typos and minor errors 2017-12-27 03:23:01 +00:00
printcap Update several more URLs 2017-10-29 08:17:03 +00:00
profile
protocols etc: minor spelling fixes. 2016-05-01 16:43:22 +00:00
rc Fix firstboot fs mount logic 2018-02-06 20:12:05 +00:00
rc.bsdextended
rc.firewall The firewall_type is ignored if not set in rc.conf or rc.conf.local, 2018-02-22 08:25:39 +00:00
rc.initdiskless userland: Fix several typos and minor errors 2017-12-27 03:23:01 +00:00
rc.resume
rc.sendmail
rc.shutdown Since r275359, there is no need to provide a bogus service name. 2015-10-26 15:16:27 +00:00
rc.subr Support configuring arbitrary limits(1) for any daemon in rc.conf 2018-01-24 14:15:06 +00:00
rc.suspend Revert r211288 and move the logic to the acpi_timer itself. 2012-02-08 20:31:42 +00:00
regdomain.xml Correct Russia spelling in regdomain.xml 2018-02-05 18:45:21 +00:00
remote Add ucomX shortcuts just like its uart sibling. 2008-10-27 17:19:14 +00:00
rpc
services Add VXLAN (RFC 7348) port 2017-12-31 17:11:12 +00:00
shells
snmpd.config Move the mibII module up so uncommenting the bridge module works 2017-01-07 09:03:40 +00:00
sysctl.conf
syslog.conf Handle the logfiles in newsyslog and syslogd conditionally, based on 2017-05-13 03:10:50 +00:00
termcap.small