Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1538984pxb; Thu, 16 Sep 2021 09:30:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqm17jaPBfrv8TZ/AYOX2LrRWmFDAS0UXiFIG80Do0IF2CNaPOeH0djyoZtRbC/a4xGNFy X-Received: by 2002:a05:6e02:1bc3:: with SMTP id x3mr4750199ilv.113.1631809808038; Thu, 16 Sep 2021 09:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809808; cv=none; d=google.com; s=arc-20160816; b=oirR5hQs9jED7OjDRbMu+Wfxbl9e3WHTlaDsc51WoC6Fj78LAsjOO8jnZTCzD8R2yp oZeViiscnAMqYKhI1ZW5uip7RG5gcLAUrhJ8I5qqLDWuSSyOojIWr7quwJUxEyGECf/8 Oc3jK8dZtPgcXzMwiT4zNDrdk+VTuL75zluFNKbKgnh3yiWB5T6TbdpX332i50FBsPuU qRrDyfRVXhGHQNIURJvOUEqW1Rg/MyPBJqO3rxbEmpy5+jdiMilq4/hiSNQ95qdwnOjg enMSL123mPZnJDGbwW6tuwJrzbiLnnXny6l4DijSSGGefg7e3ug5wSxNfURyXDRubHzP 7XSA== 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=GLNCTjtQMiXer36Hr/pDa4B0i3cbCZ6YkQE7VlvwICs=; b=sBapPSsqsFJrQ9ZW8YuGYPcWderTrHUpcvJD+jAo6oZCRLVGaB/FtZvnENw72rJZQ3 Rz0Z9wKdN4oKREbujvERaJHoAz4vNXoOh8sjUtPNbtAUJSZJysk3SHZ2SAFOjX7TOLwO eRhe2fHUKZ1Vfk+WvcWoNGwVkl6MxUiVQ0kpKTOP3JGpEnsIAzd7WdpkjA6nK2ic7+tH vRw25hVJYS1Kc6+LYVu5lz7Ffh1qN4DM4eajOzVOM14qI+UbwoxirT2N+CLw6woINKCT l0cfIXzYEPTd8srPZI6sl3dQb3+Z5uH7zBxJPJgbtP8iM8XeK4BFkS7rU9jlMYUp1HH4 cyyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VrMHfo44; 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 ay15si2964480iob.92.2021.09.16.09.29.55; Thu, 16 Sep 2021 09:30:08 -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=VrMHfo44; 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 S235275AbhIPQ3O (ORCPT + 99 others); Thu, 16 Sep 2021 12:29:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:59282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241695AbhIPQT7 (ORCPT ); Thu, 16 Sep 2021 12:19:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6668D61251; Thu, 16 Sep 2021 16:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808844; bh=63kIFkHrFm+wRAiUZlOM//EDuHZOFoI1nV/b2PZYWhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VrMHfo44vccdOcoDUliu0vvjyVXKePkWGMspCtSsldBPl4bqaaNNDKvE0w0KZZZVE lIwPLCnivczeAf+M5D7lpGJ3xQHPHh/E1ZrA+sjGowMnF5HhFxzHSio+S9R4bIPTs3 OKlQPbU5aQztJ7fxYOG5GpYUTgZ4r9lHW/ReDuwY= 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.10 242/306] btrfs: tree-log: check btrfs_lookup_data_extent return value Date: Thu, 16 Sep 2021 17:59:47 +0200 Message-Id: <20210916155802.309385902@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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 f36928efcf92..ec25e5eab349 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -708,7 +708,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