Page MenuHomeFreeBSD

dtrace/arm64: Fix copyout and copyoutstr
AcceptedPublic

Authored by freebsd_dev.thsi.be on Sat, Sep 5, 4:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Sep 16, 1:06 PM
Unknown Object (File)
Tue, Sep 15, 6:07 PM
Unknown Object (File)
Tue, Sep 15, 2:13 AM
Unknown Object (File)
Mon, Sep 14, 7:46 PM
Unknown Object (File)
Mon, Sep 14, 4:42 PM
Unknown Object (File)
Mon, Sep 14, 4:52 AM
Unknown Object (File)
Sun, Sep 13, 7:50 PM
Unknown Object (File)
Fri, Sep 11, 10:29 PM
Subscribers

Details

Reviewers
markj
andrew
gnn
Summary

Calling dtrace_copy and dtrace_copystr with the kaddr and uaddr
arguments inversed does not work with PAN. Rename them
dtrace_copyin_pan and dtrace_copyinstr_pan, respectively, and
implement dtrace_copyout_pan and dtrace_copyoutstr_pan.

Avoid excessive faulting by checkin DTrace's CPU flags. Implement the
trick from OpenSolaris/Illumos of only checking the flags when
crossing into a new page, altough more effectively by examining the
vaddr instead of the count.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 76570
Build 73453: arc lint + arc unit

Event Timeline

sys/cddl/contrib/opensolaris/uts/common/sys/dtrace_impl.h
1306

I'd like to take care of the armv6 case later. It alsos need the copy -> copyin rename and a new copyout versions. i'd like to use the same names, so dunno maybe it is better to use something else than _pan, e.g. _unpriv ?

For the record, the current broken behavior can be tested like this:

echo "Hello world!" > greetings
cat <<"EOT" > copyout.d
syscall::read:entry
/pid == $target/
{
	this->ubuf = arg1;
}

syscall::read:return
/pid == $target/
{
	self->kbuf = alloca(10);
	copyoutstr("Ciao ", this->ubuf, 5);
	copyinto(this->ubuf, 10, self->kbuf);
	copyout((void*)((uint64_t)self->kbuf+5), this->ubuf, 5);
}
EOT
dtrace -w -s copyout.d -c "cat greetings"

correct output:

dtrace: script 'copyout.d' matched 4 probes
dtrace: allowing destructive actions
 worl world!
dtrace: pid 5724 has exited

Maybe, instead of using the unprivileged load/store instructions, it would be better to explicitly disable and enable PAN like the native copyin/copyout routines do, using ENTER_USER_ACCESS/EXIT_USER_ACCESS? I believe that would let you avoid writing separate implementations for each direction. That's not an option on 32-bit arm, but they don't have to be consistent, and I'd somewhat prefer to have less code when possible.

sys/cddl/contrib/opensolaris/uts/common/sys/dtrace_impl.h
1306

These functions are really just local to <arch>/dtrace_isa.c, so I don't think the consistency matters. The prototypes are here only because it's convenient.

32-bit ARM doesn't have PAN, so that name wouldn't be appropriate.

I'd somewhat prefer to have less code when possible.

So maybe I should redo this using a single function for all 4 modes, which would disable/enable PAN, take an extra parameter (to be ORed when checking for a \0), check the CPU flags after the first byte copy and when crossing a 4k boundary and that would be it.

That's not an option on 32-bit arm, but they don't have to be consistent,

Ok. I need to fix the arm32 copyout part and I'd like to check what the status with powerpc64. Given this and the above, I need to put this review on hold for a while.

Thanks for your review.

sys/cddl/contrib/opensolaris/uts/common/sys/dtrace_impl.h
1306

To think about it, ARM32's unprivileged copyout versions won't even need the flags argument either.

Let's land this as it is. I don't really like the duplication nor the ifdef in dtrace_impl.h, but those are fairly minor and this fixes a real problem.

This revision is now accepted and ready to land.Wed, Sep 16, 1:06 PM