Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp461225pxb; Thu, 9 Sep 2021 05:07:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBBmbt0jciRKKRN0GB6UkNLplXlVJC7dXZV5MbS5Le6wwaC6rPYhnAOw0RnWOXKMkQ5ZbB X-Received: by 2002:a02:95ee:: with SMTP id b101mr2484846jai.96.1631189237658; Thu, 09 Sep 2021 05:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631189237; cv=none; d=google.com; s=arc-20160816; b=hZsfNOS8MnO6zgSEzMKVNHWqKITMK1WRcMGb+XjvwJmvwNswup22b8rl1fZbQycGNX Ar4nDXvIJ3/UV5835J7KMAM5XKAhMcpjw8Q0z8dZ647HAytnZGykZr2M1ZDi3bemQQw+ G68E/SdgOlxekU+5l7gDuHX7oXdm62j+20nY62YsK3DEoe2yMwl7ybG+raZ1g6hf7Q4H VdNv1hkfm5P1QTeEvYQI9KIQ13UeTAElzfLp3qE3pVDWFJTmyNOu3E1uvIZA+0F1CVJb 9Q8Q6TpdvDomaAATJQOvqyl2Y/N6eZPcpkDMPWFklfdsoIPC6QSaGEwbR2frODQz0gp5 WNmg== 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=H1kJtdaYsKhH49wEVfzfInU7VtToV4VWs1ZeRp1FAzs=; b=mHIJ9K58UcPAr8SDbHhNpU0OU+gDtaoK9wh6D0r4xl/o/7X21YK0EVJKeyxh4vVW+s sKvPCqPKzqFLEBrUFHR6GvGAD8isBqiq2TF0nC3+UDtdA30x07ctQODcZU51k64hjvkr 9U3aA93XxpiG1jZEXreObRXWt6dSxqQDAes+KwDpVA8xnZxBrgnyOJt4zMP4N0hLW/41 HTwdPX9P3M5acnuLM1MbTCG/ybTyCP98VBvNoVYNLknZRxSfd+O0Y8QsgLl/v9P2PpUK y9lNSrlDAMjR/jW6dI/lbu4LOIAQ0iBl8OgANWYh67B3ovB2h0P5U5sTfc7JDFjw6aKS dLUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DqckzEbJ; 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 m82si1294287ioa.74.2021.09.09.05.06.55; Thu, 09 Sep 2021 05:07:17 -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=DqckzEbJ; 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 S1346664AbhIIMDd (ORCPT + 99 others); Thu, 9 Sep 2021 08:03:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:34520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245120AbhIIL4k (ORCPT ); Thu, 9 Sep 2021 07:56:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E19EE611C6; Thu, 9 Sep 2021 11:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187923; bh=yIReAnM4BmjVOMDEMIAlM6cRmVcC9J3/OSMJ0cyLO08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DqckzEbJ9EVUrFWNc6IM8HBvqLxVbGZNF8BR8mhpeWFPOJH4xvJnBXQuM8Q3bpOer GCj8KAeofq/vavcmYLeAwYyTIpbwJqzUIRc7Vz68fLIHk1WBuZqW5FFNHkNMZ+jvY6 we8SjaIU4xd9aM3dfGyI2+5Z2dm/g4/RwUlcpz3lEYeG/AD8V9P5fCSpc4UUqfxGTu xDsLstiBDf3jGTpV6amRuN+hcm1EaLZKXlTx8h2rtH0iUoQWUKF8nNCwLnCXzqbyAm QmtUGcfjI1M28JUkzR0oesJrBMiUeOBfI0zZv/YRUfWgpCxSikgzdmdaKromL2vEPJ 1Jrl2n4Wob9iw== 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.14 197/252] btrfs: tree-log: check btrfs_lookup_data_extent return value Date: Thu, 9 Sep 2021 07:40:11 -0400 Message-Id: <20210909114106.141462-197-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-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 e6430ac9bbe8..7037e5855d2a 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -753,7 +753,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