public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] Get tracer PID without reliance on the proc FS
@ 2024-09-05 21:27 Roman Kisel
  2024-09-05 21:27 ` [PATCH 1/1] ptrace: " Roman Kisel
  0 siblings, 1 reply; 29+ messages in thread
From: Roman Kisel @ 2024-09-05 21:27 UTC (permalink / raw)
  To: oleg, linux-kernel; +Cc: apais, benhill, ssengar, sunilmut, vdso

For debugging, it might be useful to run the debug trap
instruction to break into the debugger. To detect the debugger
presence, the kernel provides the `/proc/self/status` pseudo-file
that needs to be searched for the "TracerPid:" string.

Provide a prctl command that returns the PID of the tracer if any.
That allows for much simpler logic in the user land, and makes it
possible to detect tracer presence even if PROC_FS is not enabled.

As an example where this might be useful, one might refer to
the standard C++ and Rust libraries. See these links for the details:

* https://en.cppreference.com/w/cpp/utility/breakpoint_if_debugging
* https://lists.llvm.org/pipermail/libcxx-commits/2024-May/083574.html
* https://patchwork-proxy.ozlabs.org/project/gcc/patch/20240601102446.878286-1-jwakely@redhat.com/#3321542
* https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2546r0.html
* https://github.com/rust-lang/rust/pull/129019

Roman Kisel (1):
  ptrace: Get tracer PID without reliance on the proc FS

 include/uapi/linux/ptrace.h |  1 +
 kernel/ptrace.c             | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)


base-commit: ad618736883b8970f66af799e34007475fe33a68
-- 
2.34.1


^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: [PATCH 1/1] ptrace: Get tracer PID without reliance on the proc FS
@ 2024-09-07  8:45 Jubilee Young
  2024-09-09 19:37 ` Oleg Nesterov
  2024-09-10 16:34 ` Eric W. Biederman
  0 siblings, 2 replies; 29+ messages in thread
From: Jubilee Young @ 2024-09-07  8:45 UTC (permalink / raw)
  To: oleg
  Cc: akpm, apais, benhill, ebiederm, linux-kernel, romank, ssengar,
	sunilmut, torvalds, vdso

> if the process is ptraced, debugger can insert the breakoint into
> please_insert_the_breakpoint_here(). Otherwise breakpoint_if_debugging()
> is a cheap nop.

Generally a programmer wants to put this kind of conditional breakpoint
on an exception path, for which, unless one is working with a language that
abuses exceptions for control flow (which unfortunately describes... many),
the performance isn't of enormous concern. Not that it's free, either, but
opening a file and scanning it is a lot more code than a single call to prctl.

> Perhaps it makes sense to discuss the alternatives? Say, a process can have a
> please_insert_the_breakpoint_here() function implemented in asm which just does
> asm(ret).

There's some merit in having the debuggers recognize this pattern, as that
then would save every language that wants to have this power available
the trouble of reimplementing it. But first debuggers must recognize it,
which would require teaching each of them, which can be... tedious.
Having a function named `fatal` or whatever likewise has this issue.
A toolchain, however, can simply insert a jump to a breakpoint easily,
without having to hold gdb, lldb, cdb, and whatever-other-db's hand.

- Jubilee

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

end of thread, other threads:[~2024-09-11 20:25 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-05 21:27 [PATCH 0/1] Get tracer PID without reliance on the proc FS Roman Kisel
2024-09-05 21:27 ` [PATCH 1/1] ptrace: " Roman Kisel
2024-09-06 11:24   ` Oleg Nesterov
2024-09-06 11:48     ` Oleg Nesterov
2024-09-06 19:09     ` Linus Torvalds
2024-09-06 20:08       ` Roman Kisel
2024-09-06 20:26         ` Linus Torvalds
2024-09-06 21:15           ` Roman Kisel
2024-09-09 16:18             ` Eric W. Biederman
2024-09-09 17:05               ` Oleg Nesterov
2024-09-09 17:34                 ` Eric W. Biederman
2024-09-09 17:22               ` Roman Kisel
2024-09-06 20:55         ` Oleg Nesterov
2024-09-06 21:25           ` Roman Kisel
2024-09-08 14:08             ` Oleg Nesterov
2024-09-09 15:19               ` Roman Kisel
2024-09-09 16:42                 ` Oleg Nesterov
2024-09-09 17:05                   ` Roman Kisel
2024-09-07 19:33   ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2024-09-07  8:45 Jubilee Young
2024-09-09 19:37 ` Oleg Nesterov
2024-09-10 15:40   ` Roman Kisel
2024-09-11 14:44     ` Oleg Nesterov
2024-09-11 17:41       ` Roman Kisel
2024-09-11 19:53         ` Oleg Nesterov
2024-09-11 19:57           ` Linus Torvalds
2024-09-11 20:14             ` Oleg Nesterov
2024-09-11 20:25           ` Roman Kisel
2024-09-10 16:34 ` Eric W. Biederman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox