lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAL3q7H65GG54XcOOhn1Xc-4tMBO+NuLKrgC9AiFEY8=iqwGn+g@mail.gmail.com>
Date:   Thu, 16 Sep 2021 10:30:40 +0100
From:   Filipe Manana <fdmanana@...il.com>
To:     Baptiste Lepers <baptiste.lepers@...il.com>
Cc:     "Paul E . McKenney" <paulmck@...ux.ibm.com>,
        Chris Mason <clm@...com>, Josef Bacik <josef@...icpanda.com>,
        David Sterba <dsterba@...e.com>,
        linux-btrfs <linux-btrfs@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] btrfs: transaction: Fix misplaced barrier in btrfs_record_root_in_trans

On Mon, Sep 6, 2021 at 2:38 AM Baptiste Lepers
<baptiste.lepers@...il.com> wrote:
>
> Per comment, record_root_in_trans orders the writes of the root->state
> and root->last_trans:
>       set_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state);
>       smp_wmb();
>       root->last_trans = trans->transid;
>
> But the barrier that enforces the order on the read side is misplaced:
>      smp_rmb(); <-- misplaced
>      if (root->last_trans == trans->transid &&
>     <-- missing barrier here -->
>             !test_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state))
>
> This patches fixes the ordering and wraps the racy accesses with
> READ_ONCE and WRITE_ONCE calls to avoid load/store tearing.
>
> Fixes: 7585717f304f5 ("Btrfs: fix relocation races")
> Signed-off-by: Baptiste Lepers <baptiste.lepers@...il.com>
> ---
>  fs/btrfs/transaction.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index 14b9fdc8aaa9..a609222e6704 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -437,7 +437,7 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans,
>                                    (unsigned long)root->root_key.objectid,
>                                    BTRFS_ROOT_TRANS_TAG);
>                 spin_unlock(&fs_info->fs_roots_radix_lock);
> -               root->last_trans = trans->transid;
> +               WRITE_ONCE(root->last_trans, trans->transid);
>
>                 /* this is pretty tricky.  We don't want to
>                  * take the relocation lock in btrfs_record_root_in_trans
> @@ -489,7 +489,7 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
>                                struct btrfs_root *root)
>  {
>         struct btrfs_fs_info *fs_info = root->fs_info;
> -       int ret;
> +       int ret, last_trans;

last_trans should be u64, as root->last_trans is a u64.

Other than that it looks good to me.
Thanks.

>
>         if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
>                 return 0;
> @@ -498,8 +498,9 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
>          * see record_root_in_trans for comments about IN_TRANS_SETUP usage
>          * and barriers
>          */
> +       last_trans = READ_ONCE(root->last_trans);
>         smp_rmb();
> -       if (root->last_trans == trans->transid &&
> +       if (last_trans == trans->transid &&
>             !test_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state))
>                 return 0;
>
> --
> 2.17.1
>


-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ