summaryrefslogtreecommitdiff
path: root/sys/compat/linux/linux_socket.c
Commit message (Collapse)AuthorAgeFilesLines
* unix(4): Enhance LOCAL_CREDS_PERSISTENT ABIConrad Meyer2020-11-171-0/+13
| | | | | | | | | | | | | | As this ABI is still fresh (r367287), let's correct some mistakes now: - Version the structure to allow for future changes - Include sender's pid in control message structure - Use a distinct control message type from the cmsgcred / sockcred mess Discussed with: kib, markj, trasz Differential Revision: https://reviews.freebsd.org/D27084 Notes: svn path=/head/; revision=367776
* - add more linux socket options (sorted by value)Alexander Leidinger2020-11-081-26/+343
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - map those IPv4 / IPv6 socket options which exist in FreeBSD + most of them visually verified to have the same type/layout of arguments + not tested with linux programs to behave as intended - be more human readable for known options which are not handled - be more verbose for unhandled socket message flags we know about - print the jail ID in linux_msg if run in a jail - add possibility to print debug message about known missing parts only once - add multiple levels of sysctl linux.debug: 1: print debug messages, tell about unimplemented stuff (only once) 2: like 1, but also print messages about implemented but not tested stuff (only once) 3+: like 2, but no rate limiting of messages - increase default linux debug level from 1 to 3 We are a lot more verbose in as we need to be (e.g. some of the IP socket options which are the same, and share the same memory layout, and are believed to work). The reason is that we have no good testsuite to test those linux-bits. The LTP or other test suites like the python one, are not fully up to the task we need. As such the excessive messages about emulated but not tested socket options. IMO any MFC (possible, but most probably not by me) should set the default debug level to 1. Discussed with: trasz Notes: svn path=/head/; revision=367481
* linux(4): Improve netlink diagnosticsConrad Meyer2020-11-031-15/+33
| | | | | | | | | | | | | | | | Add some missing netlink_family definitions and produce vaguely human-readable error messages for those definitions, like we used to do for just ROUTE and KOBJECT_UEVENTS. Additionally, if we know it's a netfilter socket but didn't find it in the table, fall back to printing that instead of the generic handler ("socket domain 16, ..."). No change to the emulator correctness, just mildly improved diagnostics for gaps. Notes: svn path=/head/; revision=367303
* linux(4): Emulate Linux SOL_SOCKET:SO_PASSCREDConrad Meyer2020-11-031-0/+8
| | | | | | | | | | | | This is required by some major linux applications, such as Chrome and Firefox. (As well as Electron-using applications, which are essentially a bundled version of Chrome.) Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D27012 Notes: svn path=/head/; revision=367288
* Fix misnomer - linux_to_bsd_errno() does the exact opposite.Edward Tomasz Napierala2020-10-271-1/+1
| | | | | | | | | | Reported by: arichardson MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D26965 Notes: svn path=/head/; revision=367079
* Tweak linux(4) socket(2) debug messages.Edward Tomasz Napierala2020-10-241-0/+14
| | | | | | | | | MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D26900 Notes: svn path=/head/; revision=367001
* Make linux(4) warn about unsupported socket(2) types.Edward Tomasz Napierala2020-10-211-1/+4
| | | | | | | | | MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25680 Notes: svn path=/head/; revision=366915
* Reduce code duplication by introducing linux_copyout_sockaddr()Edward Tomasz Napierala2020-09-171-40/+26
| | | | | | | | | | | | helper function. No functional changes. Reviewed by: emaste MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25804 Notes: svn path=/head/; revision=365834
* Get rid of sv_errtbl and SV_ABI_ERRNO().Edward Tomasz Napierala2020-09-171-1/+1
| | | | | | | | | Reviewed by: kib Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D26388 Notes: svn path=/head/; revision=365832
* compat: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-3/+0
| | | | Notes: svn path=/head/; revision=365080
* Fix handling of ancillary data on non-AF_UNIX Linux sockets.Mark Johnston2020-08-181-1/+2
| | | | | | | | | | | | | | | | After r340674, the "continue" would restart the loop without having updated clen, resulting in an infinite loop. Restore the old behaviour of simply ignoring all control messages on such sockets, since we currently only implement handling for AF_UNIX-specific messages. Reported by: syzkaller Reviewed by: tijl MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D26093 Notes: svn path=/head/; revision=364346
* Fix Linux recvmsg(2) when msg_namelen returned is 0. PreviouslyEdward Tomasz Napierala2020-07-051-3/+9
| | | | | | | | | | | | | | | | | | it would fail with EINVAL, breaking some of the Python regression tests. While here, cap the user-controlled message length. Note that the code doesn't seem to be copying out the new length in either (success or failure) case. This will be addressed separately. Reviewed by: kib MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25392 Notes: svn path=/head/; revision=362941
* Rework linux accept(2). This makes the code flow easier to follow,Edward Tomasz Napierala2020-07-011-22/+31
| | | | | | | | | | | | | | | | | | | | | and fixes a bug where calling accept(2) could result in closing fd 0. Note that the code still contains a number of problems: it makes assumptions about l_sockaddr_in being the same as sockaddr_in, the EFAULT-related code looks like it doesn't work at all, and the socket type check is racy. Those will be addressed later on; I'm trying to work in small steps to avoid breaking one thing while fixing another. It fixes Redis, among other things. Reviewed by: kib MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25461 Notes: svn path=/head/; revision=362833
* Make linux(4) support SO_PROTOCOL. Running Python test suiteEdward Tomasz Napierala2020-06-281-0/+2
| | | | | | | | | | | with python3.8 from Focal triggers those. MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25491 Notes: svn path=/head/; revision=362735
* Make linux(4) warn about unsupported CMSG level/type.Edward Tomasz Napierala2020-06-141-1/+8
| | | | | | | | | MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25255 Notes: svn path=/head/; revision=362176
* Fix naming clash.Edward Tomasz Napierala2020-06-121-20/+21
| | | | | | | | MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=362103
* Minor code cleanup; no functional changes.Edward Tomasz Napierala2020-06-121-6/+3
| | | | | | | | | MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25232 Notes: svn path=/head/; revision=362101
* Make linux(4) handle SO_REUSEPORT.Edward Tomasz Napierala2020-06-111-0/+2
| | | | | | | | | | Reviewed by: emaste MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25216 Notes: svn path=/head/; revision=362051
* Support SO_SNDBUFFORCE/SO_RCVBUFFORCE by aliasing them to theEdward Tomasz Napierala2020-06-101-0/+2
| | | | | | | | | | | | standard SO_SNDBUF/SO_RCVBUF. Mostly cosmetics, to get rid of the warning during 'apt upgrade'. MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25173 Notes: svn path=/head/; revision=362014
* Make linuxulator warn about unsupported getsockopt/setsockopt flags.Edward Tomasz Napierala2020-02-271-3/+10
| | | | | | | | MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D23791 Notes: svn path=/head/; revision=358403
* Make linux(4) use kern_socketpair(9) instead of going throughEdward Tomasz Napierala2020-02-101-17/+17
| | | | | | | | | | | | sys_socketpair(). It's a cleanup; no functional changes. Reviewed by: kib MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D22814 Notes: svn path=/head/; revision=357727
* linuxulator: implement sendfileEd Maste2020-02-051-3/+136
| | | | | | | | | | | Submitted by: Bora Özarslan <borako.ozarslan@gmail.com> Submitted by: Yang Wang <2333@outlook.jp> Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D19917 Notes: svn path=/head/; revision=357577
* Add TCP_CORK support to linux(4). This fixes one of the things NginxEdward Tomasz Napierala2020-01-281-0/+2
| | | | | | | | | | | trips over. MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D23171 Notes: svn path=/head/; revision=357203
* Add compat.linux.ignore_ip_recverr sysctl. This is a workaroundEdward Tomasz Napierala2020-01-281-0/+9
| | | | | | | | | | | | | | | for missing IP_RECVERR setsockopt(2) support. Without it, DNS resolution is broken for glibc >= 2.30 (glibc BZ #24047). From the user point of view this fixes "yum update" on recent CentOS 8. MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D23234 Notes: svn path=/head/; revision=357202
* Make linux(4) use kern_setsockopt(9) instead of going throughEdward Tomasz Napierala2020-01-141-18/+7
| | | | | | | | | | | | sys_setsockopt. Just a cleanup; no functional changes. Reviewed by: kib MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D22812 Notes: svn path=/head/; revision=356729
* Make linux(4) use kern_getsockopt(9) instead of going throughEdward Tomasz Napierala2020-01-141-21/+18
| | | | | | | | | | | | sys_getsockopt(). It's a cleanup; no functional changes. Reviewed by: kib (earlier version) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D22813 Notes: svn path=/head/; revision=356728
* Complete LOCAL_PEERCRED support. Cache pid of the remote process in theDmitry Chagin2019-05-301-4/+1
| | | | | | | | | | | | struct xucred. Do not bump XUCRED_VERSION as struct layout is not changed. PR: 215202 Reviewed by: tijl MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D20415 Notes: svn path=/head/; revision=348419
* Linux does not support MSG_OOB for unix(4) or non-stream oriented socket,Dmitry Chagin2019-05-301-5/+25
| | | | | | | | | | | return EOPNOTSUPP as a Linux does. Reviewed by: tijl MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D20409 Notes: svn path=/head/; revision=348418
* Do not leak sa in linux_recvmsg() call if kern_recvit() fails.Dmitry Chagin2019-05-211-2/+3
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=348058
* Do not use uninitialised sa.Dmitry Chagin2019-05-211-1/+1
| | | | | | | | Reported by: tijl@ MFC after: 1 week Notes: svn path=/head/; revision=348057
* Do not leak sa in linux_recvfrom() call if kern_recvit() fails.Dmitry Chagin2019-05-211-2/+2
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=348056
* Linux send() call returns EAGAIN instead of ENOTCONN in case when theDmitry Chagin2019-05-191-1/+17
| | | | | | | | | | | | | socket is non-blocking and connect() is not finished yet. Initial patch developed by Steven Hartland in 2008 and adopted by me. PR: 129169 Reported by: smh@ MFC after: 2 weeks Notes: svn path=/head/; revision=347969
* Linuxulator getpeername() returns EINVAL in case then namelen less then 0.Dmitry Chagin2019-05-131-0/+2
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=347537
* Our bsd_to_linux_sockaddr() and linux_to_bsd_sockaddr() functionsDmitry Chagin2019-05-131-319/+174
| | | | | | | | | | | | | | | | | | | | | | alter the userspace sockaddr to convert the format between linux and BSD versions. That's the minimum 3 of copyin/copyout operations for one syscall. Also some syscall uses linux_sa_put() and linux_getsockaddr() when load sockaddr to userspace or from userspace accordingly. To avoid this chaos, especially converting sockaddr in the userspace, rewrite these 4 functions to convert sockaddr only in kernel and leave only 2 of this functions. Also in order to reduce duplication between MD parts of the Linuxulator put struct sockaddr conversion functions that are MI out into linux_common module. PR: 232920 MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D20157 Notes: svn path=/head/; revision=347533
* Specify the correct option level when emulating SO_PEERCRED.Mark Johnston2019-01-081-0/+5
| | | | | | | | | | | | Our equivalent to SO_PEERCRED, LOCAL_PEERCRED, is implemented at socket option level 0, not SOL_SOCKET. PR: 234722 Submitted by: Dániel Bakai <bakaidl@gmail.com> MFC after: 2 weeks Notes: svn path=/head/; revision=342864
* Fix another user address dereference in linux_sendmsg syscall.Tijl Coosemans2018-11-201-3/+14
| | | | | | | | | | | | | | This was hidden behind the LINUX_CMSG_NXTHDR macro which dereferences its second argument. Stop using the macro as well as LINUX_CMSG_FIRSTHDR. Use the size field of the kernel copy of the control message header to obtain the next control message. PR: 217901 MFC after: 2 days X-MFC-With: r340631 Notes: svn path=/head/; revision=340674
* Do proper copyin of control message data in the Linux sendmsg syscall.Tijl Coosemans2018-11-191-26/+28
| | | | | | | | | | | | | | | Instead of calling m_append with a user address, allocate an mbuf cluster and copy data into it using copyin. For the SCM_CREDS case, instead of zeroing a stack variable and appending that to the mbuf, zero part of the mbuf cluster directly. One mbuf cluster is also the size limit used by the FreeBSD sendmsg syscall (uipc_syscalls.c:sockargs()). PR: 217901 Reviewed by: kib MFC after: 3 days Notes: svn path=/head/; revision=340631
* Use declared types for caddr_t arguments.Brooks Davis2018-11-061-4/+5
| | | | | | | | | | | | Leave ptrace(2) alone for the moment as it's defined to take a caddr_t. Reviewed by: kib Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D17852 Notes: svn path=/head/; revision=340199
* Improve handling of control message truncation.Mark Johnston2018-08-071-16/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a recvmsg(2) or recvmmsg(2) caller doesn't provide sufficient space for all control messages, the kernel sets MSG_CTRUNC in the message flags to indicate truncation of the control messages. In the case of SCM_RIGHTS messages, however, we were failing to dispose of the rights that had already been externalized into the recipient's file descriptor table. Add a new function and mbuf type to handle this cleanup task, and use it any time we fail to copy control messages out to the recipient. To simplify cleanup, control message truncation is now only performed at control message boundaries. The change also fixes a few related bugs: - Rights could be leaked to the recipient process if an error occurred while copying out a message's contents. - We failed to set MSG_CTRUNC if the truncation occurred on a control message boundary, e.g., if the caller received two control messages and provided only the exact amount of buffer space needed for the first. PR: 131876 Reviewed by: ed (previous version) MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D16561 Notes: svn path=/head/; revision=337423
* Make timespecadd(3) and friends publicAlan Somers2018-07-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | The timespecadd(3) family of macros were imported from NetBSD back in r35029. However, they were initially guarded by #ifdef _KERNEL. In the meantime, we have grown at least 28 syscalls that use timespecs in some way, leading many programs both inside and outside of the base system to redefine those macros. It's better just to make the definitions public. Our kernel currently defines two-argument versions of timespecadd and timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define three-argument versions. Solaris also defines a three-argument version, but only in its kernel. This revision changes our definition to match the common three-argument version. Bump _FreeBSD_version due to the breaking KPI change. Discussed with: cem, jilles, ian, bde Differential Revision: https://reviews.freebsd.org/D14725 Notes: svn path=/head/; revision=336914
* Eliminate the overhead of gratuitous repeated reinitialization of cap_rightsMatt Macy2018-05-091-5/+2
| | | | | | | | | | | | | | | - Add macros to allow preinitialization of cap_rights_t. - Convert most commonly used code paths to use preinitialized cap_rights_t. A 3.6% speedup in fstat was measured with this change. Reported by: mjg Reviewed by: oshogbo Approved by: sbruno MFC after: 1 month Notes: svn path=/head/; revision=333425
* Correct proper nouns in the LinuxulatorEd Maste2018-02-221-1/+1
| | | | | | | | | | | - Capitalize Linux - Spell FreeBSD out in full - Address some style(9) on changed lines Sponsored by: Turing Robotic Industries Inc. Notes: svn path=/head/; revision=329794
* Rationalize license text on Linuxolator filesEd Maste2018-02-161-15/+13
| | | | | | | | | | | | | | | Many licenses on Linuxolator files contained small variations from the standard FreeBSD license text. To avoid license proliferation switch to the standard 2-clause FreeBSD license for those files where I have permission from each of the listed copyright holders. Additional files waiting on permission from others are listed in review D14210. Approved by: kan, marcel, sos, rdivacky MFC after: 1 week Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=329370
* Linuxolator whitespace cleanupEd Maste2018-02-051-2/+2
| | | | | | | | | | | | | A version of each of the MD files by necessity exists for each CPU architecture supported by the Linuxolator. Clean these up so that new architectures do not inherit whitespace issues. Clean up shared Linuxolator files while here. Sponsored by: Turing Robotic Industries Inc. Notes: svn path=/head/; revision=328890
* sys/compat: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326266
* As noted by Roel Bouwman Linux allows a large buffer size than theDmitry Chagin2017-03-181-1/+1
| | | | | | | | | | | struct ucred size. Fix this. PR: 102956 Reported by: Roel Bouwman <roel at qsp nl> MFC after: 1 week Notes: svn path=/head/; revision=315503
* Remove superflous break statment.Dmitry Chagin2017-03-181-3/+0
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=315499
* Style(9), some XXX comments fix. No functional changes.Dmitry Chagin2017-02-181-19/+17
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=313914
* Initialize cap_rights before use.Dmitry Chagin2017-02-181-1/+2
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=313913
* Finich r313684.Dmitry Chagin2017-02-181-8/+8
| | | | | | | | | | | | Convert linux_recv(), linux_send() and linux_accept() system call arguments to the register_t type too. PR: 217161 MFC after: 3 days xMFC with: r313284,r313285,r313684 Notes: svn path=/head/; revision=313912