Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2212lqz; Fri, 29 Mar 2024 06:55:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWIh5w3+VlVGIEtsCZHFIatVDSFZWWKuV/AQNurYdWuGaubLk/tJepxyiHZ3ACom+0FvFdP2FPWJMDixnb62frsjemU/J0FvMictYxN/Q== X-Google-Smtp-Source: AGHT+IH5yHdUeWj0udP6P8e3q3T1MfZ2ARIukVwAdyhfjlRIGNf1HOq00l2hcq3VcwtEb6LYzEgJ X-Received: by 2002:a05:6a21:2706:b0:1a3:6190:ee03 with SMTP id rm6-20020a056a21270600b001a36190ee03mr1883613pzb.61.1711720547048; Fri, 29 Mar 2024 06:55:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711720547; cv=pass; d=google.com; s=arc-20160816; b=C2SGZPX+4QrhKUQkCRC3DF1M0g4EhwuJ4lDX/UVQuRlT9/WzR1sTjw2Rue7E8Fk2Oi gZd3owhN0xZVE/eECcrQelhOVMG3t0jSKy58eZlE4tr4fIXQmJNeRo8WP+2nlxDONxwN YinIIg3S49rPF8kPkLre7RqLwTzuRkJnKxnChw/mGuqdiwnc9KcK40NTPaWANNpfRwDa +QsyHnjPa8GBq7aSzQ9j0+k1VYMWukLeiMvvvfoj6y+6nuPmeINgQTC9yT+933Uk/Ifp kmG8/Bt6DlGn5AZZdGENVGXevISA9ml/FihUUZxEcfHXkOxntkslyGnL+kCSyvaBAhOK 9vAQ== 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=8nZHkxrzTauyifLVjzoRAGhU8D/8kXv7IdcVb/zmKcI=; fh=501z7qcKPHNy10WgpX8NmsXM+WdbuC7cJHePmiZlTgA=; b=yJEjD0RjRTZdjzsEInbvZQlMySYpZSTx5lHoEjyPLXgwB/HjMEdLH1ZBO6awNfD/SY WiMm+dLwnJARakkNN8r9sIw9omIQ5F0+jncwDlpSidXtKOoBXz+fZDJ3aeGLeFlowZVX 9JaDk4I8+8gW7NX9Xkdfpw1IYCtIcs9XHfVdh9CXBEnnnNS1qQ7gn28fpYnqe9cHjhcT NKVsoM5Fq2TOG/i5sYMd5lJ4wuPc6A6qlv0YkVktYXGXb2YazzIvFFw7+CPq0tynOcy9 GTO9ix33yjfUTjSAppPu8jV/tYyCvE3F4BPEzHdTSReoNFKbhjmYyNNS7b+/SmBWEq3S FWeQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W9N7uhMW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124793-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q200-20020a632ad1000000b005e84e725502si3671165pgq.637.2024.03.29.06.55.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 06:55:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124793-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W9N7uhMW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124793-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124793-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E7A3028928A for ; Fri, 29 Mar 2024 13:52:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7F2318B5EB; Fri, 29 Mar 2024 12:42:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W9N7uhMW" 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 AAE71148839; Fri, 29 Mar 2024 12:42:27 +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=1711716147; cv=none; b=MvpxbO6kFxPOIUWBaOkLOrAc8ctNJbmAGTXC18eYrzMZ3+N10ZEcjsD9mxG6d8Y+Cdy9TrrlFK2rpm/q2W/4e3IrJpZ/LlWmJ9hP6OQb1Jre8ybMmvvI9tO+4I0ejyNutXwx0MJUV9H/l0NZxy0Ugg/ojXKdK0ze5KXwEnZrU94= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716147; c=relaxed/simple; bh=CBLJ62ZdxOVQDTLj11F5FJn+stz1NKJMv4S1wqAkH4k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PltzN6gNfH6yB/+q0TIdAKL56jau+Mcp1y4cclWCu2GT7DR9hBB3wUhSMTrkb6PGJofqXdoKv93YR0e3wo7faa4D9WMD3vEczz2cPYZF+4rzK3It6l1GM9ZS1fHFrPRgVYib4mlwxJb4x0XDsjqVDPHUP1xRP4PK18t3Nkn9gqs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W9N7uhMW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE71CC43394; Fri, 29 Mar 2024 12:42:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716147; bh=CBLJ62ZdxOVQDTLj11F5FJn+stz1NKJMv4S1wqAkH4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W9N7uhMWRGVdxWsMQcpoA3S9J4+3M0IlwKl9J6l4c2+tBisLwr7THUaTTM1yqCGKt ucBvxKvedC6H2XpPRZUvoUM+iXd8lww39QshzTnWEQEOUSkKfQygVTNQngbDspaXdg cUXDG0lmMoHQg8n0j1EnxAdHZp/96+Q5L/aiPdhovW/UmJh/vwZxI1wKE+nRZ7qJb8 bZq2ytsSgtXPFWss5wNThSj69cCi8wdSWXizawaQpQPJfTEFvkBfWKX7mJ/gw9rAok q1oFRm2OXm/e2AqGC1Y1E/0Sl8TG8nrs93XI5Fw0gugA7TF5wIEWYvbNOyMg2Z0Cow jy46rxOdioHrw== 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.8 82/98] btrfs: export: handle invalid inode or root reference in btrfs_get_parent() Date: Fri, 29 Mar 2024 08:37:53 -0400 Message-ID: <20240329123919.3087149-82-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329123919.3087149-1-sashal@kernel.org> References: <20240329123919.3087149-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.8.2 Content-Transfer-Encoding: 8bit From: David Sterba [ Upstream commit 26b66d1d366a375745755ca7365f67110bbf6bd5 ] The get_parent handler looks up a parent of a given dentry, this can be either a subvolume or a directory. The search is set up with offset -1 but it's never expected to find such item, as it would break allowed range of inode number or a root id. This means it's a corruption (ext4 also returns this error code). Reviewed-by: Josef Bacik Reviewed-by: Anand Jain Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/export.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c index 744a02b7fd671..203e5964c9b0f 100644 --- a/fs/btrfs/export.c +++ b/fs/btrfs/export.c @@ -174,8 +174,15 @@ struct dentry *btrfs_get_parent(struct dentry *child) ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) goto fail; + if (ret == 0) { + /* + * Key with offset of -1 found, there would have to exist an + * inode with such number or a root with such id. + */ + ret = -EUCLEAN; + goto fail; + } - BUG_ON(ret == 0); /* Key with offset of -1 found */ if (path->slots[0] == 0) { ret = -ENOENT; goto fail; -- 2.43.0