Commit Graph
80 Commits
Author SHA1 Message Date
Don Lewis 180d1a0e52 MFC r321899
Lower the amd64 shared page, which contains the signal trampoline,
from the top of user memory to one page lower on machines with the
Ryzen (AMD Family 17h) CPU.  This pushes ps_strings and the stack
down by one page as well.  On Ryzen there is some sort of interaction
between code running at the top of user memory address space and
interrupts that can cause FreeBSD to either hang or silently reset.
This sounds similar to the problem found with DragonFly BSD that
was fixed with this commit:
  https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/b48dd28447fc8ef62fbc963accd301557fd9ac20
but our signal trampoline location was already lower than the address
that DragonFly moved their signal trampoline to.  It also does not
appear to be related to SMT as described here:
  https://www.phoronix.com/forums/forum/hardware/processors-memory/955368-some-ryzen-linux-users-are-facing-issues-with-heavy-compilation-loads?p=955498#post955498

  "Hi, Matt Dillon here. Yes, I did find what I believe to be a
   hardware issue with Ryzen related to concurrent operations. In a
   nutshell, for any given hyperthread pair, if one hyperthread is
   in a cpu-bound loop of any kind (can be in user mode), and the
   other hyperthread is returning from an interrupt via IRETQ, the
   hyperthread issuing the IRETQ can stall indefinitely until the
   other hyperthread with the cpu-bound loop pauses (aka HLT until
   next interrupt). After this situation occurs, the system appears
   to destabilize. The situation does not occur if the cpu-bound
   loop is on a different core than the core doing the IRETQ. The
   %rip the IRETQ returns to (e.g. userland %rip address) matters a
   *LOT*. The problem occurs more often with high %rip addresses
   such as near the top of the user stack, which is where DragonFly's
   signal trampoline traditionally resides. So a user program taking
   a signal on one thread while another thread is cpu-bound can cause
   this behavior. Changing the location of the signal trampoline
   makes it more difficult to reproduce the problem. I have not
   been because the able to completely mitigate it. When a cpu-thread
   stalls in this manner it appears to stall INSIDE the microcode
   for IRETQ. It doesn't make it to the return pc, and the cpu thread
   cannot take any IPIs or other hardware interrupts while in this
   state."
since the system instability has been observed on FreeBSD with SMT
disabled.  Interrupts to appear to play a factor since running a
signal-intensive process on the first CPU core, which handles most
of the interrupts on my machine, is far more likely to trigger the
problem than running such a process on any other core.

Also lower sv_maxuser to prevent a malicious user from using mmap()
to load and execute code in the top page of user memory that was made
available when the shared page was moved down.

Make the same changes to the 64-bit Linux emulator.

PR:		219399
Reported by:	[email protected]
Reviewed by:	kib
Reviewed by:	dchagin (previous version)
Tested by:	[email protected] (earlier version)
Differential Revision:	https://reviews.freebsd.org/D11780
2017-08-16 07:59:57 +00:00
Konstantin Belousov c7eae662bd MFC r319873:
Move struct syscall_args syscall arguments parameters container into
struct thread.
2017-07-21 18:06:57 +00:00
Dmitry Chagin bb60288144 MFC r320595:
Add support for musl consumers to the Linuxulator.

PR:		213809
Submitted by:	Yonas Yanfa (for amd64)
Reported by:	Yonas Yanfa
Relnotes:	yes
2017-07-15 08:27:23 +00:00
Dmitry Chagin 1cab49cb0b MFC r319057:
In r246085 some bits that are MI movied out into headers in compat/linux,
but I missed that when I commited x86_64 Linuxulator. So remove the duplicates.
2017-07-15 08:24:29 +00:00
John Baldwin 67f8a82930 MFC 313564:
Drop the "created from" line from files generated by makesyscalls.sh.

This information is less useful when the generated files are included in
source control along with the source.  If needed it can be reconstructed
from the $FreeBSD$ tag in the generated file.  Removing this information
from the generated output permits committing the generated files along
with the change to the system call master list without having inconsistent
metadata in the generated files.

Regenerate the affected files along with the MFC.
2017-05-10 23:09:17 +00:00
Dmitry Chagin 9e509e15ab MFC r315957:
Implement Linux mincore() system call.
This is necessary for the upcoming drm-next.
2017-04-29 09:18:55 +00:00
Dmitry Chagin 9cfc6ccfb2 MFC r315505:
Implement getrandom() syscall.
Note. GRND_RANDOM option is not supported for now.
2017-04-23 06:43:52 +00:00
Dmitry Chagin f428ede9f3 MFC r315501:
To reduce code duplication move socket defines to the MI path.
2017-04-15 15:38:15 +00:00
Dmitry Chagin bde7e6f88b MFC r314866:
Reduce code duplication between MD Linux code by moving SYSV IPC 64-bit
related struct definitions out into the MI path.

Invert the native ipc structs to the Linux ipc structs convesion logic.
Since 64-bit variant of ipc structs has more precision convert native ipc
structs to the 64-bit Linux ipc structs and then truncate 64-bit values
into the non 64-bit if needed. Unlike Linux, return EOVERFLOW if the
values do not fit.

Fix SYSV IPC for 64-bit Linuxulator which never sets IPC_64 bit.
2017-04-15 15:11:23 +00:00
Tai-hwa Liang b17b62a147 MFC 316644:
Trying to be more compatible with Linux if.h definitions:
	- renaming l_ifreq::ifru_metric to l_ifreq::ifru_ivalue;
	- adding a definition for ifr_ifindex which points to l_ifreq::ifru_ivalue.

A quick search indicates that Linux already got the above changes since 2.1.14.

Reviewed by:	kib, marcel, dchagin
2017-04-15 09:33:42 +00:00
Mahdi Mokhtari d3c566745e MFC 314783:
Regenerated Linuxulator syscall tables for r314782

Approved by:	trasz
2017-04-11 13:42:26 +00:00
Mahdi Mokhtari 3352c3c8c2 MFC r314782:
Add UNIMPLEMENTED() placeholder macro for
the syscalls that are not implemented in Linux kernel itself.
Cleanup DUMMY() macros.

Approved by:	trasz
2017-04-11 12:49:25 +00:00
Edward Tomasz Napierala a62d33f4d2 MFC r313769:
Fix definition of linux64 ptrace syscall.

Relnotes:	yes
Sponsored by:	DARPA, AFRL
2017-04-01 17:07:09 +00:00
Edward Tomasz Napierala 33dc0bacbb MFC r313770:
Regen after r313769.

Sponsored by:	DARPA, AFRL
2017-04-01 16:38:20 +00:00
Edward Tomasz Napierala 4bd2adf2be MFC r313769:
Fix definition of linux64 ptrace syscall.

Sponsored by:	DARPA, AFRL
2017-04-01 16:35:42 +00:00
Dmitry Chagin 3d1b3fd0aa MFC r314312:
Change Linux epoll_pwait syscall definition to match Linux actual one.

MFC r314313:

Regen for r314312 (Linux epoll_pwait).

MFC r314314:

Return EINVAL in case when an invalid size of signal mask specified.
2017-03-30 20:08:25 +00:00
Dmitry Chagin 2941d8dc8b MFC r314295:
Implement timerfd family syscalls.
2017-03-30 20:03:20 +00:00
Dmitry Chagin 8977cc14e8 MFC r314292:
Regen after r314291 (timerfd definition).
2017-03-30 19:59:23 +00:00
Dmitry Chagin 35fc6c520d MFC r314291:
Change Linuxulator timerfd syscalls definition to match actual Linux one.
2017-03-30 19:56:41 +00:00
Edward Tomasz Napierala 479ebdfe01 MFC r313993:
Reimplement linux_arch_prctl() as a wrapper around sysarch(2).
This also adds support for LINUX_ARCH_SET_GS.
2017-03-19 10:41:36 +00:00
Dmitry Chagin faf9f0bc83 MFC r313940:
Implement rt_tgsigqueueinfo system call used by glibc for pthread_sigqueue(3).
2017-03-15 17:11:01 +00:00
Dmitry Chagin 52c69fb27b MFC r303464 (by brooks@):
Don't create pointless backups of generated files in "make sysent".

Any sensible workflow will include a revision control system from which
to restore the old files if required.  In normal usage, developers just
have to clean up the mess.
2017-03-11 08:39:24 +00:00
Mahdi Mokhtari 415291c0ad MFC r314219
Add linux_preadv() and linux_pwritev() syscalls to Linuxulator.

Approved by:	dchagin
2017-03-08 13:09:12 +00:00
Dmitry Chagin 106c513ec4 MFC r313284:
Update syscall.master to 4.10-rc6. Also fix comments, a typo,
  and wrong numbering for a few unimplemented syscalls.

  For 32-bit Linuxulator, socketcall() syscall was historically
  the entry point for the sockets API. Starting in Linux 4.3, direct
  syscalls are provided for the sockets API. Enable it.

  The initial version of patch was provided by trasz@ and extended by me.

MFC r313285:

  Regen after r313284.

MFC r313684:

  Fix r313284.

  Members of the syscall argument structures are padded to a word size. So,
  for COMPAT_LINUX32 we should convert user supplied system call arguments
  which is 32-bit in that case to the array of register_t.

MFC r313912:

  Finish r313684.

  Convert linux_recv(), linux_send() and linux_accept() system call arguments
  to the register_t type too.
2017-02-22 19:57:59 +00:00
Tijl Coosemans 2434318ae3 MFC r312699:
Apply r210555 to 64 bit linux support:

The interpreter name should no longer be treated as a buffer that can be
overwritten.

PR:		216346
2017-01-27 10:06:20 +00:00
Ed Maste a245c320e9 MFC r305994: Catch up to sys/capability.h rename to sys/capsicum.h in r263232
Also include r305995, reverting an unintended change from r305994.
2016-12-30 16:22:24 +00:00
Dmitry Chagin 94b49ea6f9 MFC r302517:
Fix a copy/paste bug introduced during X86_64 Linuxulator work.
FreeBSD support NX bit on X86_64 processors out of the box, for i386 emulation
use READ_IMPLIES_EXEC flag, introduced in r302515.

While here move common part of mmap() and mprotect() code to the files in compat/linux
to reduce code dupcliation between Linuxulator's

Approved by:	re (gjb)
2016-07-18 16:38:06 +00:00
Dmitry Chagin 2e33c30fe3 MFC r302516:
Regen for r302515 (Linux personality).

Approved by:	re (gjb)
2016-07-18 16:35:44 +00:00
Dmitry Chagin ffa95dadf4 MFC r302515:
Implement Linux personality() system call mainly due to READ_IMPLIES_EXEC flag.
In Linux if this flag is set, PROT_READ implies PROT_EXEC for mmap().
Linux/i386 set this flag automatically if the binary requires executable stack.

READ_IMPLIES_EXEC flag will be used in the next Linux mmap() commit.

Approved by:	re (gjb)
2016-07-18 16:34:11 +00:00
Dmitry Chagin f26a190f65 Regen after r300359 (struct l_sched_param removal).
MFC after:	1 week
2016-05-21 08:03:13 +00:00
Dmitry Chagin 8cc96fb43a Correct an argument param of linux_sched_* system calls as a struct l_sched_param
does not defined due to it's nature.

MFC after:	1 week
2016-05-21 08:01:14 +00:00
Dmitry Chagin 8521d01a71 Add a forgotten in r283424 .eh_frame section with CFI & FDE records to allow
stack unwinding through signal handler.

Reported by:	Dmitry Sivachenko
MFC after:	2 weeks
2016-05-09 07:38:47 +00:00
Pedro F. Giffuni edafb5a327 sys/amd64: Small spelling fixes.
No functional change.
2016-05-03 22:13:04 +00:00
Pedro F. Giffuni b66bb393f2 Cleanup redundant parenthesis from existing howmany()/roundup() macro uses. 2016-04-22 16:57:42 +00:00
Pedro F. Giffuni ea24b0561f X86: use our nitems() macro when it is avaliable through param.h.
No functional change, only trivial cases are done in this sweep,

Discussed in:	freebsd-current
2016-04-19 23:41:46 +00:00
Baptiste Daroussin b6348be7b9 Add kern.features flags for linux and linux64 modules
kern.features.linux: 1 meaning linux 32 bits binaries are supported
kern.features.linux64: 1 meaning linux 64 bits binaries are supported

The goal here is to help 3rd party applications (including ports) to determine
if the host do support linux emulation

Reviewed by:	dchagin
MFC after:	1 week
Relnotes:	yes
Differential Revision:	D5830
2016-04-05 22:36:48 +00:00
Dmitry Chagin 7c5982000d Revert r297310 as the SOL_XXX are equal to the IPPROTO_XX except SOL_SOCKET.
Pointed out by:	ae@
2016-03-27 10:09:10 +00:00
Dmitry Chagin c826fcfe22 iConvert Linux SOL_IPV6 level.
MFC after:	1 week
2016-03-27 08:12:01 +00:00
John Baldwin aa949be551 Convert ss_sp in stack_t and sigstack to void *.
POSIX requires these members to be of type void * rather than the
char * inherited from 4BSD.  NetBSD and OpenBSD both changed their
fields to void * back in 1998.  No new build failures were reported
via an exp-run.

PR:		206503 (exp-run)
Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D5092
2016-01-27 17:55:01 +00:00
Xin LI 669414e4fb Implement AT_SECURE properly.
AT_SECURE auxv entry has been added to the Linux 2.5 kernel to pass a
boolean flag indicating whether secure mode should be enabled. 1 means
that the program has changes its credentials during the execution.
Being exported AT_SECURE used by glibc issetugid() call.

Submitted by:	imp, dchagin
Security:	FreeBSD-SA-16:10.linux
Security:	CVE-2016-1883
2016-01-27 07:20:55 +00:00
Dmitry Chagin 9dba79fb66 Remove obsolete comment.
MFC after:	3 days
2016-01-23 08:08:06 +00:00
Dmitry Chagin f138999141 Fix a typo.
MFC after:	3 days
2016-01-23 08:04:29 +00:00
Gleb Smirnoff de44d808ef Regen after r293907. 2016-01-14 10:15:21 +00:00
Gleb Smirnoff 037f750877 Change linux get_robust_list system call to match actual linux one.
The set_robust_list system call request the kernel to record the head
of the list of robust futexes owned by the calling thread. The head
argument is the list head to record.
The get_robust_list system call should return the head of the robust
list of the thread whose thread id is specified in pid argument.
The list head should be stored in the location pointed to by head
argument.

In contrast, our implemenattion of get_robust_list system call copies
the known portion of memory pointed by recorded in set_robust_list
system call pointer to the head of the robust list to the location
pointed by head argument.

So, it is possible for a local attacker to read portions of kernel
memory, which may result in a privilege escalation.

Submitted by:	mjg
Security:	SA-16:03.linux
2016-01-14 10:13:58 +00:00
Dmitry Chagin 038c720553 Implement vsyscall hack. Prior to 2.13 glibc uses vsyscall
instead of vdso. An upcoming linux_base-c6 needs it.

Differential Revision:  https://reviews.freebsd.org/D1090

Reviewed by:	kib, trasz
MFC after:	1 week
2016-01-09 20:18:53 +00:00
Konstantin Belousov 724f4b62b0 Remove sv_prepsyscall, sv_sigsize and sv_sigtbl members of the struct
sysent.

sv_prepsyscall is unused.

sv_sigsize and sv_sigtbl translate signal number from the FreeBSD
namespace into the ABI domain.  It is only utilized on i386 for iBCS2
binaries.  The issue with this approach is that signals for iBCS2 were
delivered with the FreeBSD signal frame layout, which does not follow
iBCS2.  The same note is true for any other potential user if
sv_sigtbl.  In other words, if ABI needs signal number translation, it
really needs custom sv_sendsig method instead.

Sponsored by:	The FreeBSD Foundation
2015-11-28 08:49:07 +00:00
Mark Johnston 7672ca059a Remove unneeded includes of opt_kdtrace.h.
As of r258541, KDTRACE_HOOKS is defined in opt_global.h, so opt_kdtrace.h
is not needed when defining SDT(9) probes.
2015-11-22 02:01:01 +00:00
John Baldwin f2264f5048 Regen for linux32 rename and linux64 systrace. 2015-10-22 21:33:37 +00:00
John Baldwin 2f99bcce1e Rename remaining linux32 symbols such as linux_sysent[] and
linux_syscallnames[] from linux_* to linux32_* to avoid conflicts with
linux64.ko.  While here, add support for linux64 binaries to systrace.
- Update NOPROTO entries in amd64/linux/syscalls.master to match the
  main table to fix systrace build.
- Add a special case for union l_semun arguments to the systrace
  generation.
- The systrace_linux32 module now only builds the systrace_linux32.ko.
  module on amd64.
- Add a new systrace_linux module that builds on both i386 and amd64.
  For i386 it builds the existing systrace_linux.ko.  For amd64 it
  builds a systrace_linux.ko for 64-bit binaries.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D3954
2015-10-22 21:28:20 +00:00
Mateusz Guzik 3e15a670d2 linux: fix handling of out-of-bounds syscall attempts
Due to an off by one the code would read an entry past the table, as
opposed to the last entry which contains the nosys handler.

Reported by:	Pawel Biernacki <pawel.biernacki gmail.com>
2015-10-08 21:08:35 +00:00