summaryrefslogtreecommitdiff
path: root/sys/compat/linux/linux_socket.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix r313284.Dmitry Chagin2017-02-121-20/+26
| | | | | | | | | | | | Members of the syscall argument structures are padded to a word size. So, for COMPAT_LINUX32 we should convert user supplied system call arguments which is 32-bit in that case to the array of register_t. Reported by: Oleg V. Nauman MFC after: 1 week Notes: svn path=/head/; revision=313684
* Add kern_listen(), kern_shutdown(), and kern_socket(), and use themEdward Tomasz Napierala2017-01-301-31/+13
| | | | | | | | | | | | | instead of their sys_*() counterparts in various compats. The svr4 is left untouched, because there's no point. Reviewed by: ed@, kib@ MFC after: 2 weeks Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D9367 Notes: svn path=/head/; revision=312988
* Use getsock_cap() instead of fgetsock().Gleb Smirnoff2017-01-061-16/+16
| | | | | | | Reviewed by: dchagin Notes: svn path=/head/; revision=311474
* capsicum: propagate rights on accept(2)Mariusz Zaborski2016-09-221-1/+1
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=306174
* Fix a bug introduced in r283433.Dmitry Chagin2016-06-261-8/+6
| | | | | | | | | | | | | | | | | | [1] Remove unneeded sockaddr conversion before kern_recvit() call as the from argument is used to record result (the source address of the received message) only. [2] In Linux the type of msg_namelen member of struct msghdr is signed but native msg_namelen has a unsigned type (socklen_t). So use the proper storage to fetch fromlen from userspace and than check the user supplied value and return EINVAL if it is less than 0 as a Linux do. Reported by: Thomas Mueller <tmueller at sysgo dot com> [1] Reviewed by: kib@ Approved by: re (gjb, kib) MFC after: 3 days Notes: svn path=/head/; revision=302213
* Convert proto family in both directions. The linux and native values forDmitry Chagin2016-05-221-4/+12
| | | | | | | | | | | local and inet are identical, but for inet6 values differ. PR: 155040 Reported by: Simon Walton MFC after: 2 week Notes: svn path=/head/; revision=300431
* Add a missing errno translation for SO_ERROR optname.Dmitry Chagin2016-05-221-2/+11
| | | | | | | | | PR: 135458 Reported by: Stefan Schmidt @ stadtbuch.de MFC after: 1 week Notes: svn path=/head/; revision=300416
* kernel: use our nitems() macro when it is available through param.h.Pedro F. Giffuni2016-04-191-1/+1
| | | | | | | | | No functional change, only trivial cases are done in this sweep, Discussed in: freebsd-current Notes: svn path=/head/; revision=298310
* Revert r297310 as the SOL_XXX are equal to the IPPROTO_XX except SOL_SOCKET.Dmitry Chagin2016-03-271-2/+0
| | | | | | | Pointed out by: ae@ Notes: svn path=/head/; revision=297313
* iConvert Linux SOL_IPV6 level.Dmitry Chagin2016-03-271-0/+2
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=297310
* Whitespaces and style(9) fix. No functional changes.Dmitry Chagin2016-03-271-29/+11
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=297309
* Add support for IPPROTO_IPV6 socket layer for getsockopt/setsockopt calls.Andrey V. Elsukov2016-03-091-0/+63
| | | | | | | | | | | Also add mapping for several options from RFC 3493 and 3542. Reviewed by: dchagin Tested by: Joe Love <joe at getsomwhere dot net> MFC after: 2 weeks Notes: svn path=/head/; revision=296557
* Does not leak fp. While here remove bogus cast of fp->f_data.Dmitry Chagin2016-03-081-2/+5
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=296504
* Linux accept() system call return EOPNOTSUPP errno instead of EINVALDmitry Chagin2016-03-081-1/+12
| | | | | | | | | for UDP sockets. MFC after: 1 week Notes: svn path=/head/; revision=296503
* Prevent double free of control in common sendmsg path as sosendDmitry Chagin2016-01-171-0/+1
| | | | | | | already freeing it. Notes: svn path=/head/; revision=294233
* Properly initialize flags for accept4(2) not to return spurious EINVAL.Jung-uk Kim2015-06-081-0/+1
| | | | | | | | | Note this fixes a Linuxulator regression introduced in r283490. PR: 200662 Notes: svn path=/head/; revision=284166
* Convert SCM_TIMESTAMP in recvmsg().Dmitry Chagin2015-05-241-0/+16
| | | | Notes: svn path=/head/; revision=283497
* Fix an mbuf(9) leak in sendmsg() under failure condition andDmitry Chagin2015-05-241-2/+1
| | | | | | | | | | remove unneeded check for failed M_WAITOK allocation. Found by: Brainy Code Scanner Reported by: Maxime Villard Notes: svn path=/head/; revision=283494
* Since FreeBSD supports SOCK_CLOEXEC & SOCK_NONBLOCK optionsDmitry Chagin2015-05-241-69/+25
| | | | | | | remove its emulation via fcntl call from Linuxulator. Notes: svn path=/head/; revision=283490
* Implement recvmmsg() and sendmmsg() system calls.Dmitry Chagin2015-05-241-42/+159
| | | | Notes: svn path=/head/; revision=283488
* To avoid code duplication move open/fcntl definitions to the MIDmitry Chagin2015-05-241-0/+1
| | | | | | | | | | header file. Differential Revision: https://reviews.freebsd.org/D1087 Reviewed by: trasz Notes: svn path=/head/; revision=283437
* Rewrite linux_recvfrom. To avoid double conversion of sockaddr useDmitry Chagin2015-05-241-29/+37
| | | | | | | | | | kern_recvit() directly. And check fromlen parameter before sockaddr copyin and conversion. Differential Revision: https://reviews.freebsd.org/D1082 Notes: svn path=/head/; revision=283433
* Where possible we will use M_LINUX malloc(9) type.Dmitry Chagin2015-05-241-6/+6
| | | | | | | | | | Move M_FUTEX defines to the linux_common.ko. Differential Revision: https://reviews.freebsd.org/D1077 Reviewed by: emaste Notes: svn path=/head/; revision=283427
* Disable i386 call for x86-64 Linux.Dmitry Chagin2015-05-241-1/+2
| | | | | | | | Differential Revision: https://reviews.freebsd.org/D1067 Reviewed by: trasz Notes: svn path=/head/; revision=283415
* 64-bit paltforms, like x86_64, do not use multiplexing onDmitry Chagin2015-05-241-122/+19
| | | | | | | | | | socketcall system calls. Differential Revision: https://reviews.freebsd.org/D1065 Reviewed by: trasz Notes: svn path=/head/; revision=283413
* Fix Clang -Wpointer-sign warnings.Dmitry Chagin2015-01-011-2/+3
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=276512
* Remove the no-at variants of the kern_xx() syscall helpers. E.g., weKonstantin Belousov2014-11-131-2/+2
| | | | | | | | | | | | | | | have both kern_open() and kern_openat(); change the callers to use kern_openat(). This removes one (sometimes two) levels of indirection and consolidates arguments checks. Reviewed by: mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=274476
* Update kernel inclusions of capability.h to use capsicum.h instead; someRobert Watson2014-03-161-1/+1
| | | | | | | | | | | further refinement is required as some device drivers intended to be portable over FreeBSD versions rely on __FreeBSD_version to decide whether to include capability.h. MFC after: 3 weeks Notes: svn path=/head/; revision=263233
* Provide includes that are needed in these files, and before were readGleb Smirnoff2013-10-261-1/+1
| | | | | | | | | | in implicitly via if.h -> if_var.h pollution. Sponsored by: Netflix Sponsored by: Nginx, Inc. Notes: svn path=/head/; revision=257179
* Change the cap_rights_t type from uint64_t to a structure that we can extendPawel Jakub Dawidek2013-09-051-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in the future in a backward compatible (API and ABI) way. The cap_rights_t represents capability rights. We used to use one bit to represent one right, but we are running out of spare bits. Currently the new structure provides place for 114 rights (so 50 more than the previous cap_rights_t), but it is possible to grow the structure to hold at least 285 rights, although we can make it even larger if 285 rights won't be enough. The structure definition looks like this: struct cap_rights { uint64_t cr_rights[CAP_RIGHTS_VERSION + 2]; }; The initial CAP_RIGHTS_VERSION is 0. The top two bits in the first element of the cr_rights[] array contain total number of elements in the array - 2. This means if those two bits are equal to 0, we have 2 array elements. The top two bits in all remaining array elements should be 0. The next five bits in all array elements contain array index. Only one bit is used and bit position in this five-bits range defines array index. This means there can be at most five array elements in the future. To define new right the CAPRIGHT() macro must be used. The macro takes two arguments - an array index and a bit to set, eg. #define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL) We still support aliases that combine few rights, but the rights have to belong to the same array element, eg: #define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL) #define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL) #define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP) There is new API to manage the new cap_rights_t structure: cap_rights_t *cap_rights_init(cap_rights_t *rights, ...); void cap_rights_set(cap_rights_t *rights, ...); void cap_rights_clear(cap_rights_t *rights, ...); bool cap_rights_is_set(const cap_rights_t *rights, ...); bool cap_rights_is_valid(const cap_rights_t *rights); void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src); void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src); bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little); Capability rights to the cap_rights_init(), cap_rights_set(), cap_rights_clear() and cap_rights_is_set() functions are provided by separating them with commas, eg: cap_rights_t rights; cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT); There is no need to terminate the list of rights, as those functions are actually macros that take care of the termination, eg: #define cap_rights_set(rights, ...) \ __cap_rights_set((rights), __VA_ARGS__, 0ULL) void __cap_rights_set(cap_rights_t *rights, ...); Thanks to using one bit as an array index we can assert in those functions that there are no two rights belonging to different array elements provided together. For example this is illegal and will be detected, because CAP_LOOKUP belongs to element 0 and CAP_PDKILL to element 1: cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL); Providing several rights that belongs to the same array's element this way is correct, but is not advised. It should only be used for aliases definition. This commit also breaks compatibility with some existing Capsicum system calls, but I see no other way to do that. This should be fine as Capsicum is still experimental and this change is not going to 9.x. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=255219
* Remove check for NULL prior to free(9) and m_freem(9).Eitan Adler2013-03-041-4/+2
| | | | | | | Approved by: cperciva (mentor) Notes: svn path=/head/; revision=247764
* Don't assume that all Linux TCP-level socket options are identical toJohn Baldwin2013-01-231-4/+24
| | | | | | | | | | | FreeBSD TCP-level socket options (only the first two are). Instead, using a mapping function and fail unsupported options as we do for other socket option levels. MFC after: 2 weeks Notes: svn path=/head/; revision=245849
* Mechanically substitute flags from historic mbuf allocator withGleb Smirnoff2012-12-051-1/+1
| | | | | | | | | | | | malloc(9) flags within sys. Exceptions: - sys/contrib not touched - sys/mbuf.h edited manually Notes: svn path=/head/; revision=243882
* Convert files to UTF-8Ulrich Spörlein2012-01-151-1/+1
| | | | Notes: svn path=/head/; revision=230132
* Use the caculated length instead of maximum length.Jung-uk Kim2011-10-061-2/+2
| | | | Notes: svn path=/head/; revision=226079
* Remove a now-defunct variable.Jung-uk Kim2011-10-061-16/+15
| | | | Notes: svn path=/head/; revision=226078
* Use uint32_t instead of u_int32_t. Fix style(9) nits.Jung-uk Kim2011-10-061-10/+9
| | | | Notes: svn path=/head/; revision=226074
* Make sure to ignore the leading NULL byte from Linux abstract namespace.Jung-uk Kim2011-10-061-2/+10
| | | | Notes: svn path=/head/; revision=226073
* Restore the original socket address length if it was not really AF_INET6.Jung-uk Kim2011-10-061-16/+19
| | | | Notes: svn path=/head/; revision=226072
* Retern more appropriate errno when Linux path name is too long.Jung-uk Kim2011-10-061-1/+1
| | | | Notes: svn path=/head/; revision=226071
* Inline do_sa_get() function and remove an unused return value.Jung-uk Kim2011-10-061-23/+9
| | | | Notes: svn path=/head/; revision=226069
* Unroll inlined strnlen(9) and make it easier to read. No functional change.Jung-uk Kim2011-10-061-10/+6
| | | | Notes: svn path=/head/; revision=226068
* Fix a bug in UNIX socket handling in the linux emulator which wasColin Percival2011-10-041-0/+15
| | | | | | | | | | | | exposed by the security fix in FreeBSD-SA-11:05.unix. Approved by: so (cperciva) Approved by: re (kib) Security: Related to FreeBSD-SA-11:05.unix, but not actually a security fix. Notes: svn path=/head/; revision=226023
* In order to maximize the re-usability of kernel code in user space thisKip Macy2011-09-161-13/+13
| | | | | | | | | | | | | | | | patch modifies makesyscalls.sh to prefix all of the non-compatibility calls (e.g. not linux_, freebsd32_) with sys_ and updates the kernel entry points and all places in the code that use them. It also fixes an additional name space collision between the kernel function psignal and the libc function of the same name by renaming the kernel psignal kern_psignal(). By introducing this change now we will ease future MFCs that change syscalls. Reviewed by: rwatson Approved by: re (bz) Notes: svn path=/head/; revision=225617
* Second-to-last commit implementing Capsicum capabilities in the FreeBSDRobert Watson2011-08-111-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | kernel for FreeBSD 9.0: Add a new capability mask argument to fget(9) and friends, allowing system call code to declare what capabilities are required when an integer file descriptor is converted into an in-kernel struct file *. With options CAPABILITIES compiled into the kernel, this enforces capability protection; without, this change is effectively a no-op. Some cases require special handling, such as mmap(2), which must preserve information about the maximum rights at the time of mapping in the memory map so that they can later be enforced in mprotect(2) -- this is done by narrowing the rights in the existing max_protection field used for similar purposes with file permissions. In namei(9), we assert that the code is not reached from within capability mode, as we're not yet ready to enforce namespace capabilities there. This will follow in a later commit. Update two capability names: CAP_EVENT and CAP_KEVENT become CAP_POST_KEVENT and CAP_POLL_KEVENT to more accurately indicate what they represent. Approved by: re (bz) Submitted by: jonathan Sponsored by: Google Inc Notes: svn path=/head/; revision=224778
* Revert r220032:linux compat: add SO_PASSCRED option with basic handlingAndriy Gapon2011-03-311-14/+0
| | | | | | | | | | | | | I have not properly thought through the commit. After r220031 (linux compat: improve and fix sendmsg/recvmsg compatibility) the basic handling for SO_PASSCRED is not sufficient as it breaks recvmsg functionality for SCM_CREDS messages because now we would need to handle sockcred data in addition to cmsgcred. And that is not implemented yet. Pointyhat to: avg Notes: svn path=/head/; revision=220186
* linux compat: add SO_PASSCRED option with basic handlingAndriy Gapon2011-03-261-0/+14
| | | | | | | | | | | This seems to have been a part of a bigger patch by dchagin that either haven't been committed or committed partially. Submitted by: dchagin, nox MFC after: 2 weeks Notes: svn path=/head/; revision=220032
* linux compat: improve and fix sendmsg/recvmsg compatibilityAndriy Gapon2011-03-261-51/+137
| | | | | | | | | | | | | | | | | | | | - implement baseic stubs for capget, capset, prctl PR_GET_KEEPCAPS and prctl PR_SET_KEEPCAPS. - add SCM_CREDS support to sendmsg and recvmsg - modify sendmsg to ignore control messages if not using UNIX domain sockets This should allow linux pulse audio daemon and client work on FreeBSD and interoperate with native counter-parts modulo the differences in pulseaudio versions. PR: kern/149168 Submitted by: John Wehle <john@feith.com> Reviewed by: netchild MFC after: 2 weeks Notes: svn path=/head/; revision=220031
* - Return EAFNOSUPPORT instead of EINVAL for unsupported address family,Xin LI2010-02-091-2/+7
| | | | | | | | | | | | | | | this matches the Linux behavior. - Check if we have sufficient space allocated for socket structure, which fixes a buffer overflow when wrong length is being passed into the emulation layer. [1] PR: kern/138860 Submitted by: Mateusz Guzik <mjguzik gmail com> Reported by: Alexander Best [1] MFC after: 2 weeks Notes: svn path=/head/; revision=203728
* Unconditionally call the setsockopt for IPV6_V6ONLY for v6 linux socketsBjoern A. Zeeb2009-10-251-12/+5
| | | | | | | | | | | | | | | | no matter whether we are compiled as module or if our default of the net.inet6.ip6.v6only sysctl already matches what we would set. This avoids unnecessary complications with modules, VIMAGES, INET6 and the sysctl value, especially considering that most users will use linux compat as a module. Discussed with: kib, rwatson (weeks ago) Reviewed by: rwatson MFC after: 6 weeks Notes: svn path=/head/; revision=198467