Skip to contentSkip to conversation

: xl: poison data objects in auto-generated destructors

PATCH In review Gianni Tedesco 3 participants 6 messages Aug 20, 2010

lore
Share & tools
lore
#0 lore raw

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
diff -r f68726cdf357 tools/libxl/gentypes.py
@@ -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()
Acked-by on v1 1/1
#1 lore raw
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.

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 f68726cdf357 tools/libxl/gentypes.py

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()
#2 lore raw
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.

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:

Quoted 25 lines

diff -r f68726cdf357 tools/libxl/gentypes.py

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()
#3 lore raw
In reply to Ian Campbell
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.

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.

#4 lore raw
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

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.

#5 lore raw
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

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 :)