-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kprobes incompatibility #47
Comments
Recreate procedure: First start systemtap to enable the kprobe:
Then in another window:
Notice the patch doesn't work. Now kill the stap process and the patch takes effect:
|
I had a good discussion about this with Masami Hiramatsu (kprobes maintainer). In my opinion we should go with option 4 because I think kpatching a kprobed function is an obscure and confusing use case that isn't worth supporting. Option 4 requires a new kprobes interface, but it resolves multiple issues (3 by my count). |
Option 4 still isn't perfect though. You wouldn't be able to kpatch a kprobed function, but you could still kprobe a kpatched function, which could cause a little bit of confusion if the kprobes were on the original version of the function. |
Also, we must consider the probing case after patching. We should introduce FTRACE_OPS_FL_IPMODIFY and if there is already a handler which has the flag at the given address, ftrace should reject new one. |
@mhiramat Yes, if some kprobes handlers modify IP, then I think an FTRACE_OPS_FL_IPMODIFY flag makes sense. One question: how will kprobes know if a given handler will modify the IP? Or would it always set the flag regardless? @rostedt had also suggested a FTRACE_OPS_FL_PERMANENT flag, so that a patch wouldn't ever get removed, even if function_trace_stop gets set. |
@jpoimboe all kprobes handlers is possible to change IP and it also requires the original (unmodified) IP address since it gets a kprobe handler from that. So anyway all kprobes must set the FTRACE_OPS_FL_IPMODIFY. to ensure ftrace passes unmodified IP. |
@mhiramat I talked with Steven about this a little bit. The problem with kprobes always setting FTRACE_OPS_FL_IPMODIFY is that it makes kprobes and kpatch always incompatible. If kprobes doesn't change regs->ip (which is probably true 99% of the time) then they should be able to co-exist. Another problem is that ftrace can't enforce it. If somebody doesn't provide FTRACE_OPS_FL_IPMODIFY, it would be hard for ftrace to verify that they aren't changing regs->ip. So how about this:
|
@jpoimboe I think your suggestion is OK for me. Most of the case, jprobe is the only kprobe user which can modify IP, and jprobe itself is rarely used. |
@mhiramathitachi Any chance you discussed this with Steven at LinuxCon? |
(2014/05/28 12:18), Josh Poimboeuf wrote:
Ah, I've heard that Steven will not be there. Last week I met him at LinuxCon Japan Thank you, :) Masami HIRAMATSU |
Sorry, I meant to say LinuxCon Japan :-) Are you planning on doing something like KPROBE_FLAG_IPMODIFY and FTRACE_OPS_FL_IPMODIFY like described above? |
Ah, I see :) |
Housekeeping: is there anything left to do that the introduction of the I still see kprobe_ftrace_ops() always setting |
Wow this is an old one. @mhiramathitachi @mhiramat are you still there? :-) The original suggestion was
I don't think this has been much of a problem. Masami, do you have any plans to do that? If not, we can close this. |
@jpoimboe, Thank you for correcting my account.:-) |
Hi folks, Is this still a problem? It works fine in my tests. My test steps are:
|
Also, when I unload the live patch in 2, the bpftrace in 1 continues to work as expected. |
Hi @liu-song-6 : thanks for checking, Masami fixed this in the kernel a while back with [PATCH] kprobes: Allow kprobes coexist with livepatch, so we can close this long-open issue. |
When kprobes registers with ftrace before kpatch does for the same function, kprobes "wins", until the kprobe has been unregistered with ftrace. The kernel kprobe_ftrace_handler function changes regs->ip, which overwrites the value which kpatch had written.
Option 1:
With this patch, if both kpatch and a kprobe handler try to modify the IP, kpatch always wins.
Option 2:
Create an
FTRACE_OPS_FL_LAST
flag which ensures that kpatch is called last, so that any kprobes attempts to update regs->ip will be ignored.This is another variation on option 1: if both kpatch and a kprobe handler try to modify the IP, kpatch always wins.
Option 3:
Create an
FTRACE_OPS_FL_FIRST
flag which ensures that kpatch is called first. Then pass the updated regs->ip to the kprobes functions so they can set their breakpoint at the beginning of the replacement function. The downside here is that kprobes modules can override kpatch's redirecting of functions, but that may not be much of an issue.So if both kpatch and a kprobe handler try to modify the IP, kprobes wins.
Option 4:
Create an
FTRACE_OPS_FL_IPMODIFY
flag: first to register wins.The text was updated successfully, but these errors were encountered: