summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_descrip.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* dup2(n,n) would rlimit check before handling the n==n shortcut,deraadt2019-05-131-6/+6
| | | | | and incorrectly return EBADF when n>curlim. ok millert guenther tedu
* trace struct flock; ok visa@anton2018-11-051-1/+9
|
* Remove all knotes from a file descriptor before closing the file invisa2018-08-241-1/+2
| | | | | | | fdfree(). This fixes a resource leak with cyclic kqueue references and prevents a kernel stack exhaustion scenario with long kqueue chains. OK mpi@
* Use explicit fd indexing to access fd_ofiles, to clarify the code.visa2018-08-211-7/+6
| | | | OK mpi@
* Make fnew() return a new file with only one reference. This makesvisa2018-08-201-3/+2
| | | | | | the API more logical. OK kettenis@ mpi@
* Remove a stale/obvious comment.visa2018-08-191-7/+1
| | | | OK mpi@
* Update fd_freefile when filtering/closing kqueue descriptors in fdcopy().jsing2018-08-101-2/+5
| | | | | | | | | | | | | 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@
* Move socket & pipe specific logic in their ioctl handler.mpi2018-07-101-24/+4
| | | | ok visa@, tb@
* Fix an argument type error that happens when translating fcntl(F_SETOWN)visa2018-07-071-8/+9
| | | | | | | | to ioctl(TIOCSPGRP). The ioctl handlers expect a pointer to an int, so read the argument into a local int variable and pass the variable's address to the handler instead of referencing SCARG(uap, arg) directly. OK guenther@, mpi@
* Update the file reference count field `f_count' using atomic operationsvisa2018-07-021-31/+63
| | | | | | | | | instead of using a mutex for update serialization. Use a per-fdp mutex to manage updating of file instance pointers in the `fd_ofiles' array to let fd_getfile() acquire file references safely with concurrent file reference releases. OK mpi@
* Assert that fdp is locked in fdalloc().visa2018-07-021-1/+3
| | | | OK mpi@
* Lock the file descriptor table when accessing the `fd_ofileflags' array.visa2018-07-011-1/+3
| | | | | | | | This prevents the array from being freed too early. In the function unp_internalize(), the locking also ensures the per-fdp flags stay coherent with the file instance. OK mpi@
* Raise file_pool's IPL to prevent deadlocks with the newly unlockedvisa2018-06-271-2/+2
| | | | | | system calls. OK mpi@
* Remove a duplicate fd_used() call. The new file descriptor passedvisa2018-06-261-2/+3
| | | | | | | | | | | | to dupfdopen() has already been registered with fd_used() in fdalloc(). The duplicate call distorted the number of open file descriptors returned by getdtablecount(2) if a file was opened via /dev/fd/. While there, assert that the file instance should already be in the file list. OK mpi@
* Implement DRI3/prime support. This allows graphics buffers to be passedkettenis2018-06-251-2/+6
| | | | | | | | between processes using file descriptors. This provides an alternative to eporting them with guesable 32-bit IDs. This implementation does not (yet) allow sharing of graphics buffers between GPUs. ok mpi@, visa@
* Introduce fnew(), a function to initialize a `struct file'.mpi2018-06-251-12/+31
| | | | | | Commiting now to help refactoring of DRI3 and diskmap rewrite. ok visa@, kettenis@ as part of a larger diff.
* Use atomic operations for updating `numfiles'. This makes the file countvisa2018-06-241-5/+6
| | | | | | tracking work without locks. OK kettenis@, deraadt@
* Unlock sendmsg(2) and sendto(2).mpi2018-06-201-18/+42
| | | | | | | | | | These syscalls can now be executed w/o the KERNEL_LOCK() depending on the kind of socket. The current solution uses a single global mutex to serialize access to, and reference count, 'struct file'. ok visa@, kettenis@
* Put file descriptors on shared data structures when they are completelympi2018-06-181-46/+50
| | | | | | | | | | | | | | | | | setup, take 3. LARVAL fd still exist, but they are no longer marked with a flag and no longer reachable via `fd_ofiles[]' or the global linked list. This allows us to simplifies a lot code grabbing new references to fds. All of this is now possible because dup2(2) refuses to clone LARVAL fds. Note that the `fdplock' could now be release in all open(2)-like syscalls, just like it is done in accept(2). With inputs from Mathieu Masson, visa@, guenther@ and art@ Previous version ok bluhm@, ok visa@, sthen@
* Move kqueue related fields from struct filedesc to struct kqueue. Solves a panicanton2018-06-171-8/+3
| | | | | | | | | | | | | in knote_processexit() that can occur when the filedesc belonging to the process already has been freed. Similiar work has been done in: - FreeBSD (commit bc1805c6e871c178d0b6516c3baa774ffd77224a) - DragonFlyBSD (commit ccafe911a3aa55fd5262850ecfc5765cd31a56a2) Thanks to tb@ for testing. ok kettenis@ mpi@ visa@
* Revert introduction of fdinsert(), a sanitify check triggers whenmpi2018-06-051-48/+38
| | | | | | closing a LARVAL file. Found the hardway by sthen@.
* Add an assert that makes explicit that finishdup() should receivevisa2018-06-021-1/+3
| | | | | | an inserted fp. OK mpi@
* Put file descriptors on shared data structures when they are completelympi2018-06-021-38/+46
| | | | | | | | | | | | | | | | | setup. LARVAL fd still exist, but they are no longer marked with a flag and no longer reachable via `fd_ofiles[]'. This allows us to simplifies a lot code grabbing new references to fds. All of this is now possible because dup2(2) refuses to clone LARVAL fds. Note that the `fdplock' could now be release in all open(2)-like syscalls, just like it is done in accept(2). With inputs from Mathieu -, visa@, guenther@ and art@ ok visa@, bluhm@
* Use IPL_MPFLOOR for mutexes that can be taken w/ and w/o the KERNEL_LOCK().mpi2018-05-311-2/+2
| | | | From Mathieu <naabed at poolp.org>, ok visa@, tb@
* `f_mtx' must block interrupts as long as it is taken w/ and w/o thempi2018-05-291-2/+6
| | | | | | | | KERNEL_LOCK(). Otherwise a deadlock can occur as found the hardway by tb@. ok tb@, kettenis@, visa@
* Returns EBUSY if dup2(2) is called for a LARVAL file.mpi2018-05-281-6/+7
| | | | | | | | | | | This prevents a panic due to a double free if a program exits after having called accept(2) and dup2(2) on the same fd but without the corresponding connect(5). It will also allows us to simplify file descriptor locking. The error code has been choosed to match Linux's behavior. Pointed by Mathieu on tech@ after a discussion with guenther@. ok visa@
* Change fd_iterfile() to not return imature fps instead of skipping themmpi2018-05-081-2/+2
| | | | | | later. ok bluhm@, visa@
* Protect per-file counters and document which lock is used to protectmpi2018-05-081-1/+2
| | | | | | | | | the other fields. Once we no longer have any [k] (kernel lock) protections, we'll be able to unlock almost all network related syscalls. Inputs from and ok bluhm@, visa@
* Remove proc from the parameters of vn_lock(). The parameter isvisa2018-05-021-2/+2
| | | | | | unnecessary because curproc always does the locking. OK mpi@
* Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is alwaysvisa2018-04-281-2/+2
| | | | | | | curproc that does the locking or unlocking, so the proc parameter is pointless and can be dropped. OK mpi@, deraadt@
* Move FREF() inside fd_getfile().mpi2018-04-271-12/+12
| | | | ok visa@
* Rewrite fdcopy() to avoid memcpy()s.mpi2018-04-261-52/+38
| | | | With and ok visa@
* Introduce fd_iterfile() a new helper function to iterate over `filehead'.mpi2018-04-251-1/+23
| | | | | | | This turns `filehead' into a local variable, that will make it easier to protect it. ok visa@
* Do a FREF()/FRELE() dance after fd_getfile() in sys_fcntl().mpi2018-04-181-3/+8
| | | | ok visa@
* Use the current reference instead of incrementing `f_count' manually andmpi2018-04-121-5/+4
| | | | | | | | calling FRELE(9) in finishdup(). Update comments accordingly. ok bluhm@, visa@
* Call FREF(9) earlier instead of incrementing `f_count' directly inmpi2018-04-121-4/+8
| | | | | | dupfdopen(). ok bluhm@, visa@
* The pledge flag for file descriptors opened from /dev/fd was alwaysbluhm2018-04-111-3/+1
| | | | | | | set for pledged processes. dup(2) uses the flag from the old file descriptor. Make open /dev/fd consistent to duplicate and inherit the flag. OK deraadt@
* Revert previous, it introduced a bug found the hardway by landry@.mpi2018-04-091-16/+12
|
* Call finishdup() instead of rerolling it in dupfdopen().mpi2018-04-091-12/+16
| | | | | | While here call FREF() right after fd_getfile(). ok bluhm@, visa@
* Retain the UF_PLEDGED flag from the original fd during dup(2).bluhm2018-04-061-2/+2
| | | | | Nothing uses this fd-tracking part of pledge yet. OK deraadt@
* Call FREF() right after fd_getfile() in dodup3().mpi2018-04-031-3/+6
| | | | ok millert@, bluhm@
* Call FREF() right after fd_getfile() in sys_flock().mpi2018-03-281-3/+5
| | | | | | | This ensure that all operations manipulating a 'struct file *' do so with a properly refcounted element. ok visa@, bluhm@
* Remove almost unused `flags' argument of suser().mpi2018-02-191-2/+2
| | | | | | | The account flag `ASU' will no longer be set but that makes suser() mpsafe since it no longer mess with a per-process field. No objection from millert@, ok tedu@, bluhm@
* Initialize a local variable to not leak kernel stack info to userlandmpi2017-07-201-1/+2
| | | | | | | | if TIOCGPGRP fail. Issue found by Ilja van Sprundel. ok bluhm@, millert@, deraadt@
* Add a flags argument to falloc() that lets it optionally set theguenther2017-02-111-6/+8
| | | | | | | close-on-exec flag on the newly allocated fd. Make falloc()'s return arguments non-optional: assert that they're not NULL. ok mpi@ millert@
* Track a per-fd flag UF_PLEDGED. This indicates the initial open was done by aderaadt2017-01-241-3/+10
| | | | | | | | | | | | | | | | pledged process. dup(2) and recvmsg(2) retain UF_PLEDGED from the original fd. In pledge "exec" circumstances, exceve clears UF_PLEDGED on all the process's fds. In a pledge'd process, ioctl(2) can use this additional information to grant access to ioctl's which are more sensitive or dive deeply into the kernel. Developers will be encouraged to open such sensitive resources before calling pledge(2), rather than afterwards. That matches the heading of privsep development practices. Future changes will introduce those ioctl(2) changes. Lots of discussions with semarie guenther and benno.
* Allocate all memory chunks, and potentially sleeping, before freeingmpi2017-01-231-6/+11
| | | | | | | | | the old array of open files. Fix a race for multi-threaded processes reported by cheeky.m@gmx.com on bugs@ and analyzed with bluhm@. ok deraadt@, bluhm@
* Avoid curproc dance in dupfdopen(), by passing a struct proc *deraadt2017-01-231-7/+9
| | | | ok guenther mpi
* move knhash size to event.h, use it for hashfree. from Mathieu -tedu2016-09-241-2/+2
| | | | ok guenther
* all pools have their ipl set via pool_setipl, so fold it into pool_init.dlg2016-09-151-7/+5
| | | | | | | | | | | | | | | | | | | | | | the ioff argument to pool_init() is unused and has been for many years, so this replaces it with an ipl argument. because the ipl will be set on init we no longer need pool_setipl. most of these changes have been done with coccinelle using the spatch below. cocci sucks at formatting code though, so i fixed that by hand. the manpage and subr_pool.c bits i did myself. ok tedu@ jmatthew@ @ipl@ expression pp; expression ipl; expression s, a, o, f, m, p; @@ -pool_init(pp, s, a, o, f, m, p); -pool_setipl(pp, ipl); +pool_init(pp, s, a, ipl, f, m, p);