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
Questions about the current solution of correlating static local variables #545
Comments
Ah, right. Instead of uncorrelating and correlating in the same loop, they should be done in two separate loops, so that all of the uncorrelations are done before starting the correlations.
Ah, right, this is another problem. I need to think about it a little bit. Can you clarify your suggested solution? This static local correlation has been really hard to get right :-/ |
|
@jpoimboe , there is a solution that works fine in the same restrictions. |
|
@zhouchengming1 do you have a patch which reproduces these errors? I would like to test for this in the integration test suite. |
Refine the static local variable handling again. This builds on a
previous patch by Zhou Chengming.
This fixes the following bugs reported by Zhou:
1. xxx.123 ---> xxx.123 (previous correlation by coincidence)
xxx.256 ---> xxx.256 (previous correlation by coincidence)
But real xxx.123 ---> xxx.256
In this case, the code doesn't work. Because when find patched_sym for
xxx.123, the xxx.256 in patched_object hasn't been de-correlated.
2. old-object | new-object
func1 | func1
xxx.123 | xxx.123 (inline)
func2 | func2
xxx.256 | xxx.256
xxx.123 | xxx.123 (inline)
When find patched_sym for xxx.123, first find xxx.123 in func1 of new-object,
But then find xxx.256 in func2 of new-object.
So I think should not iterate the base-sections, when find one, just go out to next symbol.
Both of these problems can be fixed by splitting the code up into
multiple passes:
1. uncorrelate all static locals
2. correlate all static locals
3. ensure each static local is referenced by all the same sections in
both objects
4. print warning on any new static locals
Fixes: dynup#545
|
I have a patch, but it's for my module, not for the kernel. |
|
I'd like to test for you, when this git repository has merged your patch. |
|
@zhouchengming1 It has been merged, please test and let me know if it works for you. Thanks! |
|
I just have tested the new kpatch. Q2: works for me on correlating static local variables ? Q3: print any warnings about new variables? Last: Thanks. |
This was broken with #548 and will be fixed with #561.
The symbol's section should already be uncorrelated here and then re-correlated here. Is it not working for you?
Yeah, I think perhaps renaming the symbol isn't the best choice. Instead maybe we should store the twin's name in a separate variable which can be referenced in kpatch_create_dynamic_rela_sections().
Why?
Thanks, I'll try it out. |
|
Ok, so two issues here. First, I was able to recreate the error: with this patch: There's definitely a bug there, though I'm not sure exactly what the problem is yet. The second issue: Before: After: In theory the correlation mapping should be: But the code tried to map it as: There is no possible algorithm for coming up with this mapping which would always be correct in all scenarios. Therefore I think we will need to add some more restrictions. |
** .data.var.18451 is the symbol of the section, we undo the correlation of the symbol var.18451 and its section indeed, but no the symbol of the section . **
You are right, when I solved the first issue, this second issue caused another error. Because the var.16219 was correlated to a wrong static local , so the kpatch-build thought its section data ( initial value) was changed, and reported this error. Thanks |
|
Thanks, this was an excellent test case BTW. I'll have to figure out a way to incorporate it into the integration tests. For reference: |
|
I propose the following restrictions for static locals:
These restrictions are more limiting but will make it much safer IMO. And I think there should usually be ways to work around these restrictions if you get creative with modifying the patch. So I think I'll need to rewrite the code yet again. |
|
I've fixed the first issue with #564. |
After seeing the relocation table above, I am worried that this restriction is hard to get. Because a little change (no new static local) may change the order of reference, and kpatch-build won't know it.
|
Yes, there's no way for kpatch-build to enforce this restriction, and there's a very small chance that it could happen. The best we can do is clearly document this restriction. The only other option I can think of is to make it even more restrictive: disallow patching of any functions which reference two static local variables of the same name. |
Normally, kpatch doesn't complain if you remove or rename a function. This is a feature, because sometimes you have to rename a function in order to patch it, if for example it doesn't have an fentry call. In the object code, it's treated as a new function. You could get the same result by copying/pasting the original function and giving the copy a new name. But renaming it makes it much easier to review the patch. In RHEL 7.4, I tried to rename l2cap_config_rsp() to l2cap_config_rsp_kpatch(), but it failed with: ERROR: l2cap_core.o: reference to static local variable CSWTCH.347 in l2cap_config_rsp was removed This particular error is an easy fix, because the CSWTCH.* symbols are read-only and are created by GCC. So they shouldn't be correlated anyway. In the future, we will need a more general fix to allow the removal of functions which use *any* static local variables. Either automatically, or by adding a manual annotation. This can be handled when we rewrite the static local variable handling in dynup#545.
|
This issue has been open for 30 days with no activity and no assignee. It will be closed in 7 days unless a comment is added. |
|
This issue was closed because it was inactive for 7 days after being marked stale. |
Why undo the previous correlation in the iteration of base->symbols?
If xxx.123 ---> xxx.123 (previous correlation by coincidence)
xxx.256 ---> xxx.256 (previous correlation by coincidence)
But real xxx.123 ---> xxx.256
In this case, the code doesn't work. Because when find patched_sym for xxx.123,
the xxx.256 in patched_object hasn't been de-correlated.
So I think should undo all previous correlation before the new correlation.
Is the iteration of base-sections wrong?
old-object | new-object
func1 | func1
xxx.123 | xxx.123 (inline)
func2 | func2
xxx.256 | xxx.256
xxx.123 | xxx.123 (inline)
When find patched_sym for xxx.123, first find xxx.123 in func1 of new-object,
But then find xxx.256 in func2 of new-object.
So I think should not iterate the base-sections, when find one, just go out to next symbol.
The text was updated successfully, but these errors were encountered: