Commit graph

1702 commits

Author SHA1 Message Date
Alex S
9e7af40094 linux: Handle IP_RECVTOS cmsg type
This unbreaks apps using GameNetworkingSockets from Valve.

(cherry picked from commit 186dc094cf1ce14b26c6dfa329a445357121238a)
2025-03-31 10:43:06 -07:00
Alex S
a5918bfbf9 linux: Fix a typo in linux_recvmsg_common
We are supposed to check the result of bsd_to_linux_sockopt_level here
rather than its input.

(cherry picked from commit 9f55630b8d72602f6ec86b15b607f5fc5fde911e)
2025-03-31 10:42:56 -07:00
Mark Johnston
c813157a15 umtx: Add a helper for unlocked umtxq_busy() calls
This seems like a natural complement to umtxq_unbusy_unlocked().  No
functional change intended.

Reviewed by:	olce, kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D49124

(cherry picked from commit b01495caac2eca73463f4a889936a19e4c1c5909)
2025-03-07 22:51:48 +00:00
John Baldwin
939bcd2c20 cpu_set_upcall / linux_clone_thread: Remove calls to cpu_thread_clean
This is intended to clean state of a thread at the end of its
lifecycle during wait(), not the beginning of its life cycle.

Reviewed by:	kib
Sponsored by:	AFRL, DARPA
Differential Revision:	https://reviews.freebsd.org/D48023

(cherry picked from commit 0e742cc77454d0872ac2f6e7fd755b6d0322b711)
2025-03-03 11:56:20 -05:00
Warner Losh
a0e2fa50e7 linux.h: don't redefine lower_32_bits if already defined
systrace.c fails to build if we're using a common compiler.h for both
openzfs and linuxkpi. The issue is easy enough to fix: don't redefined
lower_32_bits if it's already defined in linux.h, since it's the least
'standardized'. This will allow systrace.c to build using an equivalent
macro.

MFC After: 3 days
Sponsored by: Netflix

(cherry picked from commit 481d5a4891648f0a6979a48689cc16fca80d4ab6)
2024-12-12 13:21:36 +01:00
Mark Johnston
91a8054473 linux sendfile: Fix handling of non-blocking sockets
FreeBSD sendfile() may perform a partial transfer and return EAGAIN if
the socket is non-blocking.  Linux sendfile() expects no error in this
case, so squash EAGAIN.

PR:		282495
Tested by:	pieter@krikkit.xyz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D47447

(cherry picked from commit a43b745aaf4f5bbc96875d2ab3ec9bea8024eda4)
2024-11-20 21:41:08 +00:00
Ed Maste
99d3ce80ba linuxulator: ignore AT_NO_AUTOMOUNT for all stat variants
Commit ff39d74aa9 ignored AT_NO_AUTOMOUNT for statx(), but did not
change fstat64() or newfstatat(), which also take an equivalent flags
argument.  Add a linux_to_bsd_stat_flags() helper and use it in all
three places.

PR:		281526
Reviewed by:	trasz
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46711

(cherry picked from commit 3cf834d069d1dcdbe464ea74624930eaf916715d)
2024-09-29 18:37:02 -04:00
Fernando Apesteguía
ddbbc129ae faccessat(2): Honor AT_SYMLINK_NOFOLLOW
Make the system call honor `AT_SYMLINK_NOFOLLOW`.

Also enable this from `linux_faccessat2` where the issue arised the first time.
Update manual pages accordingly.

PR:			275295
Reported by:		kenrap@kennethraplee.com
Approved by:		kib@
Differential Revision:	https://reviews.freebsd.org/D46267

(cherry picked from commit 5ab6ed93cd3680f8b69dd4d05823f4740a2bdef9)
2024-09-26 09:13:50 -04:00
Andrew Turner
d5e29c62e9 linux64: Fix the build on arm64 with bti checking
When we enable checking for BTI on arm64 we need to include an ELF
note in all object files linked into a module.

As using objcopy from a binary to an ELF object file doesn't add the
note switch to using .incbin from an assembly file. This allows us to
add the needed note without affecting the included object.

Reviewed by:	imp, kib, emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45468

(cherry picked from commit bed65d85c631c3a8e60a81a15a5a745c8ef92fbe)
(cherry picked from commit ec69d230933f82c7c142b053882255aa57475463)
2024-09-02 08:48:10 +00:00
Zhenlei Huang
1b3f88bc80 linux(4): Add const qualifier to the value parameter of function handle_string()
The content that `value` point to is not going to be altered by function
handle_string().

MFC after:	1 week

(cherry picked from commit 68c890b4433d3655c7df91cc43f89f4d6a8b35e4)
2024-05-28 12:21:20 +08:00
Lexi Winter
8c81694af4 linux: ignore setsockopt(IPV6_RECVERR)
Under Linux, the socket options IP_RECVERR and IPV6_RECVERR are used to
receive socket errors via a dedicated 'error queue' which can be
retrieved via recvmsg().  FreeBSD does not support this functionality.

For IPv4, the sysctl compat.linux.ignore_ip_recverr can be set to 1 to
silently ignore attempts to set IP_RECVERR and return success to the
application, which is wrong, but is required for (among other things)
a functional DNS client in recent versions of glibc.

Add support for ignoring IPV6_RECVERR, controlled by the same sysctl.
This fixes DNS in Linux when using IPv6 resolvers.

Reviewed by: imp, Jose Luis Duran
Pull Request: https://github.com/freebsd/freebsd-src/pull/1118

(cherry picked from commit ca63710d3668cf6f3cb4faf065d8b4eeffa028ad)
2024-04-27 06:59:46 -06:00
Gleb Smirnoff
f45ecf5fe4 linux: require vnet(9) context in ifname_bsd_to_linux_name()
This function is used by netlink(9) only.  The netlink(9) taskqueue thread
runs in the vnet of the socket whose request the thread is processing
right now.  This is a correct vnet and resetting it to vnet0 is incorrect.
If the function is to be used by any other caller in addition to
netlink(9), it would be caller's responsiblity to provide correct vnet(9).

Reviewed by:		melifaro, dchagin
Differential Revision:	https://reviews.freebsd.org/D44191
PR:			277286

(cherry picked from commit 2f5a315b307447f91891c96fb23c7333fa406f2f)
2024-03-11 09:11:56 -07:00
Alfredo Mazzinghi
2de742797b Abstract UIO allocation and deallocation.
Introduce the allocuio() and freeuio() functions to allocate and
deallocate struct uio. This hides the actual allocator interface, so it
is easier to modify the sub-allocation layout of struct uio and the
corresponding iovec array.

Obtained from:	CheriBSD
Reviewed by:	kib, markj
MFC after:	2 weeks
Sponsored by:	CHaOS, EPSRC grant EP/V000292/1
Differential Revision:	https://reviews.freebsd.org/D43711

(cherry picked from commit 61cc4830a7b16400efade3d884a59fda6d80d651)
2024-03-08 23:27:20 -05:00
Konstantin Belousov
38595c9d73 linux_pwd_onexec: do not abort image activation if emul path does not exist
(cherry picked from commit 99fa799a19abeb70b1034f65407c276b64709bdc)
2024-02-29 02:24:06 +02:00
Mark Johnston
0328de3def linux: Check for copyout errors in ioctl handlers
In preparation for annotating copyin() and friends with
__result_use_check.

Reviewed by:	dchagin
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43199

(cherry picked from commit b9924c202fc34004d4164cdc50f88d8fcef26279)
2024-01-04 08:42:13 -05:00
Kristof Provost
ff15498894 netlink: move NETLINK define to opt_global.h
Move the NETLINK define into opt_global.h so we can rely on it being
set correctly, without having to remember to include opt_netlink.h.
This ensures that the NETLINK define is correctly set. If not we
may end up with unloadable modules, due to missing symbols (such as
nlmsg_get_group_writer).

PR:		274306
Reviewed by:	imp, markj
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D42179

(cherry picked from commit ab393e9548f8cc0ee28499c411963b798ebb38a5)
2023-10-16 09:42:33 +02:00
Dmitry Chagin
4c1b13627a linux(4): Fix semid64_ds structure layout
Unlike x86_64, other 64-bit architectures do not have paddings
for the time fields.

MFC after:		1 week

(cherry picked from commit 1ee29160c5e5d8fa70173445b4a6de6742af74dc)
2023-10-10 08:12:13 +03:00
Dmitry Chagin
2e82949457 linux(4): Actually delete linux_sysproto.h
MFC after:		1 week

(cherry picked from commit fbb3f13b15539f223e40ff606744dc8ba1d6569f)
2023-10-10 08:12:12 +03:00
Dmitry Chagin
ce693de706 linux(4): Deorbit linux_nosys
Differential Revision:	https://reviews.freebsd.org/D41901
MFC after:		1 week

(cherry picked from commit 199e397e9bf1076ae905e2742ef8e294870f5b27)
2023-10-10 08:12:12 +03:00
Dmitry Chagin
4d46ca6550 linux(4): Update syscalls.master to 6.5
MFC after:		1 week

(cherry picked from commit 0a16d3d14db67c89ee08f954c670ec4f447a7ab5)
2023-10-02 08:44:53 +03:00
Dmitry Chagin
a08bb9bdd2 linux(4): On Linux SIGKILL can not be reset to default
MFC after:		1 week

(cherry picked from commit 227d01c1bc7caf2e838ee6eef1e6a3cc81d79d1b)
2023-09-25 13:18:55 +03:00
Dmitry Chagin
5ce9df199d linux(4): Staticize lsiginfo_to_siginfo
It's not used outside of linux_signal.c
While here fix the indentation.

MFC after:		1 week

(cherry picked from commit 794328fbc174360a09b6ad341624e9bce46f0d2e)
2023-09-25 13:18:54 +03:00
Dmitry Chagin
a321b17b8e linux(4): Deduplicate mmap2
To help porting the Linux emulation layer to a new platforms start using
Linux names for conditional builds instead of architecture-specific ifdefs.

MFC after:		1 week

(cherry picked from commit 2a1cf1b6b55c8326bbe85d0fdf17b0f2fb9b34ce)
2023-09-12 10:48:56 +03:00
Dmitry Chagin
4d17239617 linux(4): Deduplicate mprotect, madvise
MFC after:		1 week

(cherry picked from commit 553b1a4e4eb426d2c29a033b284c13bfbab30334)
2023-09-12 10:48:39 +03:00
Vico Chen
3c93ba3d7f linux(4): Convert flags in timerfd_create
The timerfd is introduced in FreeBSD 14, and the Linux ABI timerfd is
also moved to FreeBSD native timerfd, but it can't work well as Linux
TFD_CLOEXEC and TFD_NONBLOCK haven't been converted to FreeBSD
TFD_CLOEXEC and TFD_NONBLOCK.

Reviewed by:		dchagin, jfree
PR:			273662
Differential revision:	https://reviews.freebsd.org/D41708
MFC after:		1 week

(cherry picked from commit aadc14bceb4e94f5b75a05de96cd9619b877b030)
2023-09-12 10:47:54 +03:00
Dmitry Chagin
e975d1b725 linux(4): Return ENOTSUP from listxattr instead of EPERM
FreeBSD does not permits manipulating extended attributes in the system
namespace by unprivileged accounts, even if account has appropriate
privileges to access filesystem object.
In Linux the system namespace is used to preserve posix acls. Some Gnu
coreutils binaries uses posix acls, eg, install, ls, cp.  And fails if
we unexpectedly return EPERM error from xattr system calls.

In the other hands, in Linux read and write access to the system
namespace depend on the policy implemented for each filesystem, so we'll
mimics we're a filesystem that prohibits this for unpriveleged accounts.

Reported by:		zirias
Tested by:		zirias
MFC after:		1 week

(cherry picked from commit 11e37048db35d7fcfc285b867965de1aeefec2c8)
2023-09-11 14:59:38 +03:00
Dmitry Chagin
53b3e15d73 linux(4): Fix listxattr for the case when the size is 0
If size is specified as zero, these calls return the current size
of the list of extended attribute names (and leave list unchanged).

Tested by:		zirias
MFC after:		1 week

(cherry picked from commit 18d1c86788f66f42c4e096142f4f8d168f68732c)
2023-09-11 14:59:38 +03:00
Dmitry Chagin
bce9c2e340 linux(4): Return ENOTSUP from xattr syscalls instead of EPERM
FreeBSD does not permits manipulating extended attributes in the system
namespace by unprivileged accounts, even if account has appropriate
privileges to access filesystem object.
In Linux the system namespace is used to preserve posix acls. Some Gnu
coreutils binaries uses posix acls, eg, install, ls.  And fails if we
unexpectedly return EPERM error from xattr system calls.

In the other hands, in Linux read and write access to the system
namespace depend on the policy implemented for each filesystem, so we'll
mimics we're a filesystem that prohibits this for unpriveleged accounts.

Reported by:		zirias
Tested by:		zirias
MFC after:		1 week

(cherry picked from commit 1bfc4574f78653e4b64ac9dd31518c96a17fe52b)
2023-09-11 14:59:38 +03:00
Dmitry Chagin
0f35bf8b29 linux(4): Merge removexattr for future error recode
Tested by:		zirias
MFC after:		1 week

(cherry picked from commit dfcc0237c3a97f4f7962da854389f3c5d976145a)
2023-09-11 14:59:38 +03:00
Dmitry Chagin
a9b8a0ced4 linux(4): Return ENODATA from getxattr syscalls instead of EPERM
On Linux ENODATA mean the named attribute does not exist, or the
process has no access to this attribute.

Reported by:		zirias
PR:			273517
Tested by:		zirias
MFC after:		1 week

(cherry picked from commit 4d59b790553ef75b9a4b6a673eab3354f3d012b3)
2023-09-11 14:58:50 +03:00
Dmitry Chagin
803280ea07 linux(4): Merge getxattr for future error recode
Tested by:		zirias
MFC after:		1 week

(cherry picked from commit 6b46ec66129d9490c91876f72d98e514121996a6)
2023-09-11 14:58:50 +03:00
Jake Freeland
af93fea710 timerfd: Move implementation from linux compat to sys/kern
Move the timerfd impelemntation from linux compat code to sys/kern. Use
it to implement the new system calls for timerfd. Add a hook to kern_tc
to allow timerfd to know when the system time has stepped. Add kqueue
support to timerfd. Adjust a few names to be less Linux centric.

RelNotes: YES
Reviewed by: markj (on irc), imp, kib (with reservations), jhb (slack)
Differential Revision: https://reviews.freebsd.org/D38459
2023-08-24 14:28:56 -06:00
Dmitry Chagin
524c9accdc linux(4): Replace linux32_copyiniov by freebsd32_copyiniov
MFC after:		1 month
2023-08-20 10:36:32 +03:00
Dmitry Chagin
c987ff4d7b linux(4): Replace linux32_copyinuio by freebsd32_copyinuio
MFC after:		1 month
2023-08-20 10:36:32 +03:00
Dmitry Chagin
d6cb9e728b linux(4): Return EAGAIN instead of ENOBUFS for non-blocking sockets in pwrite
MFC after:		1 month
2023-08-20 10:36:31 +03:00
Dmitry Chagin
dfbb3e2aae linux(4): Return EAGAIN instead of ENOBUFS for non-blocking sockets in pwritev
MFC after:		1 month
2023-08-20 10:36:31 +03:00
Dmitry Chagin
4231b825ac linux(4): Add a dedicated writev syscall wrapper
Adding a writev syscall wrapper is needed due to Linux family of write
syscalls doesn't distinguish between in kernel blocking operations
and always returns EAGAIN while FreeBSD can return ENOBUFS.

MFC after:		1 month
2023-08-20 10:36:31 +03:00
Dmitry Chagin
e58ff66464 linux(4): Add a write syscall wrapper
Adding a write syscall wrapper is needed due to Linux family of write
syscalls doesn't distinguish between in kernel blocking operations
and always returns EAGAIN while FreeBSD can return ENOBUFS.

MFC after:		1 month
2023-08-20 10:36:29 +03:00
Dmitry Chagin
a129642ced linux(4): Fix linker warning about undefined vdso symbols
Pointed out by:		bz
MFC after:		3 days
2023-08-20 00:48:36 +03:00
Dmitry Chagin
4f9fac78d4 linux(4): Return EAGAIN instead of ENOBUFS for non-blocking sockets in sendfile
MFC after:		1 month
2023-08-19 21:55:23 +03:00
Dmitry Chagin
da5a6738d5 linux(4): Allow in fd to be a socket in sendfile
In this case sendfile fallback is used.

MFC after:		1 month
2023-08-19 21:55:23 +03:00
Dmitry Chagin
110be11ac9 linux(4): Remove include of sys/types.h from linux_vdso.h
Due to sys/param.h includes sys/types.h and the fact that the sys/param.h
is included everywhere where linux_vdso.h is needed.
2023-08-18 15:58:32 +03:00
Dmitry Chagin
2be88e2cca linux(4): Follow style(9), don't include both sys/param.h and sys/types.h 2023-08-18 15:58:32 +03:00
Dmitry Chagin
3460fab5fc linux(4): Remove sys/cdefs.h inclusion where it's not needed due to 685dc743 2023-08-18 13:12:02 +03:00
Dmitry Chagin
c47116e909 linux(4): Update my copyrights, add SPDX tag 2023-08-17 23:54:36 +03:00
Dmitry Chagin
270e01d468 linux(4): Fix leftovers after 2ff63af9 2023-08-17 23:54:00 +03:00
Dmitry Chagin
6ecab39494 linux(4): Drop bogus __arm__ condition due to lack of 32-bit arm support
MFC after:		1 month
2023-08-17 22:57:17 +03:00
Dmitry Chagin
4a521544a6 linux(4): Don't miss error from underlying in sendfile
MFC after:		1 month
2023-08-17 22:57:17 +03:00
James McLaughlin
bb66c59753 linux(4): Add sendfile fallback for non-socket fds
Before Linux 2.6.33, out_fd must refer to a socket. Since Linux 2.6.33
it can be any file.
The patch was originally provided by James McLaughlin and adapted by me
for copy_file_range.

PR:			262535
Differential revision:	https://reviews.freebsd.org/D34555
MFC after:		1 month
2023-08-17 22:57:17 +03:00
Dmitry Chagin
7307c43963 linux(4): Use native off_t for fo_sendfile call
MFC after:		1 month
2023-08-17 22:57:17 +03:00