Properly size the leafsize field in the mdrestore_struct struct.
PATCH 1/1 Properly size the leafsize field in the mdrestore_struct struct.
It's 32 bits as defined in ctree.h, but the struct had it as 64 bits.
Found using MemorySanitizer.
--- btrfs-image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
btrfs-image.c +1 -1
@@ -128,7 +128,7 @@ struct mdrestore_struct {struct rb_root chunk_tree;struct list_head list;size_t num_items; -u64 leafsize; +u32 leafsize;u64 devid;u8 uuid[BTRFS_UUID_SIZE ];u8 fsid[BTRFS_FSID_SIZE ];
Signature · 1 line
2.0.0.526.g5318336
A message that is not in the archive (sent off-list or not yet received): CALb+jKqYiQYsHdfOBbOhd4bkR1Y_+Qjv4mvyqq8ZBuLoJkyeag@mail.gmail.com
I'd like to follow up on this a bit, because the way I found it was *weird*.
MSan found an uninitialized write. Reproducing the issue through GDB showed that there's a struct mdrestore_struct type with a member of type u64 called 'leafsize' which was... half-initialized? Four bytes were uninitialized, four were initialized. Looking further, it was being set by a call to a getter function defined in ctree.h, which pulls a particular member from a superblock struct... which is of type u32. Aha! So the struct member was missized. Easy enough to fix. Except that the mdrestore_struct is initialized using calloc, so the part that wasn't getting written to was
actually initialized, and the part that *was* was showing up as uninitialized. And actually contained a sane value, reliably. What was going on?
Turns out that btrfs's use of zlib, which was the uninstrumented system version, caused anything allocated by uncompress() to show up as uninitialized. (Trying to use __msan_unpoison did not work, as I have an iffy install of the
sanitizer in the first place (it's whatever happened to come with clang-3.3), and MSanDR (the dynamic-instrumentation tool which marks all uninstrumented libraries as good) is apparently not trivial to install. I may just build zlib.) But the point is, it would have been annoying and sad if this had been a false positive through and through, but I *did* find an actual issue here using MSan, even though MSan was pointing in the exact wrong place.
Adam Buchbinder
Hi Adam,
Quoted 5 lines · Adam Buchbinder
It's 32 bits as defined in
ctree.h, but the struct had it as 64 bits.Found using MemorySanitizer.
Signed-off-by Adam Buchbinder <[email protected]>
It looks good to me.
Thanks,
Satoru
Quoted 18 lines
--- btrfs-image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)btrfs-image.c +1
-1@@ -128,7 +128,7 @@ struct mdrestore_struct {struct rb_root chunk_tree;struct list_head list;size_t num_items; -u64 leafsize; +u32 leafsize;u64 devid;u8 uuid[BTRFS_UUID_SIZE ];u8 fsid[BTRFS_FSID_SIZE ];
Quoted 10 lines · Satoru Takeuchi
Quoted 5 lines · Adam Buchbinder
It's 32 bits as defined in
ctree.h, but the struct had it as 64 bits.Found using MemorySanitizer.
Signed-off-by Adam Buchbinder <[email protected]>It looks good to me.
Signed-off-by Satoru Takeuchi <[email protected]>
Sidned-off? Did you mean Reviewed-by ?
Satoru Takeuchi
Reviewed-byQuoted 6 lines · David Sterba
Quoted 5 lines · Satoru Takeuchi
Quoted 4 lines · Adam Buchbinder
It's 32 bits as defined in
ctree.h, but the struct had it as 64 bits.Found using MemorySanitizer.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Adam Buchbinder <[email protected]>It looks good to me.
Signed-off-by Satoru Takeuchi <[email protected]>Sidned-off? Did you mean Reviewed-by ?
Oops, sorry.
Quoted 11 lines · Satoru Takeuchi
Quoted 10 lines · David Sterba
Quoted 9 lines · Satoru Takeuchi
Quoted 5 lines · Adam Buchbinder
It's 32 bits as defined in
ctree.h, but the struct had it as 64 bits.Found using MemorySanitizer.
Signed-off-by Adam Buchbinder <[email protected]>It looks good to me.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Satoru Takeuchi <[email protected]>Sidned-off? Did you mean Reviewed-by ?
Oops, sorry.
Reviewed-by Satoru Takeuchi <[email protected]>
Thanks, patch updated.