Re: [PATCHv2 1/3] uprobe: Add uretprobe syscall to speed up return probe

From
Jiri Olsa <hidden>
Date
2024-04-08 16:02:17
Also in
bpf, linux-api, lkml
Reply to
Oleg Nesterov, 2024-04-05
On Fri, Apr 05, 2024 at 01:02:30PM +0200, Oleg Nesterov wrote:
On 04/05, Jiri Olsa wrote:
quoted
On Fri, Apr 05, 2024 at 10:22:03AM +0900, Masami Hiramatsu wrote:
quoted
I think this expects setjmp/longjmp as below

foo() { <- retprobe1
	setjmp()
	bar() { <- retprobe2
		longjmp()
	}
} <- return to trampoline

In this case, we need to skip retprobe2's instance.
Yes,
quoted
quoted
My concern is, if we can not find appropriate return instance, what happen?
e.g.

foo() { <-- retprobe1
   bar() { # sp is decremented
       sys_uretprobe() <-- ??
    }
}

It seems sys_uretprobe() will handle retprobe1 at that point instead of
SIGILL.
yes, and I think it's fine, you get the consumer called in wrong place,
but it's your fault and kernel won't crash
Agreed.

With or without this patch userpace can also do

	foo() { <-- retprobe1
		bar() {
			jump to xol_area
		}
	}

handle_trampoline() will handle retprobe1.
quoted
this can be fixed by checking the syscall is called from the trampoline
and prevent handle_trampoline call if it's not
Yes, but I still do not think this makes a lot of sense. But I won't argue.

And what should sys_uretprobe() do if it is not called from the trampoline?
I'd prefer force_sig(SIGILL) to punish the abuser ;) OK, OK, EINVAL.
so the similar behaviour with int3 ends up with immediate SIGTRAP
and not invoking pending uretprobe consumers, like:

  - setup uretprobe for foo
  - foo() {
      executes int 3 -> sends SIGTRAP
    }

because the int3 handler checks if it got executed from the uretprobe's
trampoline.. if not it treats that int3 as regular trap

while for uretprobe syscall we have at the moment following behaviour:

  - setup uretprobe for foo
  - foo() {
     uretprobe_syscall -> executes foo's uretprobe consumers
    }
  - at some point we get to the 'ret' instruction that jump into uretprobe
    trampoline and the uretprobe_syscall won't find pending uretprobe and
    will send SIGILL


so I think we should mimic int3 behaviour and:

  - setup uretprobe for foo
  - foo() {
     uretprobe_syscall -> check if we got executed from uretprobe's
     trampoline and send SIGILL if that's not the case

I think it's better to have the offending process killed right away,
rather than having more undefined behaviour, waiting for final 'ret'
instruction that jumps to uretprobe trampoline and causes SIGILL
I agree very much with Andrii,

       sigreturn()  exists only to allow the implementation of signal handlers.  It should never be
       called directly.  Details of the arguments (if any) passed to sigreturn() vary depending  on
       the architecture.

this is how sys_uretprobe() should be treated/documented.
yes, will include man page patch in new version

jirka
sigreturn() can be "improved" too. Say, it could validate sigcontext->ip
and return -EINVAL if this addr is not valid. But why?

Oleg.
Thread (30 messages) 30 messages, 5 authors, last reply 2024-04-18
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help