Commit graph

1510 commits

Author SHA1 Message Date
Dmitry Chagin
dfbeda6cf4 linux(4): Fix SO_LINGER l_onoff value
On Linux l_onoff should be 1 when linger is used.

MFC after:		2 weeks

(cherry picked from commit e8d9d8082b)
2022-06-17 22:35:32 +03:00
Dmitry Chagin
d573cf010e linux(4): Add a helper to copyout getsockopt value
For getsockopt(), optlen is a value-result argument, which is modified
on return to indicate the actual size of the value returned.
For some cases this was missed, fixed.

MFC after:		2 weeks

(cherry picked from commit e92b9a9eaa)
2022-06-17 22:35:32 +03:00
Dmitry Chagin
ccdf2cd423 linux(4): Check the socket before any others sanity checks
Strictly speaking, this check is performed by the kern_recvit(), but in
the Linux emulation layer before calling the kernel we do other sanity
checks and conversions from Linux types to the native types. This changes
an order of the error returning that is critical for some buggy Linux
applications.

For recvmmsg() syscall this fixes a panic in case when the user-supplied
vlen value is 0, then error is not initialized and garbage passed to the
bsd_to_linux_errno().

MFC after:		2 weeks

(cherry picked from commit 3a99aac66f)
2022-06-17 22:35:32 +03:00
Dmitry Chagin
089a76e915 Finish cpuset_getaffinity() after f35093f8
Split cpuset_getaffinity() into a two counterparts, where the
user_cpuset_getaffinity() is intended to operate on the cpuset_t from
user va, while kern_cpuset_getaffinity() expects the cpuset from kernel
va.
Accordingly, the code that clears the high bits is moved to the
user_cpuset_getaffinity(). Linux sched_getaffinity() syscall returns
the size of set copied to the user-space and then glibc wrapper clears
the high bits.

MFC after:		2 weeks

(cherry picked from commit d46174cd88)
2022-06-17 22:35:31 +03:00
Dmitry Chagin
d63a4afcdf linux(4): Fix unlinkat() after a125ed50
MFC after:		2 weeks

(cherry picked from commit 1bb3faed29)
2022-06-17 22:35:30 +03:00
Dmitry Chagin
959d0bdc24 linux(4): Deduplicate execve
As linux_execve is common across archs, except amd64 32-bit Linuxulator,
move it under compat/linux.

Noted by:               andrew@
MFC after:              2 weeks

(cherry picked from commit 26700ac0c4)
2022-06-17 22:35:30 +03:00
Dmitry Chagin
264df06b36 linux(4): Fix unlink() after a125ed50
MFC after:		2 weeks

(cherry picked from commit e0aef0d62d)
2022-06-17 22:35:29 +03:00
Dmitry Chagin
3dfc1fc1b3 linux(4): To improve readability use FUTEX_UNOWNED instead of 0
MFC after:		2 weeks

(cherry picked from commit b04f5d18b5)
2022-06-17 22:35:27 +03:00
Dmitry Chagin
f78fd02243 linux(4): Convert the native kernel signal codes into the Linux codes
MFC after:		2 weeks

(cherry picked from commit a6f85b12bb)
2022-06-17 22:35:26 +03:00
Dmitry Chagin
8d6ce30149 linux(4): Add kernel signal code definitions
In the next commit I'll convert the native signal codes into the Linux codes,
since they are not 1:1 mapped.

MFC after:		2 weeks

(cherry picked from commit 3030197563)
2022-06-17 22:35:26 +03:00
Dmitry Chagin
ecb5287bae linux(4): Move signal codes definitions to the appropriate header
In the Linux the struct siginfo related bits are placed into the siginfo.h
header.

MFC after:		2 weeks

(cherry picked from commit 9386e18b39)
2022-06-17 22:35:26 +03:00
Dmitry Chagin
ba77290cce linux(4): Handle cas failure on ll/sc operations
Follow the 11a6ecd4. Check and handle the case when the ll/sc casu fails
even when the compare succeeds.

For more details PR/263825, https://reviews.freebsd.org/D35150.

Obtained from:		Andrew@
MFC after:		2 weeks

(cherry picked from commit 2cd662064a)
2022-06-17 22:35:25 +03:00
Dmitry Chagin
d30b87879b linux(4): Add AT_MINSIGSTKSZ to arm64 port
MFC after:	2 weeks

(cherry picked from commit 390c9ea029)
2022-06-17 22:35:23 +03:00
Dmitry Chagin
43dbc72cc5 linux(4): Rework the definition of struct siginfo to match Linux actual one
Rework the defintion of struct siginfo so that the array padding
struct siginfo to SI_MAX_SIZE can be placed in a union along side of the
rest of the struct siginfo members.  The result is that we no longer need
the __ARCH_SI_PREAMBLE_SIZE or SI_PAD_SIZE definitions.

Move struct siginfo definition under /compat/linux to reduce MD part.
To avoid headers polution include linux_siginfo.h in the MD linux.h

MFC after:		2 weeks

(cherry picked from commit af557e649c)
2022-06-17 22:35:20 +03:00
Dmitry Chagin
0e89b88d1c linux(4): Revert c7ef7c3 as it's wrong at all.
Reported by:		trasz

(cherry picked from commit 5326ebfd05)
2022-06-17 22:35:15 +03:00
Dmitry Chagin
72bc1e6806 cpuset: Byte swap cpuset for compat32 on big endian architectures
Summary:
BITSET uses long as its basic underlying type, which is dependent on the
compile type, meaning on 32-bit builds the basic type is 32 bits, but on
64-bit builds it's 64 bits.  On little endian architectures this doesn't
matter, because the LSB is always at the low bit, so the words get
effectively concatenated moving between 32-bit and 64-bit, but on
big-endian architectures it throws a wrench in, as setting bit 0 in
32-bit mode is equivalent to setting bit 32 in 64-bit mode.  To
demonstrate:

32-bit mode:

BIT_SET(foo, 0):        0x00000001

64-bit sees: 0x0000000100000000

cpuset is the only system interface that uses bitsets, so solve this
by swapping the integer sub-components at the copyin/copyout points.

Reviewed by:    kib
Sponsored by:   Juniper Networks, Inc.
Differential Revision:  https://reviews.freebsd.org/D35225

(cherry picked from commit 47a57144af)

Fix the build after 47a57144

(cherry picked from commit 89737eb829)

cpuset: Fix the KASAN and KMSAN builds

Rename the "copyin" and "copyout" fields of struct cpuset_copy_cb to
something less generic, since sanitizers define interceptors for
copyin() and copyout() using #define.

Reported by:    syzbot+2db5d644097fc698fb6f@syzkaller.appspotmail.com
Fixes:  47a57144af ("cpuset: Byte swap cpuset for compat32 on big endian architectures")
Sponsored by:   The FreeBSD Foundation

(cherry picked from commit 4a3e51335e)

Use Linux semantics for the thread affinity syscalls.

Linux has more tolerant checks of the user supplied cpuset_t's.

Minimum cpuset_t size that the Linux kernel permits in case of
getaffinity() is the maximum CPU id, present in the system / NBBY,
the maximum size is not limited.
For setaffinity(), Linux does not limit the size of the user-provided
cpuset_t, internally using only the meaningful part of the set, where
the upper bound is the maximum CPU id, present in the system, no larger
than the size of the kernel cpuset_t.
Unlike FreeBSD, Linux ignores high bits if set in the setaffinity(),
so clear it in the sched_setaffinity() and Linuxulator itself.

Reviewed by:            Pau Amma (man pages)
In collaboration with:  jhb
Differential revision:  https://reviews.freebsd.org/D34849
MFC after:              2 weeks

(cherry picked from commit f35093f8d6)
2022-06-17 22:35:14 +03:00
Dmitry Chagin
7b0e7f785e linux(4); Style.
MFC after:		2 weeks

(cherry picked from commit 109c2bd212)
2022-06-17 22:35:07 +03:00
Dmitry Chagin
d9c17939f0 linux(4): Return native error from futex_atomic_op to avoid conversion by the caller.
MFC after:		2 weeks

(cherry picked from commit 07d108932a)
2022-06-17 22:35:06 +03:00
Dmitry Chagin
800b5aafa3 linux(4): Fixed offset miscalculation in the preadv/pwritev syscalls.
MFC after:		2 weeks

(cherry picked from commit b17446281d)
2022-06-17 22:35:06 +03:00
Dmitry Chagin
9ba35540f4 linux(4): The futex_wait operation should restart.
It's ok from the futex_wait perspective as umtxq_sleep method uses
absolute sleep timeout.

MFC after:		2 weeks

(cherry picked from commit 5eec19c8eb)
2022-06-17 22:35:01 +03:00
Dmitry Chagin
12b9d651a8 linux(4): Use the right function to get the bit index in vdso binuptime.
This is modeled after a1f93266 (by kib@).

MFC after:		2 weeks

(cherry picked from commit c6df217603)
2022-06-17 22:35:00 +03:00
Dmitry Chagin
e7a07ad1db linux(4): Implement vdso getcpu for x86.
This is modeled after f2395455 (by kib@).

MFC after:		2 weeks

(cherry picked from commit 5a6a4fb284)
2022-06-17 22:35:00 +03:00
Dmitry Chagin
573a0f3e68 linux(4): Add a helper intended for copying timespec's from the userspace.
There are many places where we copyin Linux timespec from the userspace
and then convert it to the kernel timespec. To avoid code duplication
add a tiny halper for doing this.

MFC after:		2 weeks

(cherry picked from commit 707e567a40)
2022-06-17 22:34:59 +03:00
Dmitry Chagin
34f633b6a7 linux(4): Prevent time_t overflows on i386.
As native i386 time_t is still 32-bit, check that the user-provided 64-bit
tv_sec value fits to the kernel time_t, return EOVERFLOW if not.

MFC after:		2 weeks

(cherry picked from commit 3dc2a06752)
2022-06-17 22:34:59 +03:00
Dmitry Chagin
c0584b324e linux(4): Zero out high order bits of nanoseconds in the compat mode.
Assuming the kernel would use random data, the 64-bit Linux kernel ignores
upper 32 bits of tv_nsec of struct timespec64 for 32-bit binaries.

MFC after:		2 weeks

(cherry picked from commit 1579b320f1)
2022-06-17 22:34:58 +03:00
Dmitry Chagin
5a37b53f16 linux(4): Add a helper intended for copying timespec's to the userspace.
There are many places where we convert natvie timespec and copyout it to
the userspace. To avoid code duplication add a tiny halper for doing this.

MFC after:		2 weeks

(cherry picked from commit 9a9482f874)
2022-06-17 22:34:58 +03:00
Dmitry Chagin
9fd86dde83 linux(4): Implement semtimedop syscalls.
On i386 are two semtimedop. The old one is called via multiplexor and
uses 32-bit timespec, and new semtimedop_tim64, which is uses 64-bit
timespec.

MFC after:		2 weeks

(cherry picked from commit 3245a2ecea)
2022-06-17 22:34:53 +03:00
Dmitry Chagin
d5316587f0 linux(4): Retire linux_semop implementation.
In i386 Linux semop called via ipc() multiplexor, so use kern_semop
directly from multiplexor.

MFC after:		2 weeks

(cherry picked from commit f48a68874b)
2022-06-17 22:34:47 +03:00
Dmitry Chagin
3f8eb6f28b linux(4): Implement recvmmsg_time64 syscall.
MFC after:		2 weeks

(cherry picked from commit 1744f14e26)
2022-06-17 22:34:42 +03:00
Dmitry Chagin
d32db5360b linux(4): Implement timerfd_gettime64 syscall.
MFC after:		2 weeks

(cherry picked from commit ce9f8d6ab0)
2022-06-17 22:34:37 +03:00
Dmitry Chagin
eea4b5db71 linux(4): Implement timerfd_settime64 syscall.
MFC after:		2weeks

(cherry picked from commit b1f0b08d93)
2022-06-17 22:34:31 +03:00
Dmitry Chagin
ad5e9b9867 linux(4): Implement timer_settime64 syscall.
MFC after:		2 weeks

(cherry picked from commit a1fd2911dd)
2022-06-17 22:34:26 +03:00
Dmitry Chagin
da266f693c linux(4): Implement timer_gettime64 syscall.
MFC after:		2 weeks

(cherry picked from commit 783c1bd8cb)
2022-06-17 22:34:21 +03:00
Dmitry Chagin
b2f336bb73 linux(4): Implement sched_rr_get_interval_time64 syscall.
MFC after:		2 weeks

(cherry picked from commit 8c84ca657b)
2022-06-17 22:34:15 +03:00
Dmitry Chagin
9d4b1eba0e linux(4): Add epoll_pwai2 syscall.
MFC after:	2 weeks

(cherry picked from commit e00aad1042)
2022-06-17 22:34:10 +03:00
Dmitry Chagin
92870cb499 linux(4): Add copyin_sigset() helper.
MFC after:	2 weeks

(cherry picked from commit 3923e63209)
2022-06-17 22:34:04 +03:00
Dmitry Chagin
2d05c4f018 linux(4): Add linux_epoll_pwait_ts() helper for future use.
MFC after:	2 weeks

(cherry picked from commit 27a25179c8)
2022-06-17 22:34:04 +03:00
Dmitry Chagin
c78e5c4c6a linux(4): Copyout pselect timeout.
According to pselect6 manual, on error timeout becomes undefined, by fact
Linux modifies the timeout and ignore EFAULT error if so.

MFC after:	2 weeks

(cherry picked from commit 5171ed79f6)
2022-06-17 22:34:04 +03:00
Dmitry Chagin
302cff0ef9 linux(4): Add a simple rseq syscall implementation.
To avoid annoyng messages from glibc-2.35 test suite add the simple
implementation of rseq syscall which is do nothing for now.

I plan to implement it if and when the API stabilizes.

MFC after:	2 weeks

(cherry picked from commit ee55d560e8)
2022-06-17 22:34:03 +03:00
Dmitry Chagin
7056934698 linux(4): Refactor signal send methods.
Created a couple of helpers to send signals to the specific thread or to
the whole process. Use helpers in the corresponding syscalls.
This fixes the confusion where a signal destined for a whole process
was sent to a specific thread and vice versa.
There is an exclusion for the linux_kill() syscall that takes a pid
argument and should send a signal to the whole process, but I know
at least one example where kill() takes tid.

MFC after:		2 weeks

(cherry picked from commit 6201a50d0d)
2022-06-17 22:33:55 +03:00
Dmitry Chagin
e4de536940 linux(4): Check that the thread tid in the thread group pid in linux_tdfind().
MFC after:		2 weeks

(cherry picked from commit fe894a3705)
2022-06-17 22:33:54 +03:00
Dmitry Chagin
cadaecc91e linux(4): Microoptimize bsd_to_linux_sockaddr().
Differential Revision:	https://reviews.freebsd.org/D34725
MFC after:		2 weeks

(cherry picked from commit bbddd5881d)
2022-06-17 22:33:54 +03:00
Dmitry Chagin
c5789e62ba Add timespecvalid_interval macro and use it.
Reviewed by:		jhb, imp (early rev)
Differential revision:	https://reviews.freebsd.org/D34848
MFC after:		2 weeks

(cherry picked from commit 91e7bdcdcf)
2022-06-17 22:33:53 +03:00
Dmitry Chagin
c3dfbacbe9 linux(4): Copyout actual size of addr to the user space in accept().
Differential Revision:	https://reviews.freebsd.org/D34727

(cherry picked from commit 673bce11ce)
2022-06-17 22:33:52 +03:00
Dmitry Chagin
ecf8f49968 linux(4): Limit user-supplied sockaddr length in recvfrom().
Differential Revision:	https://reviews.freebsd.org/D34726

(cherry picked from commit bb0f644cd6)
2022-06-17 22:33:52 +03:00
Dmitry Chagin
543eaf070e linux(4): Remove unnecessary PTRIN().
(cherry picked from commit 68bfaefb3d)
2022-06-17 22:33:52 +03:00
Dmitry Chagin
61337dfb34 linux(4): Handle SO_DOMAIN in getsockopt syscall.
Differential revision:	https://reviews.freebsd.org/D34714

(cherry picked from commit cf312f799a)
2022-06-17 22:33:51 +03:00
Dmitry Chagin
d33fba34ab linux(4): Prevent an attempt to copy an uninitialized source address.
PR:			259380
MFC after:		3 days

(cherry picked from commit bb46e9b510)
2022-06-17 22:33:50 +03:00
Dmitry Chagin
9f870e779c linux(4): Fix a typo in itimerspec conversion routine.
MFC after:	3 days

(cherry picked from commit 0938d04a2c)
2022-06-17 22:33:49 +03:00
Dmitry Chagin
ac33f043f6 linux(4): Cleanup empty lines.
MFC after:		2 weeks

(cherry picked from commit 09d60bfae5)
2022-06-17 22:33:48 +03:00