public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: gniebler@suse.com, linux-btrfs@vger.kernel.org
Subject: Re: [bug report] btrfs: turn fs_roots_radix in btrfs_fs_info into an XArray
Date: Wed, 11 May 2022 15:10:14 +0200	[thread overview]
Message-ID: <20220511131014.GP18596@twin.jikos.cz> (raw)
In-Reply-To: <YnKbzreg3dLw9QTa@kili>

On Wed, May 04, 2022 at 06:29:18PM +0300, Dan Carpenter wrote:
> Hello Gabriel Niebler,
> 
> The patch eb8da5bf4831: "btrfs: turn fs_roots_radix in btrfs_fs_info
> into an XArray" from Apr 26, 2022, leads to the following Smatch
> static checker warning:
> 
> fs/btrfs/disk-io.c:4453 btrfs_cleanup_fs_roots() error: uninitialized symbol 'i'.
> fs/btrfs/disk-io.c:4453 btrfs_cleanup_fs_roots() error: uninitialized symbol 'grabbed'.
> 
> fs/btrfs/disk-io.c
>     4408 int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info)
>     4409 {
>     4410         struct btrfs_root *roots[8];
>     4411         unsigned long index = 0;
>     4412         int i;
>     4413         int err = 0;
>     4414         int grabbed;
>     4415 
>     4416         while (1) {
>     4417                 struct btrfs_root *root;
>     4418 
>     4419                 spin_lock(&fs_info->fs_roots_lock);
>     4420                 if (!xa_find(&fs_info->fs_roots, &index, ULONG_MAX, XA_PRESENT)) {
>     4421                         spin_unlock(&fs_info->fs_roots_lock);
>     4422                         break;
> 
> "i" and "grabbed" are uninitialized if we hit this break statement on
> the first iteration through the loop.
> 
> roots is also uninitialized.  This error handling is badly broken.
> 
> If we hit it on the second iteration then we are also toasted.  Double
> frees.  I think.  (Trying to send emails quickly and then head out the
> door).

Thanks for the report, this has been meanwhile fixed in the tree,
Nikolay sent a fixup that replaced break with return.

  reply	other threads:[~2022-05-11 13:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04 15:29 [bug report] btrfs: turn fs_roots_radix in btrfs_fs_info into an XArray Dan Carpenter
2022-05-11 13:10 ` David Sterba [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-05-16  8:04 Dan Carpenter
2022-05-16 10:39 ` Nikolay Borisov
2022-05-16 11:02   ` Dan Carpenter
2022-05-16 11:45     ` Nikolay Borisov
2022-05-16 15:18       ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220511131014.GP18596@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=dan.carpenter@oracle.com \
    --cc=gniebler@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox