<div dir="ltr">Hello Eugene,<div><br></div><div>Thanks for your mail. It has helped me a lot. Since "e8 00 00 00 00" is inserted in every function by default, I can use this place holder to dynamically put a new memory location in it so that the instruction pointer jumps to a desired location, in my case, the patched function.</div><div><br></div><div>Thanks,</div><div>Rahul. </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 7, 2015 at 2:55 PM, Evgenii Shatokhin <span dir="ltr"><<a href="mailto:eshatokhin@odin.com" target="_blank">eshatokhin@odin.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
06.10.2015 15:21, Rahul Kumar пишет:<span class=""><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello Eugene,<br>
<br>
Thanks for your reply. In RHEL6, can I force gcc to insert no-ops before<br>
every function so that I can use a modified kpatch to achieve patching?<br>
</blockquote>
<br></span>
I know no easy way to do that, unfortunately.<br>
<br>
In RHEL 6, GCC 4.4.x can generate 'call mcount' placeholders in the kernel functions, and it does so by default. The problem is, a placeholder is after the prologue of the function rather than at its very start:<br>
<br>
push %rbp<br>
mov %rsp,%rbp<br>
callq mcount // replaced with a 5-byte nop by Ftrace<br>
<...><br>
<br>
The stack and %rbp are changed, so one cannot simply replace the placeholder with a jump to a new function.<br>
<br>
If GCC 4.4 supported '-mfentry' like the versions 4.6+ do, it would be able to generate a placeholder at the very start of the function. But it does not support it. Even if it did, the changes in Ftrace would have to be backported to the kernel too.<br>
<br>
Even if someone patched GCC to add that functionality, such changes in the compiler would require rebuilding (and re-testing, etc.) the kernel package and probably some other packages as well. Updating GCC is not something that should be taken lightly.<br>
<br>
Another way could be to ignore these placeholders entirely and just place a jump at the beginning of the function, saving the previous contents of the replaced area. But one has to be careful here: what if the function being patched is running at the moment?<br>
<br>
So, as I said, I can see no easy solution.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
<br>
Thanks and regards,<br>
Rahul.<br>
<br>
On Tue, Oct 6, 2015 at 5:03 PM, Evgenii Shatokhin <<a href="mailto:eshatokhin@odin.com" target="_blank">eshatokhin@odin.com</a><br></span><span class="">
<mailto:<a href="mailto:eshatokhin@odin.com" target="_blank">eshatokhin@odin.com</a>>> wrote:<br>
<br>
Hi,<br>
<br>
06.10.2015 14:09, Rahul Kumar пишет:<br>
<br>
Hello everybody,<br>
<br>
I have successfully used kpatch on RHEL7 and it works great. Now<br>
I am<br>
wondering if there is any way I can use kpatch on vanilla RHEL6.<br>
Please<br>
let me know whether it is possible or not.<br>
<br>
Thanks,<br>
Rahul.<br>
<br>
<br>
For Kpatch as it is now, the short answer is no, it is not possible.<br>
<br>
Kpatch needs GCC to support inserting the placeholders ('call<br>
__fentry__') at the beginning of each function, -mfentry option.<br>
IIRC, GCC 4.4.x from RHEL 6 does not support it.<br>
<br>
Another missing thing is the ability of Ftrace to change the<br>
instruction pointer (RIP register), which is not available in the<br>
kernel 2.6.32.<br>
<br>
In theory, one may rework Kpatch to use the 'call mcount'<br>
placeholders available in that kernel but it has its issues too.<br>
</span></blockquote>
<br>
Regards,<br>
Eugene<br>
<br>
</blockquote></div><br></div>