Re: [PATCH 1/1] ptrace: Get tracer PID without reliance on the proc FS

From: Roman Kisel
Date: Fri Sep 06 2024 - 16:08:21 EST




On 9/6/2024 12:09 PM, Linus Torvalds wrote:
On Fri, 6 Sept 2024 at 04:24, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:

Add cc's. Perhaps someone else can ack/nack the intent...

This (trivial) patch is obviously buggy, but fixable. I won't argue
if it can help userspace.

I think the "what's the point for user space" is the much more important thing.

Honestly, acting differently when traced sounds like a truly
fundamentally HORRIBLE model for anything at all - much less debugging
- and I think it should not be helped in any way unless you have some
really really strong arguments for it.

Can you figure it out as-is? Sure. But that's still not a reason to
make bad behavior _easier_.

No dispute that altering behavior based on whether a process is traced
or not _is_ bad behavior. To be precise, when the process is still
doing work, it undoubtedly is.

When the process has run into a fatal error and is about to exit, having
a way to break into the debugger at this exact moment wouldn't change
anything about the logic of the data processing happening in the process.
What's so horrible in that to have a way to land in the debugger to see
what exactly is going on?

Another aid of a similar kind is logging. Sure, can figure out what's
the bug without it. It is easier to with it though, and logging might
change resource consumption so much more than the check for the tracer
being present when the process is dying.

All told, let me know if I may proceed with fixing the code as Oleg
suggested, or this piece should go into the waste basket. I could make
an argument that providing the way to get the tracer PID only via
proc FS through parsing text is more like shell/Perl/Python interface
to the kernel, and for compiled languages could have what's easier in
that setting (there is an easy syscall for getting PID, and there could
be code changing the logic on the PID being odd or even for the sake
of argument).


Linus

--
Thank you,
Roman