aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linux
Commit message (Collapse)AuthorAgeFilesLines
* linux(4): Prevent integer overflow in futex_requeue.Dmitry Chagin2021-06-291-7/+16
| | | | | | | | | | | To prevent a signed integer overflow in futex_requeue add a sanity check to catch negative values of nrwake or nrrequeue. Approved by: so Security: EN-21:22.linux_futex (cherry picked from commit 25b09d6f398ea8a260ee8e2e8209fd76c61e13ee) (cherry picked from commit 43a58daffe7256f0948ce895fed9fae55dec98fc)
* MFC r363304:Edward Tomasz Napierala2020-09-011-0/+14
| | | | | | | | | | | Add a trivial linux(4) splice(2) implementation, which simply returns EINVAL. Fixes grep (grep-3.1-2build1). PR: 218699 Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=365034
* MFC r364346:Mark Johnston2020-08-251-1/+2
| | | | | | | Fix handling of ancillary data on non-AF_UNIX Linux sockets. Notes: svn path=/stable/12/; revision=364743
* MFC r362631, r364317:Mark Johnston2020-08-241-1/+103
| | | | | | | | | Implement an approximation of Linux MADV_DONTNEED semantics. PR: 230160 Notes: svn path=/stable/12/; revision=364729
* MFC r363087:Edward Tomasz Napierala2020-08-241-0/+6
| | | | | | | | | Don't emit warnings on MADV_HUGEPAGE; Firefox uses it a lot. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364717
* MFC r362440:Edward Tomasz Napierala2020-08-242-0/+77
| | | | | | | | | | | | Add linux_madvise(2) instead of having Linux apps call the native FreeBSD madvise(2) directly. While some of the flag values match, most don't. PR: kern/230160 Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364715
* MFC r347538 by dchagin:Edward Tomasz Napierala2020-08-248-790/+7
| | | | | | | | | | | | | | | | | | | | Linuxulator depends on a fundamental kernel settings such as SMP. Many of them listed in opt_global.h which is not generated while building modules outside of a kernel and such modules never match real cofigured kernel. So, we should prevent our users from building obviously defective modules. Therefore, remove the root cause of the building of modules outside of a kernel - the possibility of building modules with DEBUG or KTR flags. And remove all of DEBUG printfs as it is incomplete and in threaded programms not informative, also a half of system call does not have DEBUG printf. For debuging Linux programms we have dtrace, ktr and ktrace ability. PR: 222861 Notes: svn path=/stable/12/; revision=364712
* MFC r362101:Edward Tomasz Napierala2020-08-242-12/+3
| | | | | | | | | Minor code cleanup; no functional changes. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364710
* MFC r356729:Edward Tomasz Napierala2020-08-241-18/+7
| | | | | | | | | | Make linux(4) use kern_setsockopt(9) instead of going through sys_setsockopt. Just a cleanup; no functional changes. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364709
* MFC r356728:Edward Tomasz Napierala2020-08-241-21/+18
| | | | | | | | | | Make linux(4) use kern_getsockopt(9) instead of going through sys_getsockopt(). It's a cleanup; no functional changes. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364708
* MFC r362941:Edward Tomasz Napierala2020-08-241-3/+9
| | | | | | | | | | | | | | | | Fix Linux recvmsg(2) when msg_namelen returned is 0. Previously 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. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364707
* MFC r362833:Edward Tomasz Napierala2020-08-241-22/+31
| | | | | | | | | | | | | | | | | | | Rework linux accept(2). This makes the code flow easier to follow, 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. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364706
* MFC r362735:Edward Tomasz Napierala2020-08-242-0/+3
| | | | | | | | | | Make linux(4) support SO_PROTOCOL. Running Python test suite with python3.8 from Focal triggers those. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364705
* MFC r362176:Edward Tomasz Napierala2020-08-241-1/+8
| | | | | | | | | Make linux(4) warn about unsupported CMSG level/type. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364704
* MFC r362059:Edward Tomasz Napierala2020-08-243-3/+3
| | | | | | | | | Don't use newlines with linux_msg(). No functional changes. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364703
* MFC r354413:Edward Tomasz Napierala2020-08-243-0/+32
| | | | | | | | | | | Make linux(4) create /dev/shm. Linux applications often expect a tmpfs to be mounted there, and because they like to verify it's actually a mountpoint, a symlink won't do. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364702
* MFC r362103:Edward Tomasz Napierala2020-08-241-20/+21
| | | | | | | | | Fix naming clash. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364700
* MFC r348418 by dchagin:Edward Tomasz Napierala2020-08-241-5/+25
| | | | | | | | Linux does not support MSG_OOB for unix(4) or non-stream oriented socket, return EOPNOTSUPP as a Linux does. Notes: svn path=/stable/12/; revision=364699
* MFC r348058 by dchagin:Edward Tomasz Napierala2020-08-241-2/+3
| | | | | | | Do not leak sa in linux_recvmsg() call if kern_recvit() fails. Notes: svn path=/stable/12/; revision=364698
* MFC r348057 by dchagin:Edward Tomasz Napierala2020-08-241-1/+1
| | | | | | | Do not use uninitialised sa. Notes: svn path=/stable/12/; revision=364697
* MFC r348056 by dchagin:Edward Tomasz Napierala2020-08-241-2/+2
| | | | | | | Do not leak sa in linux_recvfrom() call if kern_recvit() fails. Notes: svn path=/stable/12/; revision=364696
* MFC r347969 by dchagin:Edward Tomasz Napierala2020-08-241-1/+17
| | | | | | | | | | | | Linux send() call returns EAGAIN instead of ENOTCONN in case when the socket is non-blocking and connect() is not finished yet. Initial patch developed by Steven Hartland in 2008 and adopted by me. PR: 129169 Notes: svn path=/stable/12/; revision=364695
* MFC r347537 by dchagin:Edward Tomasz Napierala2020-08-241-0/+2
| | | | | | | Linuxulator getpeername() returns EINVAL in case then namelen less then 0. Notes: svn path=/stable/12/; revision=364694
* MFC r347533 by dchagin:Edward Tomasz Napierala2020-08-245-328/+390
| | | | | | | | | | | | | | | | | | | | | Our bsd_to_linux_sockaddr() and linux_to_bsd_sockaddr() functions 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 Notes: svn path=/stable/12/; revision=364693
* MFC r363307:Edward Tomasz Napierala2020-08-241-1/+1
| | | | | | | | | | Make linux fallocate(2) return EOPNOTSUPP, not ENOSYS, on unsupported mode, as documented in the man page. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364692
* MFC r363125 by netchild:Edward Tomasz Napierala2020-08-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement CLOCK_MONOTONIC_RAW (linux >= 2.6.28). It is documented as a raw hardware-based clock not subject to NTP or incremental adjustments. With this "not as precise as CLOCK_MONOTONIC" description in mind, map it to our CLOCK_MONOTNIC_FAST (the same mapping as for the linux CLOCK_MONOTONIC_COARSE). This is needed for the webcomponent of steam (chromium) and some other steam component or game. The linux-steam-utils port contains a LD_PRELOAD based fix for this. There this is mapped to CLOCK_MONOTONIC. As an untrained ear/eye (= the majority of people) is normaly not noticing a difference of jitter in the 10-20 ms range, specially if you don't pay attention like for example in a browser session while watching a video stream, the mapping to CLOCK_MONOTONIC_FAST seems more appropriate than to CLOCK_MONOTONIC. MFC r363130 by netchild: Fix r363125 (Implement CLOCK_MONOTONIC_RAW (linux >= 2.6.28)), by realy using the MONOTONIC version and not the REALTIME version. Notes: svn path=/stable/12/; revision=364691
* MFC r362416:Edward Tomasz Napierala2020-08-241-0/+9
| | | | | | | | | Add warnings for unsupported Linux clockids. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364690
* MFC r357493 by dchagin:Edward Tomasz Napierala2020-08-241-35/+62
| | | | | | | | | | | | | | | Fix clock_gettime() and clock_getres() for cpu clocks: - handle the CLOCK_{PROCESS,THREAD}_CPUTIME_ID specified directly; - fix thread id calculation as in the Linuxulator we should convert the user supplied thread id to struct thread * by linux_tdfind(); - fix CPUCLOCK_SCHED case by using kern_{process,thread}_cputime() directly as native get_cputime() used by kern_clock_gettime() uses native tdfind()/pfind() to find proccess/thread. PR: 240990 Notes: svn path=/stable/12/; revision=364689
* MFC r357491 by dchagin:Edward Tomasz Napierala2020-08-241-3/+3
| | | | | | | | linux_to_native_clockid() properly initializes nwhich variable (or return error), so don't initialize nwhich in declaration and remove stale comment from r161304. Notes: svn path=/stable/12/; revision=364687
* MFC r356727:Edward Tomasz Napierala2020-08-241-1/+1
| | | | | | | | | | Make linux getcpu(2) report the domain. Submitted by: markj Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364686
* MFC r354805:Edward Tomasz Napierala2020-08-241-1/+4
| | | | | | | | | | Make linux(4) open(2)/openat(2) return ELOOP instead of EMLINK, when being passed O_NOFOLLOW. This fixes LTP testcase openat02:5. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364685
* MFC r362055:Edward Tomasz Napierala2020-08-242-4/+4
| | | | | | | | | Replace LINUX_FASYNC with LINUX_O_ASYNC; no functional changes. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364683
* MFC r364329:Mark Johnston2020-08-241-5/+3
| | | | | | | Remove "emulation" of clone(CLONE_PARENT | CLONE_THREAD). Notes: svn path=/stable/12/; revision=364680
* MFC r364328:Mark Johnston2020-08-241-0/+1
| | | | | | | Fix a lock leak when emulating futex(FUTEX_WAIT_BITSET). Notes: svn path=/stable/12/; revision=364679
* MFC r354732:Edward Tomasz Napierala2020-08-241-0/+2
| | | | | | | | | Support O_CLOEXEC in linux(4) open(2) and openat(2). Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364677
* MFC r349750:Edward Tomasz Napierala2020-08-242-0/+2
| | | | | | | | | | | | Return ENOTSUP for Linux FS_IOC_FIEMAP ioctl. Linux man(1) calls it for no good reason; this avoids the console spam (eg '(man): ioctl fd=4, cmd=0x660b ('f',11) is not implemented'). Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364670
* MFC r349746:Edward Tomasz Napierala2020-08-241-4/+8
| | | | | | | | | | | Fix linuxulator prlimit64(2) with pid == 0. This makes 'ulimit -a' return something reasonable, and helps linux binaries which attempt to close all the files, eg apt(8). Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364669
* MFC r362205:Edward Tomasz Napierala2020-08-241-0/+10
| | | | | | | | | | | Make Linux uname(2) return x86_64 to 32-bit apps. This helps Steam. PR: kern/240432 Analyzed by: Alex S <iwtcex@gmail.com> Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364668
* MFC r362104:Edward Tomasz Napierala2020-08-243-0/+8
| | | | | | | | | | Add compat.linux.debug sysctl, to make it possible to silence down the debug messages. While here, clean up some variable naming. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364667
* MFC r362015:Edward Tomasz Napierala2020-08-243-0/+36
| | | | | | | | | | | Make linux(4) set the openfiles soft resource limit to 1024 for Linux applications, which often depend on this being the case. There's a new sysctl, compat.linux.default_openfiles, to control this behaviour. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364666
* MFC r358673 by tijl:Edward Tomasz Napierala2020-08-243-10/+11
| | | | | | | | | | | Move compat.linux.map_sched_prio sysctl definition to linux_mib.c so it is only defined by linux_common kernel module and not both linux and linux64 modules. Reported by: Yuri Pankov <ypankov@fastmail.com> Notes: svn path=/stable/12/; revision=364665
* MFC r358483 by tijl:Edward Tomasz Napierala2020-08-242-7/+130
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | linuxulator: Map scheduler priorities to Linux priorities. On Linux the valid range of priorities for the SCHED_FIFO and SCHED_RR scheduling policies is [1,99]. For SCHED_OTHER the single valid priority is 0. On FreeBSD it is [0,31] for all policies. Programs are supposed to query the valid range using sched_get_priority_(min|max), but of course some programs assume the Linux values are valid. This commit adds a tunable compat.linux.map_sched_prio. When enabled sched_get_priority_(min|max) return the Linux values and sched_setscheduler and sched_(get|set)param translate between FreeBSD and Linux values. Because there are more Linux levels than FreeBSD levels, multiple Linux levels map to a single FreeBSD level, which means pre-emption might not happen as it does on Linux, so the tunable allows to disable this behaviour. It is enabled by default because I think it is unlikely that anyone runs real-time software under Linux emulation on FreeBSD that critically relies on correct pre-emption. This fixes FMOD, a commercial sound library used by several games. PR: 240043 Tested by: Alex S <iwtcex@gmail.com> Notes: svn path=/stable/12/; revision=364664
* MFC r357202:Edward Tomasz Napierala2020-08-244-0/+15
| | | | | | | | | | | | | | Add compat.linux.ignore_ip_recverr sysctl. This is a workaround 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. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364663
* MFC r355820:Edward Tomasz Napierala2020-08-244-0/+11
| | | | | | | | | | Add a hack to make ^T work for Linux binaries, enabled with 'compat.linux.preserve_vstatus=1' sysctl. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364662
* MFC r362051:Edward Tomasz Napierala2020-08-242-0/+3
| | | | | | | | | Make linux(4) handle SO_REUSEPORT. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364661
* MFC r357203:Edward Tomasz Napierala2020-08-242-0/+3
| | | | | | | | | | Add TCP_CORK support to linux(4). This fixes one of the things Nginx trips over. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364660
* MFC r357076:Edward Tomasz Napierala2020-08-242-1/+9
| | | | | | | | | | | | Make linux(4) handle MAP_32BIT. This unbreaks Mono (mono-devel-4.6.2.7+dfsg-1ubuntu1 from Ubuntu Bionic); previously would crash on "amd64_is_imm32" assert. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364659
* MFC r362014:Edward Tomasz Napierala2020-08-242-0/+4
| | | | | | | | | | | Support SO_SNDBUFFORCE/SO_RCVBUFFORCE by aliasing them to the standard SO_SNDBUF/SO_RCVBUF. Mostly cosmetics, to get rid of the warning during 'apt upgrade'. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364658
* MFC r363322:Edward Tomasz Napierala2020-08-242-3/+25
| | | | | | | | | Make linux(4) support the BLKPBSZGET ioctl. Oracle uses it. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364657
* MFC r356170:Edward Tomasz Napierala2020-08-232-1/+12
| | | | | | | | | Implement Linux BLKGETSIZE64 ioctl. Sponsored by: The FreeBSD Foundation Notes: svn path=/stable/12/; revision=364581