: xl: poison data objects in auto-generated destructors
PATCH 1/1 : xl: poison data objects in auto-generated destructors
Increase the probability of blowing up badly up during any use-after-destroy scenarios.
tools/libxl/gentypes.py +4 -0
@@ -145,15 +145,19 @@ if __name__ == '__main__': #include <stdint.h> #include <stdlib.h> +#include <string.h> #include "libxl.h" +#define LIBXL_DTOR_POISON 0xa5 + """ % " ".join(sys.argv)) for ty in [t for t in types if t.destructor_fn is not None and t.autogenerate_destructor]: f.write("void %s(%s *p)\n" % (ty.destructor_fn, ty.typename)) f.write("{\n") f.write(libxl_C_type_destroy(ty, "p", True)) + f.write("\tmemset(p, LIBXL_DTOR_POISON, sizeof(*p));\n") f.write("}\n") f.write("\n") f.close()
Quoted 4 lines · On Fri, 2010-08-20 at 15:49 +0100, Gianni Tedesco (3P) wrote:
Increase the probability of blowing up badly up during any use-after-destroy scenarios.
Signed-off-by Gianni Tedesco <[email protected]>
I'd suggest perhaps only for debug=y builds but we don't seem to propagate that concept into tools/ and it's probably not worth it anyhow.
So:
Quoted 25 lines
diff -r
f68726cdf357tools/libxl/gentypes.pytools/libxl/gentypes.py +4
-0@@ -145,15 +145,19 @@ if __name__ == '__main__': #include <stdint.h> #include <stdlib.h> +#include <string.h> #include "libxl.h" +#define LIBXL_DTOR_POISON 0xa5 + """ % " ".join(sys.argv)) for ty in [t for t in types if t.destructor_fn is not None and t.autogenerate_destructor]: f.write("void %s(%s *p)\n" % (ty.destructor_fn, ty.typename)) f.write("{\n") f.write(libxl_C_type_destroy(ty, "p", True)) + f.write("\tmemset(p, LIBXL_DTOR_POISON, sizeof(*p));\n") f.write("}\n") f.write("\n") f.close()
Quoted 9 lines · Ian Campbell
Quoted 4 lines · On Fri, 2010-08-20 at 15:49 +0100, Gianni Tedesco (3P) wrote:
Increase the probability of blowing up badly up during any use-after-destroy scenarios.
Signed-off-by Gianni Tedesco <[email protected]>I'd suggest perhaps only for debug=y builds but we don't seem to propagate that concept into
tools/and it's probably not worth it anyhow.
The other approach would be to teach valgrind about such things but not sure if it has a concept of freeing-in-two-stages. Same could be said about gc pointers but I suspect sparse or something would work well to catch those 'return gc allocated pointers' etc. bugs.
Quoted 32 lines
So:
Acked-by Ian Campbell <[email protected]>Quoted 25 lines
diff -r
f68726cdf357tools/libxl/gentypes.pytools/libxl/gentypes.py +4
-0@@ -145,15 +145,19 @@ if __name__ == '__main__': #include <stdint.h> #include <stdlib.h> +#include <string.h> #include "libxl.h" +#define LIBXL_DTOR_POISON 0xa5 + """ % " ".join(sys.argv)) for ty in [t for t in types if t.destructor_fn is not None and t.autogenerate_destructor]: f.write("void %s(%s *p)\n" % (ty.destructor_fn, ty.typename)) f.write("{\n") f.write(libxl_C_type_destroy(ty, "p", True)) + f.write("\tmemset(p, LIBXL_DTOR_POISON, sizeof(*p));\n") f.write("}\n") f.write("\n") f.close()
Quoted 9 lines · Ian Campbell
Quoted 4 lines · On Fri, 2010-08-20 at 15:49 +0100, Gianni Tedesco (3P) wrote:
Increase the probability of blowing up badly up during any use-after-destroy scenarios.
Signed-off-by Gianni Tedesco <[email protected]>I'd suggest perhaps only for debug=y builds but we don't seem to propagate that concept into
tools/and it's probably not worth it anyhow.
Agreed. We probably just want to revert this patch right before the release, it might be worth to write a note about it somewhere.
Quoted 15 lines · Ian Campbell
Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Ian Campbell
Quoted 3 lines · On Fri, 2010-08-20 at 15:49 +0100, Gianni Tedesco (3P) wrote:
Increase the probability of blowing up badly up during any use-after-destroy scenarios.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Gianni Tedesco <[email protected]>I'd suggest perhaps only for debug=y builds but we don't seem to propagate that concept into
tools/and it's probably not worth it anyhow.Agreed. We probably just want to revert this patch right before the release, it might be worth to write a note about it somewhere.
Quoted 7 lines
There's no way we'll remember to do that ;-)
If we care (and I'm not sure how much of the toolstack code is likely to be performance critical at this level) then I think the time would be better spent making debug=[yn] do something under
tools/libx?Ian.
Agreed. Also this type of stuff is nice to have in widespread testing and bug tickling that "the idiot users out there" are so damn good at :)
Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Ian Campbell
Quoted 3 lines · On Fri, 2010-08-20 at 15:49 +0100, Gianni Tedesco (3P) wrote:
Increase the probability of blowing up badly up during any use-after-destroy scenarios.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Gianni Tedesco <[email protected]>I'd suggest perhaps only for debug=y builds but we don't seem to propagate that concept into
tools/and it's probably not worth it anyhow.Agreed. We probably just want to revert this patch right before the release, it might be worth to write a note about it somewhere.
There's no way we'll remember to do that ;-)
If we care (and I'm not sure how much of the toolstack code is likely to be performance critical at this level) then I think the time would be better spent making debug=[yn] do something under tools/libx?
Ian.