Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2566362lkm; Mon, 20 Sep 2021 18:53:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXu8BQrDMkqTCT/7WOWLqMzZVU7BsQNsdVcO4nfRgaQkqc1XvbsTWFDSwE3NOFw+ZKCW/X X-Received: by 2002:a92:cd07:: with SMTP id z7mr19415645iln.15.1632189193544; Mon, 20 Sep 2021 18:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189193; cv=none; d=google.com; s=arc-20160816; b=GXYb7/NMNiebBpUq/SyzioK1ozTklSnyMg/jyMC/0iZpWKN/P9wg4I47MH9pMWAxms mR6dOT8GR0IjAwVa9OHOHu/15lkTV19VBHCWlR1qatmObMd/qExTWzh2yG3o289Eg3i5 ke2jrqAR3KFCUjbkGoofneBC39mwv62hELdZf5wEJXDj2i/dnI8L0mUp1bBmuYNvWwMN jKaymRWlU1JywSrkVy80iEZIwvjshvomJBx9pWiHL17zWq9Ed9xbLGEQPST8xynsNXid PT8WCCk6gDEMVYz9F72zwquZBXVOADpDw3F36AflWXdAbXhX80Pt3dQsrJLKNdt12Wvv Eb0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GAV0a99SAJYzxLeUFl/faR68BpP97NKb6pIAYmKFGmg=; b=KboEXdygERXwjywhqvAzGN89Vj78aR4oK1ggcVn/ytDWHwTtH+4Bk7z1PqMBlB6nEe qvE3Hq6CW/YEndMUkXewyga4PT9bUtPVYXJt3WvVwzgbX2CirHdjdkHCGM0w+lEOx04l D1HSsk4v9jwOu+VD2WjyJqFLekMBgE0W2W8ccOGVAe0tjl9p4huBNfyeFckw0+0pfCcO qBkagBSE0d01SAAK0J6m3xdwl0RdvBVo7W5/OASCBHjQrZV0FItt8zEVZK0wI74ZY1Qg Xx3klnRKUcjG4qWoqcKtpVZu7uE3VCbe8ojlomrbd/fI249POMQ1ECx6zVYtdrYL7K1t fgcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hPcnEdZ/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si2202059ilv.110.2021.09.20.18.53.02; Mon, 20 Sep 2021 18:53:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hPcnEdZ/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376896AbhITSRC (ORCPT + 99 others); Mon, 20 Sep 2021 14:17:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:35792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376336AbhITSMC (ORCPT ); Mon, 20 Sep 2021 14:12:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DB4B06327E; Mon, 20 Sep 2021 17:20:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158423; bh=LhVQYxSijWb2ticR9mMoZ1pEGPEgC7Plw8vjUmGB1sQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hPcnEdZ/D557T4Bk7suhwM4QJbZxapP6Wf/AzzttbcEW9KusEk3//FVf0VxLkbkcw FSzoQUwdj+lITLlU0sQTaPmAzXLsx62/+bLPyfeCmm1ZvfHbMRHzUfQELfsMOPw9QB T3eQ3nv8+RDKubpKUvsMpBkm08DGruCrWzSFdS6E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , Marcos Paulo de Souza , David Sterba , Sasha Levin Subject: [PATCH 5.4 148/260] btrfs: tree-log: check btrfs_lookup_data_extent return value Date: Mon, 20 Sep 2021 18:42:46 +0200 Message-Id: <20210920163936.142825719@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marcos Paulo de Souza [ Upstream commit 3736127a3aa805602b7a2ad60ec9cfce68065fbb ] Function btrfs_lookup_data_extent calls btrfs_search_slot to verify if the EXTENT_ITEM exists in the extent tree. btrfs_search_slot can return values bellow zero if an error happened. Function replay_one_extent currently checks if the search found something (0 returned) and increments the reference, and if not, it seems to evaluate as 'not found'. Fix the condition by checking if the value was bellow zero and return early. Reviewed-by: Filipe Manana Signed-off-by: Marcos Paulo de Souza Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/tree-log.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 5412361d0c27..8ea4b3da85d1 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -719,7 +719,9 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, */ ret = btrfs_lookup_data_extent(fs_info, ins.objectid, ins.offset); - if (ret == 0) { + if (ret < 0) { + goto out; + } else if (ret == 0) { btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF, ins.objectid, ins.offset, 0); -- 2.30.2