Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2373196imu; Thu, 24 Jan 2019 11:36:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN5GP4bKhte+52UgkQnRgmZPzrBC36YBfADNBqVDqfbatMKRMMpLGzPw8yuvDFh6lH1vB5mi X-Received: by 2002:a63:f34b:: with SMTP id t11mr7150864pgj.341.1548358587366; Thu, 24 Jan 2019 11:36:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548358587; cv=none; d=google.com; s=arc-20160816; b=IzPgtD8aREnpsPJMg6scLf7iC9+p9Vb2UufIRxKIHB+y0TDKdKebJ+TuSchPy65kd3 ixsRHBsbyFHGO/6j6E5uwHJ7y/EU7Vo2I/SCVy2ybhlD+5giWehL72YvCPyohBnv+Dbq cQ0svIGnJQd/7UmOZwM5sfUjhex4njYeWyzXi4hLDYAbmN0rMDKYhevT67YptQ6QADWE rXbWbHlGzqsEtfFFHeOoHCyMskQQgGuhnw9hPMHqGLdwJLM5MEQBoOuPXnJf+02LX8ox f5l+1GFwsOA0N9z87iI6UYUWNzCScunpWCaI27PcfX7O7xVm2QPxLePQMBJ2OojIac4A 99Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MH1qFrsjVB5ajyu9z2qf1n3da5/sjxYdxAZqaj02Jk0=; b=eaq8ZCmzPwgFrN51TMvwd5CfZcPwDiht8W9btlYUiB8ORiGD5d5xbQZCJvOm2lGzhG xRIcJUFXzjI1R8xTBcdugtM+rPvdnEtxLnwIEdc0e+kCjGMMGYSHosCYQObNvWscd8jD 8SDPRA99CFPQmOLlKq/NtOBgBEr++p3IjF+GFZqJEoDZpmfHU1XdSsTr+l9+ahDto5gX Ru0nGORfF9TzYemfaW1KALGfVzwbe/GgQu/IFi3Oendstmhh8aGvUgIPWlF5SV4/pBE6 Lgfywps01Lq1GZJdjbg6U7m59CNs1hXC+A37tPCttXUqMS1XZSGfuc+i68+IFS7AMxk/ MHYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nMZDCR9A; 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 t12si22521169plr.311.2019.01.24.11.36.12; Thu, 24 Jan 2019 11:36:27 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=nMZDCR9A; 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 S1732101AbfAXTd7 (ORCPT + 99 others); Thu, 24 Jan 2019 14:33:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:33734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731678AbfAXTd4 (ORCPT ); Thu, 24 Jan 2019 14:33:56 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 34CF221905; Thu, 24 Jan 2019 19:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548358435; bh=q8gvVrYg/+Iq88f/k0SIPMx8MYtOKWuAnhJJbWk8s5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nMZDCR9A55/lCDs4ASw6zxS/Snou/4LELaxMmIUMW7tDzRpnFO5y7LT+BxG3rxSMu AJxXi00INMjxzPVveyqPCMDxNutR9wDFSa7zHVJXf2zNVJl2hixYnp1qVz0jbewwbf COJaTrj2FeexMMCjCw5CSD5xqbLOV5OgKQoDCvIw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Thumshirn , David Sterba , Sasha Levin Subject: [PATCH 4.14 36/63] btrfs: improve error handling of btrfs_add_link Date: Thu, 24 Jan 2019 20:20:25 +0100 Message-Id: <20190124190159.306977550@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124190155.176570028@linuxfoundation.org> References: <20190124190155.176570028@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 1690dd41e0cb1dade80850ed8a3eb0121b96d22f ] In the error handling block, err holds the return value of either btrfs_del_root_ref() or btrfs_del_inode_ref() but it hasn't been checked since it's introduction with commit fe66a05a0679 (Btrfs: improve error handling for btrfs_insert_dir_item callers) in 2012. If the error handling in the error handling fails, there's not much left to do and the abort either happened earlier in the callees or is necessary here. So if one of btrfs_del_root_ref() or btrfs_del_inode_ref() failed, abort the transaction, but still return the original code of the failure stored in 'ret' as this will be reported to the user. Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/inode.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 909f7ea92e0b..7e288510fd2c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -6594,14 +6594,19 @@ fail_dir_item: err = btrfs_del_root_ref(trans, fs_info, key.objectid, root->root_key.objectid, parent_ino, &local_index, name, name_len); - + if (err) + btrfs_abort_transaction(trans, err); } else if (add_backref) { u64 local_index; int err; err = btrfs_del_inode_ref(trans, root, name, name_len, ino, parent_ino, &local_index); + if (err) + btrfs_abort_transaction(trans, err); } + + /* Return the original error code */ return ret; } -- 2.19.1