Commit graph

1687 commits

Author SHA1 Message Date
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
Alvin Chen
5ad5cf5079 linux(4): Be verbose about unsupported ioctl commands on ifreq ioctl
Differential revision:	https://reviews.freebsd.org/D39786
MFC after:		1 month
2023-08-17 22:57:16 +03:00
Alvin Chen
1f2b31f76e linux(4): Add 2 Linux socket ioctl commands
Support 2 Linux socket ioctl commands: SIOCGIFMETRIC, SIOCSIFMETRIC.

Differential revision:	https://reviews.freebsd.org/D39786
MFC after:		1 month
2023-08-17 22:57:16 +03:00
Warner Losh
685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh
71625ec9ad sys: Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:24 -06:00
Warner Losh
2ff63af9b8 sys: Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:18 -06:00
Warner Losh
95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Dmitry Chagin
2467ccddc0 linux(4): Fix MSG_CTRUNC handling in recvmsg()
The MSG_CTRUNC flag of the msg_flags member of the message header is
set uppon successful completition if the control data was truncated.
Upon return from a successful call msg_controllen should contain the
length of the control message sequence.

Fixes:		0eda2cea
MFC after:	1 week
2023-08-14 15:46:12 +03:00
Dmitry Chagin
9d0c9b6d6a linux(4): Add a comment explaining udata freeing on error
MFC after:	1 week
2023-08-14 15:46:12 +03:00
Dmitry Chagin
de20eb26d0 linux(4): Refactor recvmsg
As the amount of handled anxiliary messages grows move they handlers
into a separate functions.

MFC after:	1 week
2023-08-14 15:46:12 +03:00
Dmitry Chagin
bbaa5523c0 linux(4): Skip unsupported anxiliary message
Instead of returning error, skip unsupported anxiliary messages and
fail if no one handled.

MFC after:	1 week
2023-08-14 15:46:12 +03:00
Dmitry Chagin
a21238d843 linux(4): Improve readability of recvmsg control buffer copyout code
MFC after:	1 week
2023-08-14 15:46:12 +03:00
Dmitry Chagin
43c3beb741 linux(4): Drop bogus empty line in linux_socket.c
MFC after:	1 week
2023-08-14 15:46:12 +03:00
Dmitry Chagin
7d561928e6 linux(4): Fix control message size calculation again
It looks Linux recvmsg allows msg_controllen size less then CMSG_SPACE
buffer, at least for case with one cmsghdr. Glibc misc/tst-scm_rights
test succed on Ubuntu 23.04

Fixes:	 	67116c69 "linux(4): Fix control message size calculation"
MFC after:	1 week
2023-08-14 15:46:11 +03:00
Konstantin Belousov
9b65fa6940 linuxolator: implement Linux' PROT_GROWSDOWN
From the Linux man page for mprotect(2):
   PROT_GROWSDOWN
       Apply  the  protection  mode  down to the beginning of a mapping
       that grows downward (which should be a stack segment or a
       segment mapped with the MAP_GROWSDOWN flag set).

Reported by:	dchagin
Reviewed by:	alc, markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41099
2023-08-12 09:28:14 +03:00
Dmitry Chagin
bbe017e041 linux(4): Add a dedicated ioprio system calls
On Linux these system calls have an effect only when used in conjuction
with an I/O scheduler that supports I/O priorities. If no I/O scheduler
has been set for a thread, then by defaut the I/O priority will follow
the CPU nice value. Due to FreeBSD lack of I/O scheduler facilities, the
default Linux behavior is implemented.

Ubuntu 23.04 debootstrap requires Linux ionice which depends on these
syscalls.

Differential Revision:	https://reviews.freebsd.org/D41153
MFC after:		1 month
2023-08-04 16:03:57 +03:00