summaryrefslogtreecommitdiff
path: root/sys/kern
AgeCommit message (Collapse)Author
2018-08-29Initialize device numbers for newly allocated ptys. Prevents a panic caused byanton
the following: a new pty is allocated in which the kernel console output is redirected to, poll(2):ing from /dev/console at this point would be delegated to the device with the major number taken from the pty due to the earlier redirection. Since the pty does not have its correct device major assigned, the wrong device ends up being used. ok deraadt@ millert@
2018-08-28Fix stat of path components - this was breaking chrome - because theBob Beck
final directory in a name unveil was not being added with UNVEIL_INSPECT if it was not already unveiled. Now passes just added regress test for this case
2018-08-25Change kcov semantics, kernel code coverage tracing is now enabled on a peranton
thread basis instead of process. The decision to enable on process made development easier initially but could lead to non-deterministic results for processes with more than one thread. This behavior matches the implementation found on both Linux and FreeBSD. With help and ok mpi@ visa@
2018-08-24Remove all knotes from a file descriptor before closing the file inVisa Hankala
fdfree(). This fixes a resource leak with cyclic kqueue references and prevents a kernel stack exhaustion scenario with long kqueue chains. OK mpi@
2018-08-21Rework kcov kernel config. Instead of treating kcov as both an option and aanton
pseudo-device, get rid of the option. Enabling kcov now requires the following line to be added to the kernel config: pseudo-device kcov 1 This is how pseudo devices are enabled in general. A side-effect of this change is that dev/kcov.c will no longer be compiled by default. Prodded by deraadt@; ok mpi@ visa@
2018-08-21Use explicit fd indexing to access fd_ofiles, to clarify the code.Visa Hankala
OK mpi@
2018-08-21If the control message of IP_SENDSRCADDR did not fit into the socketAlexander Bluhm
buffer together with an UDP packet, sosend(9) returned EWOULDBLOCK. As it is an persistent problem, EMSGSIZE is the correct error code. Split the AF_UNIX case into a separate condition and do not change its logic. For atomic protocols, check that both data and control message length fit into the socket buffer. original bug report from Alexander Markert discussed with jca@; OK vgross@
2018-08-20Reorder checks in the read/write(2) family of syscalls to prepare makingMartin Pieuchot
file operations mp-safe. This change makes it clear that `f_offset' is only accessed in vn_read() and vn_write(), which will help taking it out of the KERNEL_LOCK(). This refactoring uncovered a race in vn_read() which is now documented and will be addressed in a later diff. ok visa@
2018-08-20Make fnew() return a new file with only one reference. This makesVisa Hankala
the API more logical. OK kettenis@ mpi@
2018-08-20Preparations for arm64 radeondrm(4) support.Mark Kettenis
ok jsg@ (who pointed out the kern_pledge.c change was necessary as well)
2018-08-19Add kcov(4), a kernel code coverage tracing driver. It's used in conjunctionanton
with the syzkaller kernel fuzzer. So far, 8 distinct panics have been found and fixed. This effort will continue. kcov is limited to architectures using Clang as their default compiler and is not enabled by default. With help from mpi@, thanks! ok kettenis@ mpi@ visa@
2018-08-19Remove a stale/obvious comment.Visa Hankala
OK mpi@
2018-08-15Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This preventsVisa Hankala
a scenario where MP-unsafe code gets run without the kernel lock as a consequence of an unlocked system call. OK mpi@, kettenis@
2018-08-13More clear version of previous namei/pledge/chroot solution. namei flagTheo de Raadt
KERNELPATH indicates this operation is being done on behalf of the kernel, not a process, so ignore chroot of the current process context, start at /, and skip unveil and pledge checks. Discussed with beck and semarie
2018-08-13in sys_statfs(), BYPASSUNVEIL can be passed to NDINIT in the "flags"Theo de Raadt
argument, rather than manually |= afterwards. Observed by semarie
2018-08-13The first panic in pledge_namei should only be for ni_pledge == 0Theo de Raadt
(the other cause is implausible, and crashes with a nice *NULL)
2018-08-13Simplify the startup of the cleaner, reaper and update threads byVisa Hankala
passing the main function directly to kthread_create(9). The start_* functions are mere stepping stones nowadays and can be pruned. They used to contain more logic in the pre-kthread era. While here, set `cleanerproc' and `syncerproc' during the thread creation rather than expect the threads to set the proc pointer. Also, rename `sched_sync' to `syncer_thread' to reduce confusion with the scheduler-related functions. OK kettenis@, deraadt@, mpi@
2018-08-13Make it possible to run pipe(2) and pipe2(2) mostly w/o KERNEL_LOCK():Martin Pieuchot
- Update counters atomatically - Use IPL_MPFLOOR for pipe's pool. - Grab the KERNEL_LOCK() before calling km_alloc(9) & km_free(9) Inputs from kettenis@, ok visa@
2018-08-11Get rid of PLEDGE_STAT, which was a hack used for unveil.Bob Beck
We use UNVEIL_INSPECT instead in the unveil flags for the same purpose, and now add traversed vnodes of a path with UNVEIL_INSPECT instead of with 0 flags and voodoo in unveil_flagmatch. This allows us to uncontort the logic of unveil_flagmatch a bunch. helpful review and ok from semarie@
2018-08-10Update fd_freefile when filtering/closing kqueue descriptors in fdcopy().Joel Sing
Prior to r1.153 of kern_descrip.c, the kqueue descriptors were removed using fdremove(), which reset fd_freefile as appropriate. The new code simply avoids adding the descriptor to the new table, however this means that fd_freefile can be left with an incorrect value, resulting in a file descriptor allocation "hole". Restore the previous behavour by lowering fd_freefile as appropriate when dropping descriptors. Issue found via golang regress tests. ok deraadt@ mpi@ visa@
2018-08-09Remove redundant "kq == kn->kn_kq" checks. The lists kq_knhash andVisa Hankala
kq_knlist are dedicated to a single kqueue instance, which makes the filtering by kn_kq unnecessary. OK kettenis@, mpi@
2018-08-07UNVEIL_* flags defined elsewhere in a .h fileTheo de Raadt
2018-08-07Fix dangling knote references.Visa Hankala
kqueue_close() does not take into account that the kqueue instance may have queued knotes. This can cause a use-after-free if new knotes are enqueued on the kqueue as a result of file closing. Correct the error by dequeueing each knote before freeing it. Since r1.93 of kern_event.c, each kqueue instance has its knotes in nonshared lists kq_knhash and kq_knlist, so kqueue_close() does not have to skip other kqueues' knotes any longer. The code can be simplified by using knote_remove() for clearing the knote lists. The function uses knote_drop() which takes care of knote dequeueing. Found and initial analysis by anton@ OK anton@, mpi@
2018-08-05Decouple unveil from the pledge flags, by adding dedicated unveil flagsBob Beck
to the namei args. This fixes a bug where chmod would be allowed when with only READ. This also allows some further cleanup of some awkward things like PLEDGE_STAT that will follow Lots of assistence from semarie@ - thanks! ok semarie@
2018-08-05Prevent a panic when reboot -q is used by making unveil_removevnodeBob Beck
sane. ok kettenis@
2018-08-03wrap long linesTheo de Raadt
2018-08-03ni_pledge flags are a uint64_t not an int - don't initialize with an int.Bob Beck
2018-08-02Grammar fix in comment.rob
ok deraadt@
2018-08-02Fix panic when we attempt to mess with "." but have a flags mismatchBob Beck
so unveil_check_final returns an error - in this case we can't just VOP_UNLOCK the parent we have to know we are dealing with "." found by anton@ - thanks
2018-07-30regenMartin Pieuchot
2018-07-30Unlock sendmsg(2), sendto(2), recvfrom(2) and recvmsg(2).Martin Pieuchot
ok kettenis@, sthen@, deraadt@, visa@, krw@
2018-07-30Fix a NULL-pointer dereference when calling open() on a cloned device with writeanton
permissions and the flags include O_TRUNC|O_SHLOCK. ok deraadt@
2018-07-30syncTheo de Raadt
2018-07-30rename 2nd argument of unveil from vague "flags" to "permissions";Theo de Raadt
man page change will follow
2018-07-30Use FNONBLOCK instead of SS_NBIO to check/indicate that the I/O modeMartin Pieuchot
for sockets is non-blocking. This allows us to G/C SS_NBIO. Having to keep the two flags in sync in a mp-safe way is complicated. This change introduce a behavior change in sosplice(), it can now always block. However this should not matter much due to the socket lock being taken beforhand. ok bluhm@, benno@, visa@
2018-07-30KNFTheo de Raadt
2018-07-30Allow for us to do a CREATE style lookup on a read only filesystemBob Beck
if and only if we are unveil doing it. Fixes an issue noticed by kn@ where unveil would fail with EROFS on a read only filesystem
2018-07-30activate unveil for testingTheo de Raadt
ok kibbles and bits
2018-07-29revert accidentally changed prototypeBob Beck
2018-07-29Don't exceed UNVEIL_MAX_VNODES with a long path now that we saveBob Beck
the traversed vnodes - noticed and fixed by semarie@
2018-07-29Make sure we don't count looking at .. as a componentBob Beck
as a descending match. Noticed by Stuart Cassoff <3d0g@bell.net>
2018-07-27Add SIOCSIFMTU to the wroute pledge.bket
This is required by, for example, slaacd(8) (which has been pledged) to set MTU on an interface. OK florian@, deraadt@
2018-07-27Don't double vput and panic after looking up "."Bob Beck
2018-07-22Avoid a NULL pointer deref when calling fchown() on a file descriptor belonginganton
to a cloned device. ok kettenis@
2018-07-20Remove a few leftovers from the days of emulation, which could result inTheo de Raadt
a bad/corrupt binary not returning ENOEXEC but some other error. ok guenther kettenis bluhm
2018-07-20Fail if a PT_LOAD segment has a memory size of 0. This prevents a panicMark Kettenis
later on, and it makes no sense for a binary to have such a segment. ok bluhm@, guenther@
2018-07-20Correctly copy across unveil's from parent to child process on fork().Bob Beck
2018-07-18Revert the change that delivers process signals to any threads. AsAlexander Bluhm
side effect pending signals specifically sent to the main thread were handled by other threads. This made gcj in textproc/pdftk port build stall. Noticed and tested by espie@.
2018-07-17unvname_new() is passed something that is always 64-bits so theKenneth R Westerback
parameter should be declared uint64_t and not int. From & for semarie@ who isn't committing at the moment and ok beck@ who is on the road.
2018-07-15Restore correct behaviour to pledge for access and stat, which was brokenBob Beck
by the unveil diff. Noticed at, and diff from semarie@