Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp34010lqz; Fri, 29 Mar 2024 07:47:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUwVaoThdOrBBGUpGZnEPN6J6cfkcnYfSEwLfsx8BTuFtLpv2zzRgBWv3hrULD8cAkcW5cgwgIoZjQFQ4lQavq2g6+hKeUJgeC+VKheHg== X-Google-Smtp-Source: AGHT+IGT2QOaUHkGCnZpJKLsbNTFQJa1OQv0e0UcnI3naDkPWFGWOeHfW03PWLoHZVJhlJBfN+qh X-Received: by 2002:a17:90a:dac3:b0:299:1777:134c with SMTP id g3-20020a17090adac300b002991777134cmr2239499pjx.33.1711723640282; Fri, 29 Mar 2024 07:47:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711723640; cv=pass; d=google.com; s=arc-20160816; b=d6Ja64o/Rf1ziH9qVyjyOVbILtgPAU3L+UTC59C6zHyUSkyypbKd2YoLId9cEGDinq jEVWLw0199uK+UTrj+87YUiSKaQaiRNOhWxSK4dL1hNAeSgRT866TyG+BlauLCQr8WTe p14pvf8BIvBHUUjku5bSfqorL7D0tVvA1zuXgUuNl+hQbv06XvvUoh0MLNylg/Vw/8Os PPCkTZL6PY3pG8dYGlCAyuxJBbybru4Ghl9Mdet8D1bGnxAfqbnx6sfZ4yZClA5+kUIm gfPXn20N+tDf5s73Chj9ahGUZ1EP6UcasmJzZJy52PAV5Rwr4BIKupD0F7FwhHvSJysx +2sw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fJ28CCyQbaNiEt/f971ovUmvHimGPxztVl0xPhTVMFE=; fh=501z7qcKPHNy10WgpX8NmsXM+WdbuC7cJHePmiZlTgA=; b=tKNazGtICqiIzS0gkO7GPRNTDofO9YL0Lv8/Gv2ZsDp2VnkVaDBab0FYzlRY7M2VXn xu8PgMV5SLS/ZanWQwTxcBpU/2KiWby+0IKke3qIdL56f45hbt16CFcwn7qc9TLKpcXH l+TPrGLY7MEBU4/d5h9bfbqYPiA9PCDSENvIi9n0Q98gEQWyGwFUQz/RvPUNWNN+77Km +VkoDsBSqQ3vWGrkfGba0VGPmwk/HkHWLnvCvT2yGpecqJXrbOOC0O02mN47N5K2OOoO o2jy2oa3EU9K5CnLefCkQrv57im3QDMOD+2f7Gvt2ULH3x7wrUBYBAMeKWmRH7G3tW6Y pMhg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DEsHjt8Q; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x14-20020a17090a46ce00b002a2188d3436si1074960pjg.8.2024.03.29.07.47.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:47:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DEsHjt8Q; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2EB8DB2655A for ; Fri, 29 Mar 2024 14:14:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22D8F1D1D59; Fri, 29 Mar 2024 12:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DEsHjt8Q" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E82514A61A; Fri, 29 Mar 2024 12:45:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716321; cv=none; b=nrjSzo4RBnSXFQhxWtEnqdP7iFv8t/qQiRm4rB9W3TZU/NhSifDNBncLC/UpFr+g4EUE4nEv6IHeeCo6+DCxbAHqo40gUfEd5JXXAnTDiOXD7kFbX1MZ96gzzvxFNV4/cpMYnJhy/8NomvMBbczPec6S0MZ8AXyMyH5WElr9ixw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716321; c=relaxed/simple; bh=l3Psi5Y188FysbyMVKHvE/2s4Z+BDxi15ATKpUq23kI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LbHsNJpRAeIN1ErNgMicwpN+N+L9yATfl62o4GVXqCb+Yk6V/pZedXDJlWZgeZX1jrzKPKmqQ3M3/EFvwuR1iMuCy07biTcPdR7e/dFEZ7cGQGtcbfcew7XK4G3OaPhajjrvy8XQraPZVQNJ4xXSLlsJz7p+eBHdEesTJ4bwcEU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DEsHjt8Q; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BC65C433F1; Fri, 29 Mar 2024 12:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716321; bh=l3Psi5Y188FysbyMVKHvE/2s4Z+BDxi15ATKpUq23kI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DEsHjt8QJlbJFhOHB0F52LIPOL/sPrz4z9eDqoiVMZwuGonhEwrVpB6sqTRTYtniw mGOBk3+ZN+f+LOrrxYMirHqIclfrkWcxKpz1Tv8r9Ntlmbz/GNWMg7uBGyfVlExcAz xl0uxldxdVwC4gR4RXMxAViBF+h4VF60JEVnVzcycbZnh7GzWiuevCdLH9OwsWLuRZ eMtjJExOzRCLmLzui5firCl01MDJKcA3AYPx8k6diWRJogbuWRRAN1UNy6fcJqZlom YUWj+hs/CXfONEQtfck0dWoA1n4V9zg7tuSXCKfsl0pQ4pY8SyM5YJtm+7ZpLP/cSs +iCqk3H8m8+Xg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: David Sterba , Josef Bacik , Anand Jain , Sasha Levin , clm@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 61/75] btrfs: handle chunk tree lookup error in btrfs_relocate_sys_chunks() Date: Fri, 29 Mar 2024 08:42:42 -0400 Message-ID: <20240329124330.3089520-61-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124330.3089520-1-sashal@kernel.org> References: <20240329124330.3089520-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.23 Content-Transfer-Encoding: 8bit From: David Sterba [ Upstream commit 7411055db5ce64f836aaffd422396af0075fdc99 ] The unhandled case in btrfs_relocate_sys_chunks() loop is a corruption, as it could be caused only by two impossible conditions: - at first the search key is set up to look for a chunk tree item, with offset -1, this is an inexact search and the key->offset will contain the correct offset upon a successful search, a valid chunk tree item cannot have an offset -1 - after first successful search, the found_key corresponds to a chunk item, the offset is decremented by 1 before the next loop, it's impossible to find a chunk item there due to alignment and size constraints Reviewed-by: Josef Bacik Reviewed-by: Anand Jain Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/volumes.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 722a1dde75636..18b12cc4df68a 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3352,7 +3352,17 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info) mutex_unlock(&fs_info->reclaim_bgs_lock); goto error; } - BUG_ON(ret == 0); /* Corruption */ + if (ret == 0) { + /* + * On the first search we would find chunk tree with + * offset -1, which is not possible. On subsequent + * loops this would find an existing item on an invalid + * offset (one less than the previous one, wrong + * alignment and size). + */ + ret = -EUCLEAN; + goto error; + } ret = btrfs_previous_item(chunk_root, path, key.objectid, key.type); -- 2.43.0