linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [REGRESSION] x86/entry: Tracer no longer has opportunity to change the syscall number at entry via orig_ax
@ 2020-08-19 17:14 Kyle Huey
  2020-08-19 19:44 ` Thomas Gleixner
  0 siblings, 1 reply; 12+ messages in thread
From: Kyle Huey @ 2020-08-19 17:14 UTC (permalink / raw)
  To: Thomas Gleixner, Kees Cook
  Cc: Robert O'Callahan, LKML,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	linux-arch, Will Deacon, Arnd Bergmann, Mark Rutland,
	Keno Fischer, Paolo Bonzini, kvm list, Gabriel Krisman Bertazi,
	Sean Christopherson

tl;dr: after 27d6b4d14f5c3ab21c4aef87dd04055a2d7adf14 ptracer
modifications to orig_ax in a syscall entry trace stop are not honored
and this breaks our code.

rr, a userspace record and replay debugger[0], redirects syscalls of
its ptracee through an in-process LD_PRELOAD-injected solib. To do
this, it ptraces the tracee to a syscall entry event, and then, if the
syscall instruction is not our redirected syscall instruction, it
examines the tracee's code and pattern matches against a set of
syscall invocations that it knows how to rewrite. If that succeeds, rr
hijacks[1] the current syscall entry by setting orig_ax to something
innocuous like SYS_gettid, runs the hijacked syscall, and then
restores program state to before the syscall entry trace event and
allows the tracee to execute forwards, through the newly patched code
and into our injected solib.

Before 27d6b4d14f5c3ab21c4aef87dd04055a2d7adf14 modifications to
orig_ax were honored by x86's syscall_enter_trace[2]. The generic arch
code however does not honor any modifications to the syscall number[3]
(presumably because on most architectures syscall results clobber the
first argument and not the syscall number, so there is no equivalent
to orig_rax).

Note that the above is just one example of when rr changes the syscall
number this way. This is done in many places in our code and rr is
largely broken on 5.9-rc1 at the moment because of this bug.

- Kyle

[0] https://rr-project.org/
[1] https://github.com/mozilla/rr/blob/cd61ba22ccc05b426691312784674c0eb8e654ef/src/Task.cc#L872
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/entry/common.c?h=v5.8&id=bcf876870b95592b52519ed4aafcf9d95999bc9c#n204
[3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/entry/common.c?h=v5.8&id=27d6b4d14f5c3ab21c4aef87dd04055a2d7adf14#n44

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-09-17  0:48 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 17:14 [REGRESSION] x86/entry: Tracer no longer has opportunity to change the syscall number at entry via orig_ax Kyle Huey
2020-08-19 19:44 ` Thomas Gleixner
2020-08-20 17:26   ` Kyle Huey
2020-08-20 21:09   ` Kees Cook
2020-08-21  0:35     ` Thomas Gleixner
2020-08-21 14:21   ` [tip: core/urgent] core/entry: Respect syscall number rewrites tip-bot2 for Thomas Gleixner
     [not found]   ` <87a6xzrr89.fsf@mpe.ellerman.id.au>
2020-09-11 18:58     ` [REGRESSION] x86/entry: Tracer no longer has opportunity to change the syscall number at entry via orig_ax Kees Cook
2020-09-12  0:10     ` Kees Cook
2020-09-13  7:44       ` Michael Ellerman
2020-09-13 18:27         ` Thomas Gleixner
2020-09-14 20:04           ` Kees Cook
2020-09-17  0:39             ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).