[lkml]   [2018]   [Jul]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Patch in this message
    Subject[PATCH 4.17 128/220] Btrfs: fix return value on rename exchange failure
    4.17-stable review patch.  If anyone has any objections, please let me know.


    From: Filipe Manana <>

    commit c5b4a50b74018b3677098151ec5f4fce07d5e6a0 upstream.

    If we failed during a rename exchange operation after starting/joining a
    transaction, we would end up replacing the return value, stored in the
    local 'ret' variable, with the return value from btrfs_end_transaction().
    So this could end up returning 0 (success) to user space despite the
    operation having failed and aborted the transaction, because if there are
    multiple tasks having a reference on the transaction at the time
    btrfs_end_transaction() is called by the rename exchange, that function
    returns 0 (otherwise it returns -EIO and not the original error value).
    So fix this by not overwriting the return value on error after getting
    a transaction handle.

    Fixes: cdd1fedf8261 ("btrfs: add support for RENAME_EXCHANGE and RENAME_WHITEOUT")
    CC: # 4.9+
    Signed-off-by: Filipe Manana <>
    Reviewed-by: David Sterba <>
    Signed-off-by: David Sterba <>
    Signed-off-by: Greg Kroah-Hartman <>

    fs/btrfs/inode.c | 4 +++-
    1 file changed, 3 insertions(+), 1 deletion(-)

    --- a/fs/btrfs/inode.c
    +++ b/fs/btrfs/inode.c
    @@ -9475,6 +9475,7 @@ static int btrfs_rename_exchange(struct
    u64 new_idx = 0;
    u64 root_objectid;
    int ret;
    + int ret2;
    bool root_log_pinned = false;
    bool dest_log_pinned = false;

    @@ -9671,7 +9672,8 @@ out_fail:
    dest_log_pinned = false;
    - ret = btrfs_end_transaction(trans);
    + ret2 = btrfs_end_transaction(trans);
    + ret = ret ? ret : ret2;
    if (new_ino == BTRFS_FIRST_FREE_OBJECTID)

     \ /
      Last update: 2018-07-01 19:07    [W:2.627 / U:0.028 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site