Commit graph

242 commits

Author SHA1 Message Date
Andrew Turner
e5e2c7ffa0 Create sys/reg.h for the common code previously in machine/reg.h
Move the common kernel function signatures from machine/reg.h to a new
sys/reg.h. This is in preperation for adding PT_GETREGSET to ptrace(2).

Reviewed by:	imp, markj
Sponsored by:	DARPA, AFRL (original work)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D19830

(cherry picked from commit b792434150)
2022-05-12 15:12:59 -07:00
Edward Tomasz Napierala
f707a6cf1a Add infrastructure required for Linux coredump support
This adds `sv_elf_core_osabi`, `sv_elf_core_abi_vendor`,
and `sv_elf_core_prepare_notes` fields to `struct sysentvec`,
and modifies imgact_elf.c to make use of them instead
of hardcoding FreeBSD-specific values.  It also updates all
of the ABI definitions to preserve current behaviour.

This makes it possible to implement non-native ELF coredump
support without unnecessary code duplication.  It will be used
for Linux coredumps.

Reviewed By:	kib
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D30921

(cherry picked from commit 435754a59e)
2022-05-12 15:12:59 -07:00
Edward Tomasz Napierala
bb726462cb linux: Make PTRACE_GETREGSET return proper buffer size
This fixes Chrome warning:

[1022/152319.328632:ERROR:ptracer.cc(476)] Unexpected registers size 0 != 216, 68

Reviewed By:	emaste
Sponsored By:	EPSRC
Differential Revision: https://reviews.freebsd.org/D32616

(cherry picked from commit f939dccfd7)
2022-02-21 13:36:23 +00:00
Edward Tomasz Napierala
f89bad7c9c linux: Fix ptrace panic with ERESTART
Translate ERESTART into Linux "internal" errno ERESTARTSYS.
This fixes the erestartsys.gen.test from strace(1).

Reviewed By:	kib
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32623

(cherry picked from commit 6547153e46)
2022-02-21 13:36:11 +00:00
Edward Tomasz Napierala
f4fd475d45 linux: Improve debug for PTRACE_GETEVENTMSG
No functional changes.

Sponsored By:	EPSRC

(cherry picked from commit 2ec26ae402)
2022-02-21 13:36:01 +00:00
Edward Tomasz Napierala
fc36cd43fd linux: implement PTRACE_EVENT_EXEC
This fixes strace(1) from Ubuntu Focal.

Reviewed By:	jhb
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32367

(cherry picked from commit 6e66030c4c)
2022-02-21 13:35:51 +00:00
Edward Tomasz Napierala
3b7841de78 linux: Make PTRACE_GET_SYSCALL_INFO handle EJUSTRETURN
This fixes panic when trying to run strace(8) from Focal.

Reviewed By:	kib
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32355

(cherry picked from commit 2558bb8e91)
2022-02-21 13:35:30 +00:00
Edward Tomasz Napierala
046274e798 linux: Improve debug for PTRACE_GETREGSET
No functional changes.

Sponsored By:	EPSRC

(cherry picked from commit e3a83df119)
2022-02-21 13:35:20 +00:00
Edward Tomasz Napierala
98e26c32bb linux: Improve debugging for PTRACE_GETREGSET
It's triggered by gdb(1).

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32456

(cherry picked from commit a03d4d73e4)
2022-02-21 13:35:10 +00:00
Edward Tomasz Napierala
d33684f371 linux: Implement some bits of PTRACE_PEEKUSER
This makes Linux gdb from Bionic a little less broken.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32455

(cherry picked from commit f9246e1484)
2022-02-21 13:34:56 +00:00
Edward Tomasz Napierala
36ff5ce03c linux: Adjust PTRACE_GET_SYSCALL_INFO buffer size semantics
The tests/ptrace_syscall_info test from strace(1) complained
about this.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D32368

(cherry picked from commit 75a9d95b4d)
2022-02-21 13:34:44 +00:00
Konstantin Belousov
4cae9d803a Remove PT_GET_SC_ARGS_ALL
Reimplement bdf0f24bb1 by checking for the caller' ABI in
the implementation of PT_GET_SC_ARGS, and copying out everything if
it is Linuxolator.

Also fix a minor information leak: if PT_GET_SC_ARGS_ALL is done on the
thread reused after other process, it allows to read some number of that
thread last syscall arguments. Clear td_sa.args in thread_alloc().

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D31968

(cherry picked from commit f575573ca5)
2022-02-21 13:34:16 +00:00
Edward Tomasz Napierala
8371bf67d6 linux: implement PTRACE_GET_SYSCALL_INFO
This is one of the pieces required to make modern (ie Focal)
strace(1) work.

Reviewed By:	jhb (earlier version)
Sponsored by:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D28212

(cherry picked from commit bdf0f24bb1)
2022-02-21 13:23:50 +00:00
Edward Tomasz Napierala
0737ef6fbc linux: make ptrace(2) return EIO when trying to peek invalid address
Previously we've returned the error from native ptrace(2), ENOMEM.
This confused Linux strace(2).

Reviewed By:	emaste
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D29925

(cherry picked from commit 77651151f3)
2022-02-21 13:19:30 +00:00
Edward Tomasz Napierala
7256167dfd linux: refactor bsd_to_linux_regset() out of linux_ptrace.c
This will be used for Linux coredump support.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D30365

(cherry picked from commit 95c19e1d65)
2022-02-21 12:46:06 +00:00
Edward Tomasz Napierala
26105b4c13 linux(4): make arch_prctl(2) support GET_CET_STATUS, report unknown codes
This is largely a no-op, to make future debugging slightly easier.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D30035

(cherry picked from commit 916f3dba45)
2022-02-21 12:44:26 +00:00
Edward Tomasz Napierala
1f948bb41f linux(4): fix ptrace(2) to properly handle orig_rax
This fixes strace(1) erroneously reporting return values
as "Function not implemented", combined with reporting the binary
ABI as X32.

Very similar code in linux_ptrace_getregs() is left as it is - it's
probably wrong too, but I don't have a way to test it.

Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D29927

(cherry picked from commit 023bff7990)
2022-02-21 12:43:37 +00:00
Edward Tomasz Napierala
15acd92e8f linux: implement rt_sigsuspend(2) on arm64
... by making it architecture-independent.

Reviewed By:	dchagin
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D31259

(cherry picked from commit 72f7ddb587)
2022-02-14 18:45:24 +00:00
Edward Tomasz Napierala
64b1197cce Regen after 6d926e850d.
Sponsored By:	EPSRC

(cherry picked from commit c0f171736a)
2022-02-13 21:31:00 +00:00
Edward Tomasz Napierala
2e2337522f linux: add new syscall numbers
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D30193

(cherry picked from commit 6d926e850d)
2022-02-13 21:30:49 +00:00
Edward Tomasz Napierala
187a635352 linux: adjust ordering of Linux auxv and add dummy AT_HWCAP2
This should be a no-op; the purpose of this is to reduce
a spurious difference between Linuxulator and Linux, to make
debugging core dumps slightly easier.

Note that AT_HWCAP2 we pass to Linux binaries is always 0,
instead of being equal to 'cpu_feature2'.  This matches what
I've observed under Ubuntu Focal VM.

Reviewed By:	chuck, dchagin
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D29609

(cherry picked from commit ca6e1fa3ce)
2022-02-13 21:06:37 +00:00
Mark Johnston
947e849150 sysent: Add a sv_psstringssz field to struct sysentvec
The size of the ps_strings structure varies between ABIs, so this is
useful for computing the address of the ps_strings structure relative to
the top of the stack when stack address randomization is enabled.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 3fc21fdd5f)
2022-01-31 09:48:11 -05:00
Mark Johnston
d247611467 exec: Introduce the PROC_PS_STRINGS() macro
Rather than fetching the ps_strings address directly from a process'
sysentvec, use this macro.  With stack address randomization the
ps_strings address is no longer fixed.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 706f4a81a8)
2022-01-31 09:46:57 -05:00
Konstantin Belousov
fbdc76539b Add security.bsd.allow_ptrace sysctl
(cherry picked from commit fe6db72708)
2022-01-29 03:10:44 +02:00
Mark Johnston
1562fe492a exec: Simplify sv_copyout_strings implementations a bit
Simplify control flow around handling of the execpath length and signal
trampoline.  Cache the sysentvec pointer in a local variable.

No functional change intended.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f04a096049)
2022-01-14 08:50:06 -05:00
Konstantin Belousov
682f5b9385 amd64: consistently use uprintf() to report weird situations in sigreturn
(cherry picked from commit 2e79a21632)
2021-10-10 12:21:17 +03:00
Konstantin Belousov
61b29720ef amd64: centralize definitions of CS_SECURE and EFL_SECURE
(cherry picked from commit a42d362bb5)
2021-10-10 12:21:17 +03:00
Edward Tomasz Napierala
97de1b27db linux: make sure to zero the l_siginfo structure for ptrace(2)
Reported By:	dchagin
Sponsored By:	EPSRC

(cherry picked from commit f102b61d0e)
2021-09-13 10:39:42 -04:00
Konstantin Belousov
52d8029e93 Add quirks for Linux ABI signals handling
(cherry picked from commit 870e197d52)
2021-06-22 04:45:32 +03:00
Konstantin Belousov
dc107fe1f9 linuxolator: Add compat.linux.setid_allowed knob
PR:	21463

(cherry picked from commit 598f6fb49c)
2021-06-13 04:22:33 +03:00
Konstantin Belousov
876ffe2879 amd64/linux*: add required header to get the constant value
Otherwise asm silently interpret it as the external global symbol.

Reported by:	bz
Sponsored by:	The FreeBSD Foundation
Fixes:	91aae953cb

(cherry picked from commit a59f028537)
2021-05-26 15:18:54 -04:00
Konstantin Belousov
6bbde34ae6 amd64: clear PSL.AC in the right frame
If copyin family of routines fault, kernel does clear PSL.AC on the
fault entry, but the AC flag of the faulted frame is kept intact.  Since
onfault handler is effectively jump, AC survives until syscall exit.

Reported by:	m00nbsd, via Sony
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
admbugs:	975

(cherry picked from commit 91aae953cb)
2021-05-26 15:18:41 -04:00
Mark Johnston
14cc132657 linux: Fix SMAP-enabled futex routines
Some of them were dereferencing the user pointer before disabling SMAP.

PR:		255591
Reviewed by:	kib
Tested by:	pitwuu@gmail.com
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit fb58045145)
2021-05-23 12:43:43 -04:00
Ed Maste
6cd1cb27a9 regen syscall files after 0bd5d81f1e 2021-05-19 20:32:47 -04:00
Konstantin Belousov
6c74b12295 amd64 linux64: use x86_clear_dbregs()
(cherry picked from commit 2f15884747)
2021-04-23 14:14:08 +03:00
John Baldwin
f9d590884a Rename linux_set_upcall_kse() to linux_set_upcall().
This matches the rename of cpu_set_upcall_kse() in
5c2cf81845.

Sponsored by:	DARPA

(cherry picked from commit 3b57ddb029)
2021-03-29 15:36:11 -07:00
John Baldwin
77dfa7cfaf amd64: Cleanups to setting TLS registers for Linux binaries.
- Use update_pcb_bases() when updating FS or GS base addresses to
  permit use of FSBASE and GSBASE in Linux processes.  This also sets
  PCB_FULL_IRET.  linux32 was setting PCB_32BIT which should be a
  no-op (exec sets it).

- Remove write-only variables to construct unused segment descriptors
  for linux32.

Sponsored by:	Netflix

(cherry picked from commit 704547ce1c)
2021-03-29 11:09:41 -07:00
Mark Johnston
3df2766a69 linux: Unmap the VDSO page when unloading
linux_shared_page_init() creates an object and grabs and maps a single
page to back the VDSO.  When destroying the VDSO object, we failed to
destroy the mapping and free KVA.  Fix this.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D28696

(cherry picked from commit 0fc8a79672)
2021-02-22 20:29:55 -05:00
Edward Tomasz Napierala
c987d6a677 linux: map EBUSY returned by ptrace into ESRCH
The ptrace(2) Linux man page claims the syscall returns ESRCH,
if the tracee is not stopped; the native ptrace(2) returns EBUSY.

Sponsored by:	The FreeBSD Foundation
2021-01-19 11:21:55 +00:00
Edward Tomasz Napierala
47f7345bab linux: fix PTRACE_POKEDATA and PTRACE_POKETEXT.
Sponsored by:	The FreeBSD Foundation
2021-01-19 10:30:55 +00:00
Konstantin Belousov
4815f175d0 Linuxolator: Replace use of eventhandlers by sysent hooks.
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D27309
2020-11-23 18:18:16 +00:00
Conrad Meyer
77eb984147 'make sysent' for r367773
X-MFC-With:	r367773
2020-11-17 19:53:59 +00:00
Conrad Meyer
de774e422e linux(4): Implement name_to_handle_at(), open_by_handle_at()
They are similar to our getfhat(2) and fhopen(2) syscalls.

Differential Revision:	https://reviews.freebsd.org/D27111
2020-11-17 19:51:47 +00:00
Conrad Meyer
e9b13c6612 linux(4): Deduplicate unimpl/dummy syscall handlers
No functional change.

Reviewed by:	emaste, trasz
Differential Revision:	https://reviews.freebsd.org/D27099
2020-11-05 19:30:31 +00:00
Mateusz Piotrowski
a858a39b31 Fix a typo 2020-11-04 10:38:25 +00:00
Edward Tomasz Napierala
bce7ee9d41 Drop "All rights reserved" from all my stuff. This includes
Foundation copyrights, approved by emaste@.  It does not include
files which carry other people's copyrights; if you're one
of those people, feel free to make similar change.

Reviewed by:	emaste, imp, gbe (manpages)
Differential Revision:	https://reviews.freebsd.org/D26980
2020-10-28 13:46:11 +00:00
Edward Tomasz Napierala
866b1f5147 Fix misnomer - linux_to_bsd_errno() does the exact opposite.
Reported by:	arichardson
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26965
2020-10-27 12:49:40 +00:00
Kyle Evans
d42a83b1a9 audit: also correctly audit linux_execve()
Linux execve() gets audited as AUE_EXECVE as well, we should also interpret
the return from this correctly for the same reasoning as in r367002.

MFC with:	r367002
2020-10-26 17:30:17 +00:00
Edward Tomasz Napierala
6221ec6064 Stop calling set_syscall_retval() from linux_set_syscall_retval().
The former clobbers some registers that shouldn't be touched.

Reviewed by:	kib (earlier version)
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26406
2020-10-18 16:16:22 +00:00
Edward Tomasz Napierala
c0d07d326f Slightly tweak linux ptrace(2) debug message; no functional changes.
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26815
2020-10-18 15:56:47 +00:00