summaryrefslogtreecommitdiff
path: root/sys/kern/uipc_usrreq.c
AgeCommit message (Collapse)Author
2019-05-24Prevent a kernel hang if an empty message is sent over an SOCK_SEQPACKETAlexander Bluhm
socketpair. Do not wakeup receiver if there is no data available. OK claudio@ anton@
2019-02-13Allow SO_PEERCRED to be called on sockets created with socketpair.Martijn van Duren
OK claudio@ and jca@
2019-02-04Avoid an mbuf double free in the oob soreceive() path. In theAlexander Bluhm
usrreq functions move the mbuf m_freem() logic to the release block instead of distributing it over the switch statement. Then the goto release in the initial check, whether the pcb still exists, will not free the mbuf for the PRU_RCVD, PRU_RVCOOB, PRU_SENSE command. OK claudio@ mpi@ visa@ Reported-by: syzbot+8e7997d4036ae523c79c@syzkaller.appspotmail.com
2018-11-21In unp_internalize() check the length more carefully preventing anClaudio Jeker
underflow in a later calcuation. Using the same CMSG_LEN(0) check that other cmsghdr handlers implemented. Probelm found by anton@ OK anton@, deraadt@, visa@
2018-11-21When using MSG_PEEK to peak into packets skip control messages holdingClaudio Jeker
SCM_RIGHTS from being sent to the userland since they hold kernel internal data and it does not make sense to externalize it. OK deraadt@, guenther@, visa@
2018-11-09M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers forClaudio Jeker
m_leadingspace() and m_trailingspace(). Convert all callers to call directly the functions and remove the defines. OK krw@, mpi@
2018-07-09Use function name in panic string, like in some other places.Claudio Jeker
OK henning@ benno@
2018-07-02Update the file reference count field `f_count' using atomic operationsVisa Hankala
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@
2018-07-01Lock the file descriptor table when accessing the `fd_ofileflags' array.Visa Hankala
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@
2018-06-23Improve the consistency of variable naming in unp_externalize().Visa Hankala
Rename the int array `fdp' to `fds', and use the name `fdp' for a variable that points to the filedesc struct of the current process. This use of `fdp' puts unp_externalize() in line with filesystem code. OK millert@, kettenis@
2018-06-20Unlock sendmsg(2) and sendto(2).Martin Pieuchot
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@
2018-06-11Do not unlock the KERNEL_LOCK() unconditionally in sounlock().Martin Pieuchot
Instead introduce two flags to deal with global lock recursion. This is necessary until we get per-socket lock. Req. by and ok visa@
2018-06-07Make callers of VOP_CREATE(9) and VOP_MKNOD(9) responsible forVisa Hankala
unlocking the directory vnode. OK mpi@, helg@
2018-06-06Pass the socket to sounlock(), this prepare the terrain for per-socketMartin Pieuchot
locking. ok visa@, bluhm@
2018-04-28Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is alwaysVisa Hankala
curproc that does the locking or unlocking, so the proc parameter is pointless and can be dropped. OK mpi@, deraadt@
2018-04-27Move FREF() inside fd_getfile().Martin Pieuchot
ok visa@
2018-04-18Call FREF(9) earlier instead of incrementing `f_count' by hand.Martin Pieuchot
ok millert@, visa@
2018-01-04Unifdef snd/rcv.Martin Pieuchot
ok visa@, claudio@
2017-12-19Remove a 27 year old #ifdef notdef chunk involving SB_LOCK.Martin Pieuchot
ok bluhm@
2017-12-19Inline socket buffer related defines, no functional change.Martin Pieuchot
ok bluhm@
2017-11-02Move PRU_DETACH out of pr_usrreq into per proto pr_detachFlorian Obser
functions to pave way for more fine grained locking. Suggested by, comments & OK mpi
2017-08-11Validate sockaddr from userland in central functions. This resultsAlexander Bluhm
in common checks for unix, inet, inet6 instead of partial checks here and there. Some checks are already done at a higher layer, but better be paranoid with user input. OK claudio@ millert@
2017-06-26Assert that the corresponding socket is locked when manipulating socketMartin Pieuchot
buffers. This is one step towards unlocking TCP input path. Note that all the functions asserting for the socket lock are not necessarilly MP-safe. All the fields of 'struct socket' aren't protected. Introduce a new kernel-only kqueue hint, NOTE_SUBMIT, to be able to tell when a filter needs to lock the underlying data structures. Logic and name taken from NetBSD. Tested by Hrvoje Popovski. ok claudio@, bluhm@, mikeb@
2017-03-13Move PRU_ATTACH out of the pr_usrreq functions into pr_attach.Claudio Jeker
Attach is quite a different thing to the other PRU functions and this should make locking a bit simpler. This also removes the ugly hack on how proto was passed to the attach function. OK bluhm@ and mpi@ on a previous version
2017-02-14Wrap the NET_LOCK() into a per-socket solock() that does nothing forMartin Pieuchot
unix domain sockets. This should prevent the multiple deadlock related to unix domain sockets. Inputs from millert@ and bluhm@, ok bluhm@
2017-02-09Temporarily grab the NET_LOCK() around soisdisconnected().Martin Pieuchot
This makes a (wrong) assert disappear and makes sure we hack to avoid a recursion in the upcall case still work. The real solution to this problem is to not grab the NET_LOCK() before entering uipc_usrreq(). Issue reported by dtucker@
2017-02-09Release the NET_LOCK() before calling unp_detach(), fix a recursionMartin Pieuchot
found by dtucker@
2017-01-27In sosend() the size of the control message for file descriptorAlexander Bluhm
passing is checked. As the data type has changed in unp_internalize(), the calculation has to be adapted in sosend(). Found by relayd regress test on i386. OK millert@
2017-01-25Enable the NET_LOCK(), take 2.Martin Pieuchot
Recursions are currently known and marked a XXXSMP. Please report any assert to bugs@
2017-01-24Track a per-fd flag UF_PLEDGED. This indicates the initial open was done by aTheo de Raadt
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.
2017-01-23File descriptor passing internalizes fd's into an mbuf-stored array ofTheo de Raadt
struct file *, and then externalizes back to fd upon delivery. Convert storage to array of struct fdpass, containing struct file * (and soon something else). memcpy originally intended for alignment purposes can be removed because CMSG_ALIGN is _ALIGN. There is some anxiety over changing this code, but it reads easier. ok mpi guenther kettenis
2016-12-29Change NET_LOCK()/NET_UNLOCK() to be simple wrappers aroundMartin Pieuchot
splsoftnet()/splx() until the known issues are fixed. In other words, stop using a rwlock since it creates a deadlock when chrome is used. Issue reported by Dimitris Papastamos and kettenis@ ok visa@
2016-12-29Release the NET_LOCK() before calling unp_connect(). It is not possibleMartin Pieuchot
to hold it during VFS operations as NFS might try to grab it. Problem also reported by Siegfried Rudzio on bugs@. ok visa@
2016-12-22Release the NET_LOCK() before namei(9) as a workaround to let NFS bootMartin Pieuchot
work without assert. ok visa@, bluhm@
2016-12-22Revert workaround for NFS boot, it triggers the following assert:Martin Pieuchot
swakeup sowakeup sowwakeup unp_connect2 unp_connect uipc_usrreq soconnect sys_connect reported by stsp@, tb@ and RT Thrush
2016-12-22Work around a NET_LOCK() recursion seen during NFS netboot:Visa Hankala
sosend <- NET_LOCK() nfs_send nfs_request nfs_lookup VOP_LOOKUP vfs_lookup namei unp_connect uipc_usrreq soconnect <- NET_LOCK() sys_connect OK bluhm@ mpi@
2016-12-19Introduce the NET_LOCK() a rwlock used to serialize accesses to the partsMartin Pieuchot
of the network stack that are not yet ready to be executed in parallel or where new sleeping points are not possible. This first pass replace all the entry points leading to ip_output(). This is done to not introduce new sleeping points when trying to acquire ART's write lock, needed when a new L2 entry is created via the RT_RESOLVE. Inputs from and ok bluhm@, ok dlg@
2016-11-29m_free() and m_freem() test for NULL. Simplify callers which had their ownJonathan Gray
NULL tests. ok mpi@
2016-08-26The *_HEAD_INITIALIZER() macros are documented as taking the struct,Philip Guenther
not a pointer to it
2016-08-17Fix an mbuf leak and missing error propagation in uipc_usrreq(PRU_SEND)Alexander Bluhm
in case sbappendcontrol() fails. From Simon Mages; OK mikeb@
2016-07-19instead of messing about with pointer arithmetic, add an empty arrayTed Unangst
to the end of the defer structure. solves sizing and alignment concerns.
2016-07-12in the great unp_gc rewrite, a null check was lost. we have spent someTed Unangst
time investigating and arguing about whether a NULL fp is a bug or not, but what has become clear is that NULL fps get passed to unp_discard and have been for quite some time. restore old accomodating behavior by checking for null in unp_gc. ok deraadt kettenis
2016-07-12The check for pledge "recvfd" was mistakenly only being performedTheo de Raadt
for chroot'd processes. ok stefan semarie
2016-04-25remove systrace remnantsTed Unangst
2016-03-19Remove the unused flags argument from VOP_UNLOCK().natano
torture tested on amd64, i386 and macppc ok beck mpi stefan "the change looks right" deraadt
2015-12-05remove stale lint annotationsTed Unangst
2015-11-03AF_UNIX connect is a "unix" operation, not "rpath wpath"Theo de Raadt
2015-11-02move the pledgenote annotation from `struct proc' to `struct nameidata'Sebastien Marie
pledgenote is used for annotate the policy for a namei context. So make it tracking the nameidata. It is expected for the caller to explicitly define the policy. It is a kernel bug to not do so. ok deraadt@
2015-11-01refactor pledge_*_check and pledge_fail functionsSebastien Marie
- rename _check function without suffix: a "pledge" function called from anywhere is a "check" function. - makes pledge_fail call the responsability to the _check function. remove it from caller. - make proper use of (potential) returned error of _check() functions. - adds pledge_kill() and pledge_protexec() with and OK deraadt@
2015-11-01bind() on AF_UNIX should set PLEDGE_UNIX not PLEDGE_CPATH; ok semarieTheo de Raadt