Commit Graph

15072 Commits

Author SHA1 Message Date
Mariusz Zaborski
ad5e83dd3c fd: fix up fget_cap
If the kernel is not compiled with the CAPABILITIES kernel options
fget_unlocked doesn't return the sequence number so fd_modify will
always report modification, in that case we got infinity loop.

Reported by:	br
Reviewed by:	mjg
Tested by:	br, def
2016-09-23 08:13:46 +00:00
Mateusz Guzik
deffc4a026 fd: fix up fgetvp_rights after r306184
fget_cap_locked returns a referenced file, but the fgetvp_rights does
not need it. Instead, due to the filedesc lock being held, it can
ref the vnode after the file was looked up.

Fix up fget_cap_locked to be consistent with other _locked helpers and not
ref the file.

This plugs a leak introduced in r306184.

Pointy hat to: mjg, oshogbo
2016-09-23 06:51:46 +00:00
Mateusz Guzik
1d2541fd1a cache: get rid of the global lock
Add a table of vnode locks and use them along with bucketlocks to provide
concurrent modification support. The approach taken is to preserve the
current behaviour of the namecache and just lock all relevant parts before
any changes are made.

Lookups still require the relevant bucket to be locked.

Discussed with:		kib
Tested by:	pho
2016-09-23 04:45:11 +00:00
Gleb Smirnoff
a2d8f9d2fc Fix regression from r297400, which truncates headers in case of low socket
buffer and put a small optimization for low socket buffer case:

- Do not hack uio_resid, and let m_uiotombuf() properly take care of it. This
  fixes truncation of headers at low buffer.
- If headers ate all the space, jump right to the end of the cycle, to
  avoid doing single page I/O and allocating zero length mbuf.
- Clear hdr_uio only if space is positive, which indicates that all uio
  was copied in.

Reviewed by:	pluknet, jtl, emax, rrs, lstewart, emax, gallatin, scottl
2016-09-22 20:34:44 +00:00
Ruslan Bukin
30f3bfe58e Adjust the sopt_val pointer on bigendian systems (e.g. MIPS64EB).
sooptcopyin() checks if size of data provided by user is <= than we can
accept, else it strips down the size. On bigendian platforms we have to
move pointer as well so we copy the actual data.

Reviewed by:	gnn
Sponsored by:	DARPA, AFRL
Sponsored by:	HEIF5
Differential Revision:	https://reviews.freebsd.org/D7980
2016-09-22 12:41:53 +00:00
Mariusz Zaborski
6490bc6529 fd: simplify fgetvp_rights by using fget_cap_locked
Reviewed by:	mjg
2016-09-22 11:54:20 +00:00
Mariusz Zaborski
85b0f9de11 capsicum: propagate rights on accept(2)
Descriptor returned by accept(2) should inherits capabilities rights from
the listening socket.

PR:		201052
Reviewed by:	emaste, jonathan
Discussed with:	many
Differential Revision:	https://reviews.freebsd.org/D7724
2016-09-22 09:58:46 +00:00
Mark Johnston
bdaf6d6913 Regenerate syscall provider argument strings. 2016-09-22 04:50:03 +00:00
Mark Johnston
5a4dfc8d83 Annotate syscall provider pointer arguments with the "userland" keyword.
This causes dtrace to automatically copyin arguments from userland, so
one no longer has to explicitly use the copyin() action to do so. Moreover,
copyin() on userland addresses is a no-op, so existing scripts should be
unaffected by this change.

Discussed with:	rstone
MFC after:	2 weeks
2016-09-22 04:49:31 +00:00
Konstantin Belousov
851194715d Make resettodr_lock accessible outside subr_rtc.c. Protect
CLOCK_GETTIME() with the lock.

Now all time-related accesses to the CMOS for RTC should be under the
lock.  This is needed to allow upcoming EFI Runtime Services support
to provide required execution environment for the firmware calls.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2016-09-21 10:15:08 +00:00
Konstantin Belousov
643f6f47fd Add PROC_TRAPCAP procctl(2) controls and global sysctl kern.trap_enocap.
Both can be used to cause processes in capability mode to receive
SIGTRAP when ENOTCAPABLE or ECAPMODE errors are returned from
syscalls.

Idea by:	emaste
Reviewed by:	oshogbo (previous version), emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D7965
2016-09-21 08:23:33 +00:00
Edward Tomasz Napierala
e313b4dd95 Fix bug introduced with r302388, which could cause processes accessing
automounted shares to hang with "vfs_busy" wchan.

(As a workaround one can run 'automount -u' from cron.)

Reviewed by:	kib@
MFC after:	1 month
2016-09-21 05:44:13 +00:00
Sepherosa Ziehau
a5ec35dfee Fix LINT building.
Sponsored by:	Microsoft
2016-09-18 07:37:00 +00:00
Ed Maste
69a2875821 Renumber license clauses in sys/kern to avoid skipping #3 2016-09-15 13:16:20 +00:00
Kevin Lo
c3bef61e58 Remove the 4.3BSD compatible macro m_copy(), use m_copym() instead.
Reviewed by:	gnn
Differential Revision:	https://reviews.freebsd.org/D7878
2016-09-15 07:41:48 +00:00
Mariusz Zaborski
6e70b4f058 fd: add fget_cap and fget_cap_locked primitives
They can be used to obtain capabilities along with a referenced fp.

Reviewed by:	mjg@
2016-09-12 22:46:19 +00:00
John Baldwin
71499f6a2d Make device_quiet() an attachment property.
In particular, reset the DF_QUIET flag when detaching from a device so
that a driver that marks a device quiet doesn't dictate policy for a
different driver that may claim the device in the future.

Reviewed by:	rpokala, wblock
MFC after:	2 weeks
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D7803
2016-09-12 18:06:42 +00:00
Mateusz Guzik
a27815330c cache: improve scalability by introducing bucket locks
An array of bucket locks is added.

All modifications still require the global cache_lock to be held for
writing. However, most readers only need the relevant bucket lock and in
effect can run concurrently to the writer as long as they use a
different lock. See the added comment for more details.

This is an intermediate step towards removal of the global lock.

Reviewed by:	kib
Tested by:	pho
2016-09-10 16:29:53 +00:00
Konstantin Belousov
2e4fd101fa Fix build 2016-09-10 09:00:12 +00:00
Jilles Tjoelker
d30e66e53a wait: Do not copyout uninitialized status/rusage/wrusage.
If wait4() or wait6() return 0 because of WNOHANG, the status, rusage and
wrusage information should not be returned.

PR:		212048
Reported by:	Casey Lucas
MFC after:	2 weeks
2016-09-09 21:58:48 +00:00
Mateusz Guzik
a0d45f0fc8 locks: add backoff for spin mutexes and thread lock
Reviewed by:	jhb
2016-09-09 19:13:02 +00:00
Ed Maste
82b3cec52b ANSIfy uipc_syscalls.c
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D7839
2016-09-09 17:40:26 +00:00
Ed Maste
e62264e2dd Update capabilities.conf comment
getdtablesize is per-process state, not global state
2016-09-08 14:04:04 +00:00
Kevin Lo
cee4a05669 In m_devget(), if the data fits in a packet header mbuf, check the amount
of data is less than or equal to MHLEN instead of MLEN when placing initial
small packet header at end of mbuf.

Reviewed by:	glebius
MFC after:	3 days
2016-09-08 01:02:53 +00:00
Brooks Davis
ed6d876b19 Modernize the initalization of sigproptbl.
Use C99 designators to set the value of each slot and the nitems macro to
check for valid entries. In the process, switch to indexing by signal
number rather than signal-1 for improved clarity.

Obtained from:	CheriBSD (a6053c5abf)
Sponsored by:	DARPA, AFRL
Reviewed by:	kib
2016-09-06 22:03:53 +00:00
Mateusz Guzik
5b7d9ae2fd cv: do a lockless check for no waiters in cv_signal and cv_broadcastpri
In case of some consumers like zfs there are no waiters vast majority of
the time

Reviewed by:	jhb
MFC after:	1 week
2016-09-06 17:16:59 +00:00
Mateusz Guzik
591df14528 cache: defer freeing entries until after the global lock is dropped
This also defers vdrop for held vnodes.

Glanced at by:	kib
2016-09-04 16:52:14 +00:00
Mateusz Guzik
31977b420a cache: manage negative entry list with a dedicated lock
Since negative entries are managed with a LRU list, a hit requires a
modificaton.

Currently the code tries to upgrade the global lock if needed and is
forced to retry the lookup if it fails.

Provide a dedicated lock for use when the cache is only shared-locked.

Reviewed by:	kib
MFC after:	1 week
2016-09-04 08:58:35 +00:00
Mateusz Guzik
b9042ae1bf cache: put all negative entry management code into dedicated functions
Reviewed by:	kib
MFC after:	1 week
2016-09-04 08:55:15 +00:00
Mark Johnston
3da0f3c9ae Micro-optimize sleepq_signal().
Lift a comparison out of the loop that finds the highest-priority thread
on the queue.

MFC after:	1 week
2016-09-04 00:29:48 +00:00
Brooks Davis
fd50a70770 Merge from CheriBSD:
Rename sigprop-table constants to SIGPROP_ from SA_ to reduce the
impression of a namespace collision.

Submitted by:	rwatson
Reviewed by:	jhb, kib (slightly different versions)
Obtained from:	CheriBSD (814ec5771c)
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D7616
2016-09-02 18:22:56 +00:00
Ed Maste
dd38731e09 allow kern.proc.nfds sysctl in capability mode
Reviewed by:	allanjude
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D7733
2016-09-01 02:51:50 +00:00
Patrick Kelsey
da2ded6575 _taskqueue_start_threads() now fails if it doesn't actually start any threads.
Reviewed by:	jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D7701
2016-09-01 02:05:46 +00:00
Mark Johnston
99ab95db4d Rename unp_dispose_so() to unp_dispose().
It implements the dom_dispose method for local socket domain, so its name
should match the method name.
2016-08-31 21:48:22 +00:00
Ed Maste
bce38b9f35 Regnerate after r305140, getdtablesize in capability mode
Sponsored by:	The FreeBSD Foundation
2016-08-31 18:37:51 +00:00
Ed Maste
ca380195ab Allow getdtablesize in capability mode
getdtablesize is "trivial global state" and is similar to
getrlimit(RLIMIT_NOFILE), so should be permitted in capability mode.

Reviewed by:	oshogbo
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D7719
2016-08-31 18:33:15 +00:00
Allan Jude
61bd7ae0ec Eliminate unnecessary loop in _cap_check()
Calling cap_rights_contains() several times with the same inputs is not
going to produce a different output. The variable being iterated, i, is
never used inside the for loop.

The loop is actually done in cap_rights_contains()

Submitted by:	Ryan Moeller <ryan@freqlabs.com>
Reviewed by:	oshogbo, ed
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D7369
2016-08-31 17:52:11 +00:00
Nathan Whitehorn
09c697016b Back out misfired extra file in r305108. 2016-08-31 04:03:55 +00:00
Nathan Whitehorn
c9a124dc9a Refix operation on sparse CPU mappings as in r302372, temporarily broken
by r304716.

PR:		kern/210106
MFC after:	2 days
2016-08-31 04:02:52 +00:00
Mateusz Guzik
4cbafea09c fd: add fdeget_locked and use in kern_descrip 2016-08-30 21:53:22 +00:00
Bryan Drewery
533f3e1026 Reduce duplicated logic for !SMP
Sponsored by:	EMC / Isilon Storage Division
2016-08-30 19:26:07 +00:00
John Baldwin
e05ec081fe Implement 'devctl clear driver' to undo a previous 'devctl set driver'.
Add a new 'clear driver' command for devctl along with the accompanying
ioctl and devctl_clear_driver() library routine to reset a device to
use a wildcard devclass instead of a fixed devclass.  This can be used
to undo a previous 'set driver' command.  After the device's name has
been reset to permit wildcard names, it is reprobed so that it can
attach to newly-available (to it) device drivers.

MFC after:	1 month
Sponsored by:	Chelsio Communications
2016-08-29 22:48:36 +00:00
Mateusz Guzik
11d3ad2eab vfs: provide a common exit point in namei for error cases
This shortens the function, adds the SDT_PROBE use for error cases and
consistenly unrefs rootdir last.

Reviewed by:	kib
MFC after:	2 weeks
2016-08-27 22:43:41 +00:00
Konstantin Belousov
9ce60e28fd Consistently delimit each vnode description block with two blank
lines.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2016-08-27 18:12:42 +00:00
Konstantin Belousov
0f2d97838d In both do_rw_wrlock() and do_rw_rdlock() after r304808, do not
obliterate possible error from sleep with errors from
umtxq_check_susp(), when looping to clear URWLOCK_{READ,WRITE}_WAITERS.

Noted and reviewed by:	vangyzen
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2016-08-25 19:15:02 +00:00
Konstantin Belousov
28e21133f3 Prevent leak of URWLOCK_READ_WAITERS flag for urwlocks.
If there was some error, e.g. the sleep was interrupted, as in the
referenced PR, do_rw_rdlock() did not cleared URWLOCK_READ_WAITERS.
Since unlock only wakes up write waiters when there is no read
waiters, for URWLOCK_PREFER_READER kind of locks, the result was
missed wakeups for writers.

In particular, the most visible victims are ld-elf.so locks in
processes which loaded libthr, because rtld locks are urwlocks in
prefer-reader mode.  Normal rwlocks fall into prefer-reader mode only
if thread already owns rw lock in read mode, which is not typical and
correspondingly less visible.  In the PR, unowned rtld bind lock was
waited for in the process where only one thread was left alive.

Note that do_rw_wrlock() correctly clears URWLOCK_WRITE_WAITERS in
case of errors.

Reported and tested by:	longwitz@incore.de
PR:	211947
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2016-08-25 16:35:42 +00:00
Bruce Evans
d350ce61cf Less-quick fix for locking fixes in r172250. r172250 added a second
syscons spinlock for the output routine alone.  It is better to extend
the coverage of the first syscons spinlock added in r162285.  2 locks
might work with complicated juggling, but no juggling was done.  What
the 2 locks actually did was to cover some of the missing locking in
each other and deadlock less often against each other than a single
lock with larger coverage would against itself.  Races are preferable
to deadlocks here, but 2 locks are still worse since they are harder
to understand and fix.

Prefer deadlocks to races and merge the second lock into the first one.

Extend the scope of the spinlocking to all of sc_cnputc() instead of
just the sc_puts() part.  This further prefers deadlocks to races.

Extend the kdb_active hack from sc_puts() internals for the second lock
to all spinlocking.  This reduces deadlocks much more than the other
changes increases them.  The s/p,10* test in ddb gets much further now.
Hide this detail in the SC_VIDEO_LOCK() macro.  Add namespace pollution
in 1 nested #include and reduce namespace pollution in other nested
#includes to pay for this.

Move the first lock higher in the witness order.  The second lock was
unnaturally low and the first lock was unnaturally high.  The second
lock had to be above "sleepq chain" and/or "callout" to avoid spurious
LORs for visual bells in sc_puts().  Other console driver locks are
already even higher (but not adjacent like they should be) except when
they are missing from the table.  Audio bells also benefit from the
syscons lock being high so that audio mutexes have chance of being
lower.  Otherwise, console drviver locks should be as low as possible.
Non-spurious LORs now occur if the bell code calls printf() or is
interrupted (perhaps by an NMI) and the interrupt handler calls
printf().  Previous commits turned off many bells in console i/o but
missed ones done by the teken layer.
2016-08-25 13:46:52 +00:00
Robert Watson
70a98c110e Audit the accepted (or rejected) username argument to setlogin(2).
(NB: This was likely a mismerge from XNU in audit support, where the
text argument to setlogin(2) is captured -- but as a text token,
whereas this change uses the dedicated login-name field in struct
audit_record.)

MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2016-08-20 20:28:08 +00:00
Robert Watson
c3c0088bb0 Audit additional vnode information in the implementation of the
ftruncate(2) system call.  This was not required by the Common
Criteria, which needed only open-time audit.

MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
2016-08-20 18:51:48 +00:00
Mark Johnston
e5574e0966 Don't set P2_PTRACE_FSTP in a process that invokes ptrace(PT_TRACE_ME).
Such processes are stopped synchronously by a direct call to
ptracestop(SIGTRAP) upon exec. P2_PTRACE_FSTP causes the exec()ing thread
to suspend itself while waiting for a SIGSTOP that never arrives.

Reviewed by:	kib
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D7576
2016-08-19 17:57:14 +00:00