Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2972601imm; Sun, 1 Jul 2018 09:27:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIG6ydi21nM00JLEnGplEEAa4vxtLZIPbOJBT/1R42UIkiiHs5CEFMQoiYN0hHr79eiMlNG X-Received: by 2002:a63:7b1b:: with SMTP id w27-v6mr18274664pgc.199.1530462452287; Sun, 01 Jul 2018 09:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530462452; cv=none; d=google.com; s=arc-20160816; b=ugiTRAYtI8mIeRRNObwBS4JNR0I+c/jlan/90x1plqnfS8ZMp8nvgUla0qK2Jy8kLE a/J4SdhMcb9Pf0uiz/RMv/nu8vnVBc/ju896vG/jVAvwHj7V1avzmaDGulBhC3Wgt2ys cN66PTkyf5RkNR09zWXCHJIo/ah+RdSyYsTfSrXCMKuhbXoVsq0P+RwBbtUdQTfRB4yj riG1dee00ql+fEtDxPHyRP01x/QkPlhRjPXbyPe+Khywgi9mPDJOboIv0/gkcXw929N7 G5uyg5WrShxSs9O8rQHkPKNbn4MYWdyofd2MtzZSNoYuuriUHcUm+M3y9dDJPtbFC7da j4jg== 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=ieX5qr9ETMxddOugVuyTzklqVMAZtuYq3y3vwgdq6UA=; b=lMnr1RVJhlOgY5CCkXkDppyolB1EdzAmg5/f3ySwsIDptMu7vM9SI3PcGOjdYZe8Bp mywF4sNrOam1c9w6q1ULs/me2UPrl0CV4lZM5D5lssMy3H4m8asj22Sc5E+n1/T2Wa7E DAQZvgMZuaxW4vreziHT8XFqTzVv/bSMqcJr0Ug3ul+Bq5XuObA2fQLr1tMAX3DpMSi3 mypcGhVcahxXaVVsm679UbtndHO8lEsHoBNr1WuHS7ztvqK33/9gqlr2Ubi+Sh0JAWaA Db7MBpJFC62nJC6YKv4wu+T9KScMGFKOy7x/AWbyv1rPxyZyAZdgQJJTDQkgI0rEDnmj S7CQ== 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 i184-v6si2458479pfg.250.2018.07.01.09.27.17; Sun, 01 Jul 2018 09:27:32 -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 S965182AbeGAQ0m (ORCPT + 99 others); Sun, 1 Jul 2018 12:26:42 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33912 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932678AbeGAQ0d (ORCPT ); Sun, 1 Jul 2018 12:26:33 -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 2D09AAEF; Sun, 1 Jul 2018 16:26:32 +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.9 053/101] Btrfs: fix return value on rename exchange failure Date: Sun, 1 Jul 2018 18:21:39 +0200 Message-Id: <20180701160759.265134383@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@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.9-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 @@ -9561,6 +9561,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; @@ -9751,7 +9752,8 @@ out_fail: dest_log_pinned = false; } } - ret = btrfs_end_transaction(trans, root); + ret2 = btrfs_end_transaction(trans, root); + ret = ret ? ret : ret2; out_notrans: if (new_ino == BTRFS_FIRST_FREE_OBJECTID) up_read(&dest->fs_info->subvol_sem);