-
Notifications
You must be signed in to change notification settings - Fork 336
re-enable forced patch modules #398
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
Conversation
|
@flaming-toast This looks really good. Some minor comments coming... |
kmod/patch/kpatch-patch-hook.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/strlen(__kpatch_checksum) + 1/PAGE_SIZE/ here, to avoid overrunning buf.
|
end comments |
8be9a68 to
33164c4
Compare
|
Fixed review comments and rebased.
|
Ah, that's probably because the checksum string is stored in the section with a newline. I think it would be better to replace the newline with a trailing NULL. |
|
@jpoimboe Oh that explains it. :-) |
|
Ok, I think that works because there just happens to be a NULL byte after the Also I think it's kind of weird and unexpected to store the newline. So I think the newline should be replaced with a trailing NULL. Maybe something like: |
33164c4 to
7f215fd
Compare
|
I think the following should work (removes newline, adds NULL byte at the end): $ md5sum ../patch/output.o | awk '{printf "%s\0", $1}' > checksum.tmp || die$ hexdump -C checksum.tmp
00000000 37 66 65 37 61 31 38 36 63 31 32 36 66 37 33 38 |7fe7a186c126f738|
00000010 34 34 37 36 63 30 32 61 65 66 30 39 34 30 64 30 |4476c02aef0940d0|
00000020 00 |.|
00000021So I added that in, as well as the newline back in the |
|
Thanks @flaming-toast! |
|
@jpoimboe I am just realizing this, but I'll need to fix up testmod/doit.sh to include the new checksum section as well (which I can do in a separate PR). In addition, for kpatch unload, I think it probably makes sense to verify the checksum there as well...(I overlooked this, apologies! should be quick to add that change) |
I'm not sure what's needed here?
Why would we verify the checksum on unload? Feel free to add more commits to this PR if needed. |
I was not sure if it would be correct behavior if for whatever reason, a user supplies a module that happens to have the same name as another module already loaded, but differ in content. The unload would still succeed, even though the user supplied a fundamentally different module as an argument. But perhaps I am thinking too much here. :-) As for the doit.sh test script, it now fails while building the test module complaining that it cannot find a .kpatch.checksum section that the linker script is referencing, because of course, it does not have one. Should be quick to fix though. |
Ah, I see. I'm thinking we can not worry about that case :-)
Ah, cool. Add the commit to this PR and I'll put my thumb back up :-) |
|
Cool, fixed up doit.sh, should all work now! |
|
👍 |
In order to safely re-enable patch modules, add a special .kpatch.checksum section containing an md5sum of a patch module's contents. The contents of this section are exported to sysfs via patch_init and double checked when kpatch load finds that a module of the same name is already loaded.
|
Thanks @flaming-toast , that is my only comment |
|
End of my comments as well, thanks for your patience @flaming-toast |
0442756 to
bc851a4
Compare
|
Absolutely no problem, thanks for all the comments. |
kmod/patch/kpatch-patch-hook.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you missed my last comment here? Basically no need to check kpmod.enabled here or at line 75 because it's racy to check it without the mutex, and it's already being checked in kpatch_register/unregister.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, I'll go ahead and remove those lines.
bc851a4 to
8f06a11
Compare
|
Alright, I think I've addressed all comments so far. Let me know if there are any more issues. |
|
👍 |
re-enable forced patch modules
This warning no longer applies thanks to dynup#398.
Attempts to address #343, after taking the comments there into consideration.
Quick rundown:
.kpatch.checksumsection is added to the final output.o object usingobjcopy..kpatch.checksumare exported to sysfs.sysfs_create_group(previouslysysfs_create_file) moved to the end ofpatch_initto avoid the race condition wherekpatch_registeris called beforekpmod.objectsis fully initialized.kpmod->enabledcheck inkpatch_registerto after obtaining the mutex andtry_module_get. This was done so that If there are concurrent calls tokpatch_register, only one would succeed, and the others would see thatkpmod->enabledis already set true. Same forkpatch_unregister.load_modulenow checks if the given module is already loaded (or if another module with the same name is). If so, verify that the checksums read from the .ko file and the corresponding module in sysfs match.Other comments:
patch_init. Help verify that it's still sane :-) Also, not sure if I be calling sysfs_remove_group if sysfs_create_group fails. Doesn't make sense since if it fails the group was never created...Am I missing any other error conditions?This is the initial version of this patch so I suspect there may be things I am missing, or perhaps some parts can be done better. :-) As always, feedback is welcome.