x86/livepatch: Fail the build if duplicate symbols exist
PATCH 1/1 x86/livepatch: Fail the build if duplicate symbols exist
From: Ross Lagerwall <[email protected]>
The binary diffing algorithm used by xen-livepatch depends on having unique symbols.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Ross Lagerwall <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Norbert Manthey <[email protected]>
This patch has been part of the XenServer patchqueue for ages, and should have been upstreamed sooner. It obviously can't be applied while the "block speculation" issue is outstanding.
--- xen/arch/x86/Makefile | 1 + xen/tools/symbols.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-)
xen/arch/x86/Makefile +1 -0
@@ -98,6 +98,7 @@ endif syms-warn-dup-y := --warn-dup syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := +syms-warn-dup-$(CONFIG_LIVEPATCH) := --error-dup $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32 ./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \
xen/tools/symbols.c +9 -2
@@ -599,7 +599,7 @@ static int compare_name(const void *p1, const void *p2)int main (int argc,char **argv) {unsigned int i; -bool unsorted = false, warn_dup = false; +bool unsorted = false, warn_dup = false, error_dup = false, found_dup = false;if (argc >=2 ) {for (i =1 ; i < argc; i++) {
@@ -619,6 +619,8 @@ int main(int argc, char **argv) sort_by_name =1 ; else if (strcmp(argv[i], "--warn-dup") == 0) warn_dup = true; + else if (strcmp(argv[i], "--error-dup") == 0) + warn_dup = error_dup = true; else if (strcmp(argv[i], "--xensyms") == 0) map_only = true; else
@@ -634,14 +636,19 @@ int main(int argc, char **argv)for (i =1 ; i < table_cnt; ++i)if (strcmp (SYMBOL_NAME (table + i -1 ),SYMBOL_NAME (table + i)) ==0 && - table[i -1 ].addr != table[i].addr) + table[i -1 ].addr != table[i].addr) {fprintf (stderr,"Duplicate symbol '%s' (%llx != %llx)\n" ,SYMBOL_NAME (table + i), table[i].addr, table[i -1 ].addr); + found_dup = true; + } unsorted = true; } +if (error_dup && found_dup) +exit (1 ); +if (unsorted)qsort (table, table_cnt,sizeof (*table), compare_value);
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines · Andrew Cooper
From: Ross Lagerwall <[email protected]>
The binary diffing algorithm used by xen-livepatch depends on having unique symbols.
Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
Quoted 76 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Ross Lagerwall <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Norbert Manthey <[email protected]>This patch has been part of the XenServer patchqueue for ages, and should have been upstreamed sooner. It obviously can't be applied while the "block speculation" issue is outstanding.
--- xen/arch/x86/Makefile | 1 + xen/tools/symbols.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-)xen/arch/x86/Makefile +1
-0@@ -98,6 +98,7 @@ endif syms-warn-dup-y := --warn-dup syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := +syms-warn-dup-$(CONFIG_LIVEPATCH) := --error-dup $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32 ./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \xen/tools/symbols.c +9
-2@@ -599,7 +599,7 @@ static int compare_name(const void *p1, const void *p2)int main (int argc,char **argv) {unsigned int i; -bool unsorted = false, warn_dup = false; +bool unsorted = false, warn_dup = false, error_dup = false, found_dup = false;if (argc >=2 ) {for (i =1 ; i < argc; i++) {@@ -619,6 +619,8 @@ int main(int argc, char **argv) sort_by_name =1 ; else if (strcmp(argv[i], "--warn-dup") == 0) warn_dup = true; + else if (strcmp(argv[i], "--error-dup") == 0) + warn_dup = error_dup = true; else if (strcmp(argv[i], "--xensyms") == 0) map_only = true; else@@ -634,14 +636,19 @@ int main(int argc, char **argv)for (i =1 ; i < table_cnt; ++i)if (strcmp (SYMBOL_NAME (table + i -1 ),SYMBOL_NAME (table + i)) ==0 && - table[i -1 ].addr != table[i].addr) + table[i -1 ].addr != table[i].addr) {fprintf (stderr,"Duplicate symbol '%s' (%llx != %llx)\n" ,SYMBOL_NAME (table + i), table[i].addr, table[i -1 ].addr); + found_dup = true; + } unsorted = true; } +if (error_dup && found_dup) +exit (1 ); +if (unsorted)qsort (table, table_cnt,sizeof (*table), compare_value);Signature · 1 line
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich
Acked-byQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 05.04.19 at 23:02, <[email protected]> wrote:
Quoted 4 lines · Andrew Cooper
From: Ross Lagerwall <[email protected]>
The binary diffing algorithm used by xen-livepatch depends on having unique symbols.
Question: Is this an inherent requirement, or an effect of the current implementation? It would seem to me that at least in the common case (binary didn't changer overly heavily) it ought to be possible to re-associate the duplicates with their correct origins. And by making the build fail (including in cases like the one we have right now), we're painting ourselves into the corner of having to "fix" code which isn't actually buggy.
Was the option of altering (amending) the symbol name instead of causing failure considered? Again, in the common case this shouldn't have overly bad implications: Typically the order of symbols wouldn't change between builds, so tagging the duplicates with a sequence number might be good enough. And even if the order changed, as long as both instances in fact derive from the same inline function, all would still be fine afaict. Granted there's some heuristic underlying this, in that we then would hope for there not to be actually differing functions with the same source file and symbol names.
Quoted 3 lines
Quoted 2 lines
Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Konrad Rzeszutek Wilk <[email protected]>
As for the time being this is hopefully going to do (once, as you say, the currently present issue has been addressed):
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 05.04.19 at 23:02, <[email protected]> wrote:
Quoted 4 lines · Andrew Cooper
From: Ross Lagerwall <[email protected]>
The binary diffing algorithm used by xen-livepatch depends on having unique symbols.
Quoted 7 lines
Question: Is this an inherent requirement, or an effect of the current implementation? It would seem to me that at least in the common case (binary didn't changer overly heavily) it ought to be possible to re-associate the duplicates with their correct origins. And by making the build fail (including in cases like the one we have right now), we're painting ourselves into the corner of having to "fix" code which isn't actually buggy.
It is inherent. The tool needs a unique way to identify each block of code, so it can work out if the binary has changed by more than just relocations.
How do you propose disambiguating ambiguous symbols after the fact?
(This is semi rhetorical, because even if there is a possible way, there is no plausible way it is the sensible option to take.)
Quoted 3 lines
Was the option of altering (amending) the symbol name instead of causing failure considered?
Amending how? We've already got one bodge to prepend the filename to static symbols.
The problem here is that we have two domctl.c's which both out-of-line the functions, and the compiler-adjustment of .isra.0 is deterministic based on the function parameters.
Quoted 4 lines
Again, in the common case this
shouldn't have overly bad implications: Typically the order of symbols wouldn't change between builds, so tagging the duplicates with a sequence number might be good enough.
This is painting ourselves into a corner with LTO.
Outside of LTO, the link order of files doesn't change, but the order of symbols in a file changes a fair bit.
Also, this reasoning depends on people only making trivial changes via livepatch, which, as it turns out, isn't the case in practice.
Quoted 2 lines
And even if the order changed, as long as both instances in fact derive from the same inline function, all would still be fine afaict.
How do you propose that we determine this?
Quoted 3 lines
Granted there's some heuristic underlying this, in that we then would hope for there not to be actually differing functions with the same source file and symbol names.
The more assumptions we start making, the more subtly this will go wrong in the future.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Konrad Rzeszutek Wilk <[email protected]>As for the time being this is hopefully going to do (once, as you say, the currently present issue has been addressed):
Acked-by Jan Beulich <[email protected]>
Thanks,
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 08.04.19 at 12:11, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 05.04.19 at 23:02, <[email protected]> wrote:
Quoted 4 lines · Andrew Cooper
From: Ross Lagerwall <[email protected]>
The binary diffing algorithm used by xen-livepatch depends on having unique symbols.
Quoted 7 lines
Question: Is this an inherent requirement, or an effect of the current implementation? It would seem to me that at least in the common case (binary didn't changer overly heavily) it ought to be possible to re-associate the duplicates with their correct origins. And by making the build fail (including in cases like the one we have right now), we're painting ourselves into the corner of having to "fix" code which isn't actually buggy.
Quoted 8 lines
It is inherent. The tool needs a unique way to identify each block of code, so it can work out if the binary has changed by more than just relocations.
How do you propose disambiguating ambiguous symbols after the fact?
(This is semi rhetorical, because even if there is a possible way, there is no plausible way it is the sensible option to take.)
I don't understand why you consider it impossible for this to be a sensible option.
First of all, from the very beginning of live-patching's existence I've been questioning it having got made dependent on the internal symbol table we generate, for there being a chance of it being broken in some way.
As to disambiguating: Other nearby local symbols could surely help. This might be a problem with -ffunction-sections, but other than I thought we don't appear to be using it - at least I couldn't get grep to produce a hit in xen/, config/, and the tree root.
Finally we likely could avoid the ambiguities altogether, e.g. by making the compiler emit (relative) directories when populating STT_FILE symbols. We already qualify multiply compiled source files by an object file name; I don't see why we couldn't also suitably qualify singly compiled files (and perhaps there's even a compiler option, such that we wouldn't need to issue .file assembler directives ourselves).
Another possibility to avoid (false) ambiguities could be to make the non-inline expansions of intended-to-be-inline functions link-once (which by implication means non-static, and hence necessarily uniquely named).
Quoted 5 lines
Quoted 2 lines
Was the option of altering (amending) the symbol name instead of causing failure considered?
Amending how? We've already got one bodge to prepend the filename to static symbols.
Right, in an attempt to disambiguate them. If the file names included (relative) paths, this would have been enough. Since they don't (for now at least), a sequence number might help.
Quoted 6 lines
Quoted 4 lines
Again, in the common case this
shouldn't have overly bad implications: Typically the order of symbols wouldn't change between builds, so tagging the duplicates with a sequence number might be good enough.This is painting ourselves into a corner with LTO.
Hmm, yes, it all would depend on the amount of churn between builds.
Quoted 7 lines
Also, this reasoning depends on people only making trivial changes via livepatch, which, as it turns out, isn't the case in practice.
Quoted 2 lines
And even if the order changed, as long as both instances in fact derive from the same inline function, all would still be fine afaict.
How do you propose that we determine this?
We build with debug info, so it ought to be possible in principle to know that both have the same source origin.
Quoted 6 lines
Quoted 3 lines
Granted there's some heuristic underlying this, in that we then would hope for there not to be actually differing functions with the same source file and symbol names.
The more assumptions we start making, the more subtly this will go wrong in the future.
Yes, I agree - that's the main downside. But failing a build is a pretty meaningful downside as well, the more when people may not build with LIVEPATCH=y before they submit. (FTR, personally I wouldn't consider it appropriate to revert in such a case, as an issue here has nothing to do with the actual change, but only with how we post-process data.) And even if they did, compiler (version) differences may make them not notice any issue. For this last reason even automatic testing (osstest or else) may end up assuming all is fine when it's not.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 08.04.19 at 12:11, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 05.04.19 at 23:02, <[email protected]> wrote:
Quoted 4 lines · Andrew Cooper
From: Ross Lagerwall <[email protected]>
The binary diffing algorithm used by xen-livepatch depends on having unique symbols.
Quoted 7 lines
Question: Is this an inherent requirement, or an effect of the current implementation? It would seem to me that at least in the common case (binary didn't changer overly heavily) it ought to be possible to re-associate the duplicates with their correct origins. And by making the build fail (including in cases like the one we have right now), we're painting ourselves into the corner of having to "fix" code which isn't actually buggy.
It is inherent. The tool needs a unique way to identify each block of code, so it can work out if the binary has changed by more than just relocations.
Quoted 6 lines
Quoted 4 lines
How do you propose disambiguating ambiguous symbols after the fact?
(This is semi rhetorical, because even if there is a possible way, there is no plausible way it is the sensible option to take.)
I don't understand why you consider it impossible for this to be a sensible option.
Because there is no problem which is best solved by throwing away the information you've got, and then trying to reconstruct it at a later point using divination.
Quoted 4 lines
First of all, from the very beginning of live-patching's existence I've been questioning it having got made dependent on the internal symbol table we generate, for there being a chance of it being broken in some way.
Xen uses the same diffing mechanism as kpatch. This was chosen for a number reasons, but first and foremost, because Ross and Konrad did the work which automatically gives them a 9/10'th choice on how to solve the various issues at hand, and "reusing an existing tool" is a very good reason.
You are welcome to invent a brand new way of performing binary diffing, but on top of needing to be at least as functional as the current solution, you will need to justify why deviating from the existing standard tooling is a good thing for the Xen community to be doing.
Until then, the current solution depends on having unique symbols.
Quoted 4 lines
As to disambiguating: Other nearby local symbols could surely help. This might be a problem with -ffunction-sections, but other than I thought we don't appear to be using it - at least I couldn't get grep to produce a hit in xen/, config/, and the tree root.
-ffunction-sections is injected by the livepatch-buildtools build logic. It doesn't live in the main xen.git build.
Quoted 8 lines
Finally we likely could avoid the ambiguities altogether, e.g. by making the compiler emit (relative) directories when populating
STT_FILEsymbols. We already qualify multiply compiled source files by an object file name; I don't see why we couldn't also suitably qualify singly compiled files (and perhaps there's even a compiler option, such that we wouldn't need to issue .file assembler directives ourselves).
Quoted 4 lines
Another possibility to avoid (false) ambiguities could be to make the non-inline expansions of intended-to-be-inline functions link-once (which by implication means non-static, and hence necessarily uniquely named).
I repeat my previous questions of "how do you propose to make this happen", with a side implication of "without inventing increasingly contorted logic to try and overcome problems which have been solved in more simple ways by others".
Quoted 8 lines
Quoted 6 lines
Also, this reasoning depends on people only making trivial changes via livepatch, which, as it turns out, isn't the case in practice.
Quoted 2 lines
And even if the order changed, as long as both instances in fact derive from the same inline function, all would still be fine afaict.
How do you propose that we determine this?
We build with debug info, so it ought to be possible in principle to know that both have the same source origin.
That doesn't make it safe. On release builds with LIVEPATCH enabled, it is domctl.c#is_pv_domain.isra.0 which is the duplicated symbol, and being separate translation units, the transformation into .isra.0 may be different.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Granted there's some heuristic underlying this, in that we then would hope for there not to be actually differing functions with the same source file and symbol names.
The more assumptions we start making, the more subtly this will go wrong in the future.
Yes, I agree - that's the main downside. But failing a build is a pretty meaningful downside as well, the more when people may not build with LIVEPATCH=y before they submit.
This is what CI is for, and why we also have things like RANDCONFIG.
But for people who want livepatching to work, failing the build is the obvious choice. The alternative is finding out that you've got customers with systems running the broken build of Xen which you can't generate a livepatch for.
Quoted 6 lines
(FTR, personally I wouldn't consider it appropriate to revert in such a case, as an issue here has nothing to do with the actual change, but only with how we post-process data.) And even if they did, compiler (version) differences may make them not notice any issue. For this last reason even automatic testing (osstest or else) may end up assuming all is fine when it's not.
No amount of automation is going to be able to perfectly determine that, for all current and future potential compilers, the resulting binary is fine.
But what we have here is a construct which breaks every version of GCC I've tried it with, and general CI definitely will pick this aspect up.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 11.04.19 at 21:51, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 08.04.19 at 12:11, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 05.04.19 at 23:02, <[email protected]> wrote:
Quoted 4 lines · Andrew Cooper
From: Ross Lagerwall <[email protected]>
The binary diffing algorithm used by xen-livepatch depends on having unique symbols.
Quoted 7 lines
Question: Is this an inherent requirement, or an effect of the current implementation? It would seem to me that at least in the common case (binary didn't changer overly heavily) it ought to be possible to re-associate the duplicates with their correct origins. And by making the build fail (including in cases like the one we have right now), we're painting ourselves into the corner of having to "fix" code which isn't actually buggy.
It is inherent. The tool needs a unique way to identify each block of code, so it can work out if the binary has changed by more than just relocations.
How do you propose disambiguating ambiguous symbols after the fact?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
(This is semi rhetorical, because even if there is a possible way, there is no plausible way it is the sensible option to take.)
I don't understand why you consider it impossible for this to be a sensible option.
Because there is no problem which is best solved by throwing away the information you've got, and then trying to reconstruct it at a later point using divination.
What information did I suggest to throw away?
To me it doesn't sound impossible to produce a diff of two binaries if both have the same number of instances of an otherwise identically named symbol. For live patching purposes the assumption has to be anyway that it's not the entire executable which changes, but just limited regions thereof.
Quoted 11 lines
Quoted 4 lines
First of all, from the very beginning of live-patching's existence I've been questioning it having got made dependent on the internal symbol table we generate, for there being a chance of it being broken in some way.
Xen uses the same diffing mechanism as kpatch. This was chosen for a number reasons, but first and foremost, because Ross and Konrad did the work which automatically gives them a 9/10'th choice on how to solve the various issues at hand, and "reusing an existing tool" is a very good reason.
Quoted 6 lines
You are welcome to invent a brand new way of performing binary diffing, but on top of needing to be at least as functional as the current solution, you will need to justify why deviating from the existing standard tooling is a good thing for the Xen community to be doing.
Until then, the current solution depends on having unique symbols.
Okay, I can accept this as an argument, and I certainly don't plan on writing a replacement (let alone justifying why I did).
Quoted 7 lines
Quoted 4 lines
As to disambiguating: Other nearby local symbols could surely help. This might be a problem with -ffunction-sections, but other than I thought we don't appear to be using it - at least I couldn't get grep to produce a hit in xen/, config/, and the tree root.
-ffunction-sections is injected by the livepatch-buildtools build logic. It doesn't live in the main xen.git build.
I see - not very fortunate, but at least I wasn't entirely mis-remembering that it gets used.
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
And even if the order changed, as long as both instances in fact derive from the same inline function, all would still be fine afaict.
How do you propose that we determine this?
We build with debug info, so it ought to be possible in principle to know that both have the same source origin.
That doesn't make it safe. On release builds with LIVEPATCH enabled, it is domctl.c#is_pv_domain.isra.0 which is the duplicated symbol, and being separate translation units, the transformation into .isra.0 may be different.
Oh, right - good point.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel