Page MenuHomeFreeBSD

ptrace(2): PT_SET_SC_RET request
ClosedPublic

Authored by kib on Wed, Jul 15, 2:24 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Jul 21, 6:53 AM
Unknown Object (File)
Tue, Jul 21, 2:44 AM
Unknown Object (File)
Mon, Jul 20, 9:02 PM
Unknown Object (File)
Mon, Jul 20, 7:24 PM
Unknown Object (File)
Mon, Jul 20, 6:36 PM
Unknown Object (File)
Mon, Jul 20, 5:46 PM
Unknown Object (File)
Mon, Jul 20, 5:10 PM
Unknown Object (File)
Mon, Jul 20, 5:06 PM

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Wed, Jul 15, 2:24 AM
kib added a reviewer: markj.

Document PT_SET_SC_RET

sys/kern/sys_process.c
1350
1364

Why not set TDB_USERWR here?

kib marked 2 inline comments as done.Wed, Jul 15, 8:56 PM
kib added inline comments.
sys/kern/sys_process.c
1350

I will also fix the style for PT_GET_SC_RET then.

1364

It would not serve any purpose, IMO.

kib marked 2 inline comments as done.

Style

lib/libsys/ptrace.2
866 ↗(On Diff #182031)

The size is not validated anywhere AFAICS.

871 ↗(On Diff #182031)

My suggestion for the last sentence: "After the thread is resumed, it returns to userspace with machine state set as though the system call handler had returned the values passed via the .Fa data argument."

sys/compat/freebsd32/freebsd32_misc.c
1065

Shouldn't we require uap->data == sizeof(r32.psr)? If uap->data is smaller, we'll copy uninitialized stack bytes into the native struct.

sys/kern/subr_syscall.c
70

How is it possible to have !traced && (td->td_dbgflags & TDB_SET_SC_RET) != 0?

kib marked 3 inline comments as done.Wed, Jul 15, 9:57 PM
kib added inline comments.
lib/libsys/ptrace.2
871 ↗(On Diff #182031)

I replaced it with the slight modification, it is not the 'data'.

sys/kern/subr_syscall.c
70

Might be it is not, but I did it out of caution.

I can remove it, but the idea is to ensure that the flags affecting the previous syscall entry do not leak to the current.

kib marked an inline comment as done.

Validate uap->data to be the size of the structure.
Edit man page.

markj added inline comments.
lib/libsys/ptrace.2
873 ↗(On Diff #182061)
sys/kern/subr_syscall.c
88

If TDB_SET_SC_RET is set, we will log the syscall via KTR and ktrace (but not dtrace) even though it is not executed. IMO it is better not to log anything in this case, i.e., we should skip this tracing.

This revision is now accepted and ready to land.Thu, Jul 16, 3:39 PM
kib marked an inline comment as done.Thu, Jul 16, 3:51 PM
kib added inline comments.
sys/kern/subr_syscall.c
88

TDB_SET_SC_RET is not set at this point, so KTR tracing goes due to the natural flow.

But for ktrace records, I thought about it, and I want them both (enter/exit) recorded. When I do the ktrace, I want to see the traced program perception of the kernel actions, and this includes the fake syscalls.

In fact, my use case is that I did 'ktrace -di capsicumised-truss -f sh -c 'date;date' and I want to see the values reported to the controlled process, sh in this case, by the tracer (truss).

In principle I agree with the sentiment that a marker would be useful in the ktrace records that would flag the fake syscall results.

This revision was automatically updated to reflect the committed changes.