Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp502486pxb; Thu, 9 Sep 2021 06:01:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwggcsrekFVotyAp6ohMmcCT+RggX2Z/pGaAlo+f61/ey4OFULEzOJaa9PBll/1tc9ZYfpk X-Received: by 2002:a6b:6a14:: with SMTP id x20mr2458667iog.177.1631192485314; Thu, 09 Sep 2021 06:01:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631192485; cv=none; d=google.com; s=arc-20160816; b=NNCQC3faSZJGiw4pkncq6J+jnU/GLqnToKpduxwVo98RZ72e0e2ZIQX39l11x8DemK l1gSQoMtoJRhjW+GNhhzw1QysYJFoM5MgepmHdtv0nOjGeUzE9X5PmwdR2jgZu7B/mIf YDPAWgkBD4GSrOnn3f0UMgz+hst7xElWdtAMI+20TmlzD+QkE9vqzp+Zz1Q5Fm/NTeze whZ0/ud+dqk6KizKl7QJE0tAnxMTX/IR5vbKJw5p4oucYfp5yhAjeII/OSNJgw6miDCH WMIz9Mzo2l+D24ChSWRZq8ITbZIJRvapiJhdLiuozUFRW6BuP/k+OAEwBAbsFJ9yMcuX v7kg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GAV0a99SAJYzxLeUFl/faR68BpP97NKb6pIAYmKFGmg=; b=b3v0bGQ53hgMRM0GE4dI1hntf3KLkXL9/tDf69cKSfllJ3RTs44MPv0QQtGg26WwLq /BvN9fep+ExidcHQ7fvAh22bL9BfmgrK25/iWS+xcRCBqfhP4Rw7TozLv4Zn0A5yB/zZ YpvcOudqfhwzQHyAGiRQ1o9LrRctE2TaQY96mRqzjAF26e5i93mKhZA6+h5O0Ub9edTC /M1L6JMda49KVpXmblHKbDUXrvLn8sYe2OmnArZeKQxPqXgXzvSoSbPGBEbVN1yg3C5x r1/xbH4WGBaQVYR4NTqwKwt8MTdGrvQcSJFChww59SR1jM8R5OXMDrHt6pb1acxL1IL1 DKeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Nx0xJTJZ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q20si1709399ilj.61.2021.09.09.06.01.03; Thu, 09 Sep 2021 06:01:25 -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=@kernel.org header.s=k20201202 header.b=Nx0xJTJZ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345873AbhIINAl (ORCPT + 99 others); Thu, 9 Sep 2021 09:00:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:41728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355013AbhIIMtW (ORCPT ); Thu, 9 Sep 2021 08:49:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 44ADD63224; Thu, 9 Sep 2021 11:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188613; bh=LhVQYxSijWb2ticR9mMoZ1pEGPEgC7Plw8vjUmGB1sQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nx0xJTJZnGMbyTyG4SJ143BTNH+VVxEZNOMpHUS8/ndTcOOMZCbzZFlkIVsgER9JN 5xGYMPJLaZbHfJZVD5qI4NullfKiNpe1Tthbto6KSYzLX+/4qGxhBOI8iV5br1bat3 5+WZ7ITVCFr3skE2QkRvDrUhP63hsBXnIT9/7KvD09Q+yVHxZT0ab8du2iN+a7slUF Xsv5Mr8Pj66Vly1kYkri2omAs+3dzM8jwPgwTClbh0HbskeMr5RTj/g0ZW5eQZDIti yz0dUPA5EmhsHHNA2HydS9lwLHuP1c/bGGE8GhoDTtPGAO+6KYz8y7t3BuPVplm43h xcdpder0VLY9g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Marcos Paulo de Souza , Filipe Manana , David Sterba , Sasha Levin , linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 083/109] btrfs: tree-log: check btrfs_lookup_data_extent return value Date: Thu, 9 Sep 2021 07:54:40 -0400 Message-Id: <20210909115507.147917-83-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115507.147917-1-sashal@kernel.org> References: <20210909115507.147917-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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