Commit graph

1534 commits

Author SHA1 Message Date
Dmitry Chagin
f8da863470 linux(4): Implement __vdso_time
PR:		240769
MFC after:	3 days

(cherry picked from commit 42317e6426)
2022-07-12 00:28:28 +03:00
Dmitry Chagin
8287577434 linux(4): Trace Linux l_sigset_t.
MFC after:		2 weeks

(cherry picked from commit 9310737333)
2022-07-06 14:02:13 +03:00
Mateusz Guzik
b2ae573abd linux: plug a set-but-not-used var
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 93494e425b)
2022-06-22 13:07:07 +03:00
Edward Tomasz Napierala
e226a45a66 linux(4): bump osrelease to 4.4.0.
This is required for the current Arch Linux binaries to work.

PR:		254112
Reviewed By:	emaste
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D29218

(cherry picked from commit 156da725d3)
2022-06-17 22:35:42 +03:00
Dmitry Chagin
8cbf694e68 linux(4): Return EINVAL when the clockid has invalid bits are set
Linux forbids PERTHREAD bit set for CLOCKFD clock.

MFC after:		2 weeks

(cherry picked from commit 539fadb493)
2022-06-17 22:35:41 +03:00
Dmitry Chagin
ee3efd6341 linux(4): Return ENOTSUP for unsupported clockid
It's much better from the user perspective to get a sane error code.

MFC after:		2 weeks

(cherry picked from commit 452f4636c3)
2022-06-17 22:35:41 +03:00
Dmitry Chagin
7c61d8e494 linux(4): Prefer sizeof(object) vs sizeof(type)
MFC after:		2 weeks

(cherry picked from commit 2722e515ac)
2022-06-17 22:35:40 +03:00
Dmitry Chagin
81d68fff1a linux(4): Error is not a bool, use proper comparison
MFC afer:		2 weeks

(cherry picked from commit 5573143777)
2022-06-17 22:35:40 +03:00
Dmitry Chagin
50fe2c32d5 linux(4): Use the copyin_sigset() in the remaining places
MFC after:		2 weeks

(cherry picked from commit 5e872c279a)
2022-06-17 22:35:39 +03:00
Dmitry Chagin
4312a49826 linux(4): Refactor SIGPWR mapping
Map Linux RT signals to the native RT signals starting from SIGRTMIN,
and Linux SIGPWR signal map to after the last RT signal.

MFC after:		2 weeks

(cherry picked from commit 7a7cee5585)
2022-06-17 22:35:39 +03:00
Dmitry Chagin
553fb2c654 linux(4): Fix the type of a constant in the signal mask macro
Since l_sigset_t is 64-bit unsigned on all Linuxulators, fix the type
of a constant in the signal mask manipulation macro.
The suffix L indicates type long which is 32-bit on i386, therefore,
bitwise operations between a 32-bit constant and 64-bit signal mask
lead to the wrong result.

Pointy hat to:		dchagin
MFC after:		2 weeks

(cherry picked from commit 669516a1a1)
2022-06-17 22:35:39 +03:00
Dmitry Chagin
601c19df36 linux(4): Reduce duplication between MD parts of the Linuxulator
Move sigprocmask actions defines under compat/linux,
they are identical across all Linux architectures.

MFC after:		2 weeks

(cherry picked from commit 2ca34847e7)
2022-06-17 22:35:37 +03:00
Dmitry Chagin
82062a0443 linux(4): Handle multiple mbufs in a control message chain in recvmsg
PR:		230274
MFC after:	2 weeks

(cherry picked from commit 3735f9cff1)
2022-06-17 22:35:37 +03:00
Dmitry Chagin
a66a545578 linux(4): Ratelimit message about unupported cmsg
MFC after:		2 weeks

(cherry picked from commit 31d7f3e9ce)
2022-06-17 22:35:36 +03:00
Dmitry Chagin
d05e863ca2 linux(4): Handle IP_ORIGDSTADDR socket option for IPPROTO_IP protocol level
MFC after:		2 weeks

(cherry picked from commit f8a6615064)
2022-06-17 22:35:36 +03:00
Dmitry Chagin
b13a727fce linux(4): Add LINUX_RATELIMIT_MSG_OPT2 for future use
MFC after:		2 weeks

(cherry picked from commit 4f02a4f48c)
2022-06-17 22:35:36 +03:00
Dmitry Chagin
44c89ec74d linux(4): Overwrite SO_TIMESTAMP counterpart
A socket cannot mix SO_TIMESTAMP and SO_TIMESTAMPNS: the two modes
are mutually exclusive.

MFC after:		2 weeks

(cherry picked from commit 53494b918d)
2022-06-17 22:35:35 +03:00
Dmitry Chagin
fc9014c195 linux(4): Refactor linux_common_recvmsg()
To improve readability lower nesting level, better naming for variables.
No functional changes.

MFC after:		2 weeks

(cherry picked from commit 0eda2ceab7)
2022-06-17 22:35:35 +03:00
Dmitry Chagin
01a6eb8a64 linux(4): Handle SO_TIMESTAMPNS socket option
The SO_TIMESTAMPNS enables or disables the receiving of the SCM_TIMESTAMPNS
control message. The cmsg_data field is a struct timespec.
To distinguish between SO_TIMESTAMP and SO_TIMESTAMPNS in the recvmsg()
map the last one to the SO_BINTIME and convert bintime to the timespec.
In the rest, implementation is identical to the SO_TIMESTAMP.

MFC after:		2 weeks

(cherry picked from commit 71bc8bcf66)
2022-06-17 22:35:35 +03:00
Dmitry Chagin
6bee81f9c6 linux(4): Handle 64-bit SO_TIMESTAMP for 32-bit binaries
To solve y2k38 problem in the recvmsg syscall the new SO_TIMESTAMP
constant were added on v5.1 Linux kernel. So, old 32-bit binaries
that knows only 32-bit time_t uses the old value of the constant,
and binaries that knows 64-bit time_t uses the new constant.

To determine what size of time_t type is expected by the user-space,
store requested value (SO_TIMESTAMP) in the process emuldata structure.

MFC after:		2 weeks

(cherry picked from commit 0e26e54bdf)
2022-06-17 22:35:34 +03:00
Dmitry Chagin
4c5b420b65 linux(4): For future use replace malloc type for l_sockaddr by M_LINUX
MFC after:		2 weeks

(cherry picked from commit 6335583990)
2022-06-17 22:35:34 +03:00
Dmitry Chagin
ac37e0edf9 linux(4): Improve recvmsg() readability
To improve recvmsg() readability SCM_ handlers moved to a separate
functions.

MFC after:		2 weeks

(cherry picked from commit b408788d6b)
2022-06-17 22:35:34 +03:00
Dmitry Chagin
24f2f93f5e linux(4): For future use move SCM definitions below socket options
MFC after:		2 weeks

(cherry picked from commit f409a7c538)
2022-06-17 22:35:33 +03:00
Dmitry Chagin
e23fea0a08 linux(4): Avoid EISCONN if addr is specified for sendto()
If the socket is in a connected state, the target address should be
ignored.

MFC after:		2 weeks

(cherry picked from commit db48fa8319)
2022-06-17 22:35:33 +03:00
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