All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Properly size the leafsize field in the mdrestore_struct struct.
@ 2014-06-12 22:57 Adam Buchbinder
       [not found] ` <CALb+jKqYiQYsHdfOBbOhd4bkR1Y_+Qjv4mvyqq8ZBuLoJkyeag@mail.gmail.com>
  2014-06-18  6:01 ` Satoru Takeuchi
  0 siblings, 2 replies; 6+ messages in thread
From: Adam Buchbinder @ 2014-06-12 22:57 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dave, 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 <abuchbinder@google.com>
---
 btrfs-image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/btrfs-image.c b/btrfs-image.c
index cf1fe2d..98d765a 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -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];
-- 
2.0.0.526.g5318336


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Properly size the leafsize field in the mdrestore_struct struct.
       [not found] ` <CALb+jKqYiQYsHdfOBbOhd4bkR1Y_+Qjv4mvyqq8ZBuLoJkyeag@mail.gmail.com>
@ 2014-06-13 23:58   ` Adam Buchbinder
  0 siblings, 0 replies; 6+ messages in thread
From: Adam Buchbinder @ 2014-06-13 23:58 UTC (permalink / raw)
  To: linux-btrfs

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Properly size the leafsize field in the mdrestore_struct struct.
  2014-06-12 22:57 [PATCH] Properly size the leafsize field in the mdrestore_struct struct Adam Buchbinder
       [not found] ` <CALb+jKqYiQYsHdfOBbOhd4bkR1Y_+Qjv4mvyqq8ZBuLoJkyeag@mail.gmail.com>
@ 2014-06-18  6:01 ` Satoru Takeuchi
  2014-06-23 13:44   ` David Sterba
  1 sibling, 1 reply; 6+ messages in thread
From: Satoru Takeuchi @ 2014-06-18  6:01 UTC (permalink / raw)
  To: Adam Buchbinder, linux-btrfs; +Cc: dave

Hi Adam,

(2014/06/13 7:57), Adam Buchbinder wrote:
> 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 <abuchbinder@google.com>

It looks good to me.

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>

Thanks,
Satoru

> ---
>   btrfs-image.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/btrfs-image.c b/btrfs-image.c
> index cf1fe2d..98d765a 100644
> --- a/btrfs-image.c
> +++ b/btrfs-image.c
> @@ -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];
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Properly size the leafsize field in the mdrestore_struct struct.
  2014-06-18  6:01 ` Satoru Takeuchi
@ 2014-06-23 13:44   ` David Sterba
  2014-06-23 23:12     ` Satoru Takeuchi
  0 siblings, 1 reply; 6+ messages in thread
From: David Sterba @ 2014-06-23 13:44 UTC (permalink / raw)
  To: Satoru Takeuchi; +Cc: Adam Buchbinder, linux-btrfs

On Wed, Jun 18, 2014 at 03:01:32PM +0900, Satoru Takeuchi wrote:
> (2014/06/13 7:57), Adam Buchbinder wrote:
> > 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 <abuchbinder@google.com>
> 
> It looks good to me.
> 
> Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>

Sidned-off? Did you mean Reviewed-by ?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Properly size the leafsize field in the mdrestore_struct struct.
  2014-06-23 13:44   ` David Sterba
@ 2014-06-23 23:12     ` Satoru Takeuchi
  2014-06-24  8:50       ` David Sterba
  0 siblings, 1 reply; 6+ messages in thread
From: Satoru Takeuchi @ 2014-06-23 23:12 UTC (permalink / raw)
  To: dsterba, Adam Buchbinder, linux-btrfs

(2014/06/23 22:44), David Sterba wrote:
> On Wed, Jun 18, 2014 at 03:01:32PM +0900, Satoru Takeuchi wrote:
>> (2014/06/13 7:57), Adam Buchbinder wrote:
>>> 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 <abuchbinder@google.com>
>>
>> It looks good to me.
>>
>> Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
>
> Sidned-off? Did you mean Reviewed-by ?
>

Oops, sorry.

Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Properly size the leafsize field in the mdrestore_struct struct.
  2014-06-23 23:12     ` Satoru Takeuchi
@ 2014-06-24  8:50       ` David Sterba
  0 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2014-06-24  8:50 UTC (permalink / raw)
  To: Satoru Takeuchi; +Cc: dsterba, Adam Buchbinder, linux-btrfs

On Tue, Jun 24, 2014 at 08:12:30AM +0900, Satoru Takeuchi wrote:
> (2014/06/23 22:44), David Sterba wrote:
> >On Wed, Jun 18, 2014 at 03:01:32PM +0900, Satoru Takeuchi wrote:
> >>(2014/06/13 7:57), Adam Buchbinder wrote:
> >>>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 <abuchbinder@google.com>
> >>
> >>It looks good to me.
> >>
> >>Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
> >
> >Sidned-off? Did you mean Reviewed-by ?
> 
> Oops, sorry.
> 
> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>

Thanks, patch updated.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-06-24  8:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-12 22:57 [PATCH] Properly size the leafsize field in the mdrestore_struct struct Adam Buchbinder
     [not found] ` <CALb+jKqYiQYsHdfOBbOhd4bkR1Y_+Qjv4mvyqq8ZBuLoJkyeag@mail.gmail.com>
2014-06-13 23:58   ` Adam Buchbinder
2014-06-18  6:01 ` Satoru Takeuchi
2014-06-23 13:44   ` David Sterba
2014-06-23 23:12     ` Satoru Takeuchi
2014-06-24  8:50       ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.