mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Eric W. Biederman" <ebiederm@xmission.com>
To: Jubilee Young <workingjubilee@gmail.com>
Cc: oleg@redhat.com,  akpm@linux-foundation.org,
	 apais@microsoft.com, benhill@microsoft.com,
	 linux-kernel@vger.kernel.org, romank@linux.microsoft.com,
	 ssengar@microsoft.com, sunilmut@microsoft.com,
	 torvalds@linux-foundation.org, vdso@hexbites.dev
Subject: Re: [PATCH 1/1] ptrace: Get tracer PID without reliance on the proc FS
Date: Tue, 10 Sep 2024 11:34:18 -0500	[thread overview]
Message-ID: <87seu7bh85.fsf@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <CAPNHn3rTjMcbNXRpZTBc-zEkmnnMJO2iem9-eUdBkyaquz88rw@mail.gmail.com> (Jubilee Young's message of "Sat, 7 Sep 2024 01:45:50 -0700")

Jubilee Young <workingjubilee@gmail.com> writes:

>> 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.

I want to reiterate what Oleg pointed out elsewhere in this
conversation.

Observing a process is ptracing the current process does not mean a
debugger is attached to the current process.  It could be strace, or
upstart or some other code that happens to use the ptrace facility.

Which in turn means that opening /proc/self/status and looking for
TracerPid does not reliably detect if a debugger is attached.

Which unfortunately means that this must be solved as a coopeartive
effort between the library implementation and the debuggers.  Nothing
else can reliably tell you that a debugger is attached to your process.




Which in turn means this can not be solved in the kernel.  It must
be done as a cooperative effort between the implementation of the
library and the debuggers.

>> 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.

Unfortunately that is the only solution that I can see that will work
reliably.

> 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.

Eric

  parent reply	other threads:[~2024-09-10 16:34 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]
  -- strict thread matches above, loose matches on Subject: below --
2024-09-05 21:27 [PATCH 0/1] " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87seu7bh85.fsf@email.froward.int.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=akpm@linux-foundation.org \
    --cc=apais@microsoft.com \
    --cc=benhill@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=romank@linux.microsoft.com \
    --cc=ssengar@microsoft.com \
    --cc=sunilmut@microsoft.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vdso@hexbites.dev \
    --cc=workingjubilee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome