Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3004358imm; Sun, 1 Jul 2018 10:06:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIY2Ln2ix9K9te2MLMahgMc6133nZtj23OdF0C0IJkViJCAZnY6Tqgw43W1xe40fIWY0GRN X-Received: by 2002:a65:6689:: with SMTP id b9-v6mr19033289pgw.326.1530464812666; Sun, 01 Jul 2018 10:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530464812; cv=none; d=google.com; s=arc-20160816; b=ognSe+XPcROukBfhguZOz8KZBjTL1kZGrhxGHpjKTtU86BSRuhIHRxqk3FYwKSCYKH 1IXdxlu6fupTKyPOmX4S4ATp0d5KdIAyTV1X4Dp1p0GomB+n9eeV1Xdc229l2Thel5V8 8kXbEraY3YnXdZPzqPUCsuGb1TVrDif9lDtrwaJVS7MmyEY1LCuz+j7QTC6Co/LU1aJm ePC3LC4fdApz1Xd69YWy7qZnYcj5PsIoYIALbpIwFQOdUHVw9NO7wFE/oWaEUrHFHBRq 8EndRrYHT0NEDU7qtoP3qqAZGhYAFgmav80ISenCiYH+b6kWXRUTjszcmSEjo21hYd+G HZYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=lgnBUOkmad/GvhjPy6B1BGIw4gosScFIAiSMOgSz5pY=; b=1BtjitZBGv2FbXFTlXhlLzAh3hrSq8A2eaX9J52TeCIYdQMQ1zdktv7I5udu8QAVWJ vnobC6FdsobAPOpjop48nTwKzuvYxNk2ROwNa/Xb7XjLtCg0ZYoDWOo/QbK+R+/3nCKJ uR7w4/SIw/e1PVt22wW9fVTKSYiYv4ssheRyPnhPRQ3ah5lOAYGbr/DWBYq8pLSQBH8x 4DWArko4IZVp+H99OU+7jkAnCiVEJZpmoB/g+lyZDBEOn/KhgS/9aakvdiFoAvtR5ix7 hhDIw+xWXSWhbVC9kQ3V7b6SCnwJivIOQ6MCObU8pjGqkA2gDM/1omLJw+UMYMBCzeU+ DTdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1-v6si12619207pgs.221.2018.07.01.10.06.38; Sun, 01 Jul 2018 10:06:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753562AbeGARF6 (ORCPT + 99 others); Sun, 1 Jul 2018 13:05:58 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37622 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031260AbeGAQmX (ORCPT ); Sun, 1 Jul 2018 12:42:23 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E5810AA6; Sun, 1 Jul 2018 16:42:22 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba Subject: [PATCH 4.17 128/220] Btrfs: fix return value on rename exchange failure Date: Sun, 1 Jul 2018 18:22:32 +0200 Message-Id: <20180701160913.683036142@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: stable@vger.kernel.org # 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; out_notrans: if (new_ino == BTRFS_FIRST_FREE_OBJECTID) up_read(&fs_info->subvol_sem);