-
Notifications
You must be signed in to change notification settings - Fork 305
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
Issue while patching syscalls #1171
Comments
I'm not sure we've ever patched a syscall before. The problem is, that in It's possible to work around this limitation, but it will be a bit tricky. We'll need to mess with the syscall macros a bit... let me play around with it. |
Here's a patch which seems like it would work for patching the syscall. However it seems to have triggered a bug in kpatch-build:
Looking into it... |
Ah, that's because of this funny code:
which tries to access far beyond the bounds of the "hello" string. Otherwise, try out the above patch and let me know if it works for you. |
I opened #1172 to slightly improve the message for the error I saw. It should have said ".LC7+139" instead of ".rodata.__kpatch_do_sys_uname.str1.1+139". |
With syscall.patch.txt, I am getting errors like
Is this triggered by certain gcc? I am using |
Hm, it works for me with kernel 5.11 and I'm having trouble making sense of the error. It could be the gcc version or the kernel version (most of the macros were copy/pasted from the kernel with slight changes). |
The error also confuses me. I am using a 5.6 based kernel, which might be the reason. Let me debug more. Once this is all figured out, shall we include KPATCH_SYSCALL_DEFINEx() etc. in kpatch-macros.h? |
Yes, I think so. We might end up needing to have multiple versions of the macros based on kernel version and arch. And we can add an integration test to hopefully catch if/when the macros no longer work for future kernels. |
Have we considered adding kpatch-macros.h to the kernel tree? I guess this would reduce version/arch checks within kpatch-macros.h. |
This version works for the 5.6 kernel.
|
That would be nice, but it would be NAKed with a vengeance. Long term we do hope to have a unified patch creation solution which can live completely in the kernel tree. |
The change by @jpoimboe works great on a 5.12 based kernel. Thanks again. |
@liu-song-6 Glad that worked! Reopening so I don't forget to add the macro. |
On x86, attempting to patch a syscall results in an error, due to a missing fentry hook in the inner __do_sys##name() function. The fentry hook is missing because of the 'inline' annotation, which invokes 'notrace'. Add some kpatch-specific syscall definition macros which can be used for patching a syscall. These macros are copied almost verbatim from the kernel, the main difference being a 'kpatch' prefix added to the __do_sys##name() function name. This causes kpatch-build to treat it as a new function (due to its new name), and its caller __se_sys##name() function is inlined by its own caller __x64_sys##name() function, which has an fentry hook. To patch a syscall, just use replace the use of the SYSCALL_DEFINE1 (or similar) macro with the "KPATCH_" prefixed version. (This isn't needed on powerpc because the __do_sys##name() function is inlined by the compiler because it only has a single call site.) Fixes: dynup#1171 Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
On x86, attempting to patch a syscall results in an error, due to a missing fentry hook in the inner __do_sys##name() function. The fentry hook is missing because of the 'inline' annotation, which invokes 'notrace'. Add some kpatch-specific syscall definition macros which can be used for patching a syscall. These macros are copied almost verbatim from the kernel, the main difference being a 'kpatch' prefix added to the __do_sys##name() function name. This causes kpatch-build to treat it as a new function (due to its new name), and its caller __se_sys##name() function is inlined by its own caller __x64_sys##name() function, which has an fentry hook. To patch a syscall, just use replace the use of the SYSCALL_DEFINE1 (or similar) macro with the "KPATCH_" prefixed version. (This isn't needed on powerpc because the __do_sys##name() function is inlined by the compiler because it only has a single call site.) Fixes: dynup#1171 Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Hi,
I am testing a simple patch to a syscall:
create-diff-object failed on this:
which is true. On the other hand, we have __x64_sys_uname with proper fentry
So I guess we can just patch __x64_sys_uname instead?
Do we have better solution for this?
The text was updated successfully, but these errors were encountered: