Skip to contentSkip to conversation

CONFIG_HAVE_ARCH_TRACEHOOK and you

DISCUSSION Russell King 2 participants 2 messages Sep 12, 2008 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

ptrace_report_syscall
---------------------

What's the purpose of the PT_PTRACED check in there? The current code is setup such that you can only start tracing syscalls if the __ptrace_may_access test succeeds, which will only succeed if PT_PTRACED is already set. TIF_SYSCALL_TRACE will be cleared before PT_PTRACED is cleared when stopping ptracing. So, TIF_SYSCALL_TRACE can only ever be set if PT_PTRACED is already set, and hopefully arch code never tries to call the syscall tracing hooks if TIF_SYSCALL_TRACE isn't set. That all means that the PT_PTRACED test seems redundant.

Also, shouldn't ptrace_report_syscall() be in linux/ptrace.h, since it's just the guts of the existing syscall tracing hook irrespective of the tracehook stuff?

syscall
-------

* syscall_get_arguments - extract system call parameter values

 * @task:       task of interest, must be blocked
 * @regs:       task_pt_regs() of @task
 * @i:          argument index [0,5]
 * @n:          number of arguments; n+i must be [1,6].
 * @args:       array filled with argument values

This is all very well, but adds a lot of complexity for architectures which isn't currently required. This is fine if you have a sane ABI where you can just pick the arguments straight out of the registers one by one.

However, with ARM EABI, we have the situation where, for a syscall such as:

	long sys_foo(int a, long long b, long long c, int d);

the register allocation ends up as:

	a => r0
	b => r2, r3
	c => r4, r5
	d => r6

whereas:

	long sys_foo(long long a, long long b, int c, int d);

the register allocation ends up as:

	a => r0, r1
	b => r2, r3
	c => r4
	d => r5

So, in order to know which register argument N is in, you need to know all the types of the arguments which come before it. That means creating and maintaining a table of syscall arguments which sounds really sucky.

I can think of why you want these interfaces - because you see it as necessary for things like strace. However, strace needs to know the type information for each syscall argument in any case, so by putting the requirement for arg N access into the kernel, you're causing that type information to be placed not only in strace but also into the kernel.

It also means that you can't randomly change the syscall number, since changing the syscall number between those two examples means you need to reshuffle the registers to make the arguments fit.

To me, this looks like a source of a large can of worms. Is this really necessary, or can we keep this functionality pushed to where it belongs - in the very few userspace applications which require it?

I think the rest of syscall.h shouldn't be that much of a problem for ARM.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
#1 lore raw
Quoted 4 lines

ptrace_report_syscall
---------------------

What's the purpose of the PT_PTRACED check in there? [...]

The short answer is that tracehook_report_syscall_* is just about moving the current ptrace logic into the shared inline, not changing that logic. So it's a separate issue. The current logic (in arch/arm/kernel/ptrace.c too) has the check, I didn't change that.

In fact, I think it's not entirely redundant. When the tracer exits suddenly without doing PTRACE_DETACH (kill -9 gdb or whatnot), then ->ptrace gets cleared but TIF_SYSCALL_TRACE never gets reset. (That very arguably should be fixed, but it's not anything new.)

But all that's entirely orthogonal to consolidating each arch's copy of the code into ptrace_report_syscall, which is the only change to this area of ptrace that the tracehook migration itself does.

Quoted 3 lines

Also, shouldn't ptrace_report_syscall() be in linux/ptrace.h, since it's just the guts of the existing syscall tracing hook irrespective of the tracehook stuff?

I have no objection.

Quoted 4 lines

So, in order to know which register argument N is in, you need to know all the types of the arguments which come before it. That means creating and maintaining a table of syscall arguments which sounds really sucky.

I certainly don't propose that you do any of that. I think this is just a documentation issue. Instead of "syscall arguments", read "syscall argument registers, in the most naturally useful order for your arch".

Everything about these values, and the syscall # value (when != -1L), is entirely arch-specific. The asm/syscall.h interfaces aren't meant to make the meaning of those bits generic.

For example, on all 32-bit machines, __NR_pread64 logically takes 4 arguments but that's in 5 argument registers. In the syscall.h calls, args[3] means only the 4th argument register, not the whole "4th argument" (which is (args[3] | (args[4] << 32)) on LE-32).

Indeed, we do expect userland to know exactly which registers, in which order, we mean by "the 6 syscall arg registers" on the particular arch/ABI. It may be handy for userland that on some arch's or for many syscalls on most arch's, this happens to correspond with one argument per register in the natural order of syscall arguments at source level. But it's userland's problem to grok the ABI enough to know what these 6 registers plus the syscall # mean.

The reason we need syscall_get_arguments is that it can be used in places that the full user_regset calls can't be, such as in task_current_syscall. It's deep knowledge of the internals of the kernel's entry paths to know which user registers can and can't be found correctly in pt_regs when inside a fast-path system call entry. Nothing in userland knows that, nor should it. (And anyway, the user_regset calls are only kosher to call at "safe spots" like ptrace/signal stops--so that the arch's regset code is not obliged to carefully slice and dice for partially-available regsets.) When inside a syscall, the argument registers were certainly copied in, so we specify syscall_get_arguments assuming that these can always be got.

Thanks,
Roland