Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp28827lqz; Fri, 29 Mar 2024 07:37:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUh32i9K4Gr5VbdxEiBn8ck875weQ0eFmd4pqteCzjUODURVyZ+y8sIugOGmuxw1uCzpeIovzgzN7GblNigdP/qsTIporkziTzkRK6SqA== X-Google-Smtp-Source: AGHT+IE8DcP4bBFRqgSvIUrCD7XQOKL6EBSo4gbNdIbksDsCJ3CMhXWBCEZu0v3/vqRbAfmW75DO X-Received: by 2002:a17:906:9904:b0:a46:53e9:aef9 with SMTP id zl4-20020a170906990400b00a4653e9aef9mr1497737ejb.65.1711723024522; Fri, 29 Mar 2024 07:37:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711723024; cv=pass; d=google.com; s=arc-20160816; b=BrK11yBtowKn1+gYh1LZdI4zIgaa5I/96AqWrYSLztA6O1omMevTBEsOWg8Rqzv9Fn 0W4G2kmL1A0C6d1ju2/6zpP3xhkq+p15r1UdbYa+76U9VfCFPYCTHT4/xGD3lRqpqdDi iMqtCKsoabdqL/1r8pow3NKGwPbD0vBM/LwgUXK6us+S5IgTjXjvwWVpzAQOgZ6oZY/P ueW0XUCZhKLJRYr+CWxtbK2EaaUk3ZnoMgNiGsczwJDMxp+kOK7kt5iNN3hcixWKHp0V l3UkoAVAG0HiD5KvgWot8mVECuboXh7COFBxASnx6ym88ETbZtzYLC8SuRJQroUbEt/C 87qQ== 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=gpHY0vGisAHoUXBVPGSxE+y3q+OoLnKX5l3Fdxv7LEA=; fh=501z7qcKPHNy10WgpX8NmsXM+WdbuC7cJHePmiZlTgA=; b=RxF+B2yAOxtGXQzBnZ129k7vweOiDIRfGSHCs6ycwwK7wKuDaIsRF07owN4TD6C9Dz 8ljrZVtvpOq7sWlURB+k3ORcjrnuqby2e9hWfxOQ9f2PtkJKs8lIya426O4jHZGvnBZr iGy9L3EAGUWcLCmorL0bghhB7oz75jAfmA7zcVla5AGlhy6lN+6JIBri5GC2e21IY1nb 9R0dXTlDKT5tSpoKSki4oXjMF998DLZirhhoPURJ8eXM79NOgC9miOevpCVn61pnHxah vLSkW/H1YyLR7dakGU93AV47nfss9bkxcm+20Z8tekp1+2ehU3Lns7WUi0MF95L23so2 L+3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=X2+5lUfV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124925-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124925-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ku16-20020a170907789000b00a46b8c85631si1856701ejc.1014.2024.03.29.07.37.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:37:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124925-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=X2+5lUfV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124925-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124925-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D1BDF1F2BAD2 for ; Fri, 29 Mar 2024 14:27:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D9ED1A3388; Fri, 29 Mar 2024 12:47:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X2+5lUfV" 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 C20B21A2B93; Fri, 29 Mar 2024 12:47:18 +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=1711716438; cv=none; b=MEvyuvnl11luTP4H3Bq3NfuYFkcUib34ArnFx8R6NqgUsxBycEINZtyMo6jcsxM6pgMZFp3eN2IYOjZuA8S0LKYmlozbkJQuMCw2rUw1YbWolPOVQYtPmlFotpNc/hUoYCTBU6TJl62zFLcwG57W2A82b2Nj3UGwR9OJCeY3fiY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716438; c=relaxed/simple; bh=d5DArg/0hqWJGePnz1+kSxWB/3LWOiBxH1jRuA5RlpU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VbH0ZwoeuhxlP4Tz+rnEKPiDY59TZKUzpidFAiPXnQmjCZT1uIyhRisjdYtSFx7CRrqtURHjPo6lUa2LKEPSHC2fAE/bAcjZ/vs1Io2ZeO8WhejANetl+gBVq9W1BRYc2fLxGTv8BwLygWfdoXND2hMNrPze7/qIu6Qzy/EUKkA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X2+5lUfV; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC61BC433C7; Fri, 29 Mar 2024 12:47:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716438; bh=d5DArg/0hqWJGePnz1+kSxWB/3LWOiBxH1jRuA5RlpU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X2+5lUfV7Kq5ohezF10KO9CjRv5rj0tn77A8Noovpt2awGCaAtItq0T0MAuvpV3vG CNOAyj+DyXPLYVoePDLS3SN92oqIEyPzWMTnLhsk7jszM1iUL2qmsJVHgOE4ghyLry fKbyN8Jie0R/Aavw4USgTgPTSk0IoHwC8haFGgWXeIl3sqwXuPYcIW0F+QTXqfWGZy pnG/KIdHw1la5W5twTvjPjFUlmPb8AZLgbYOiuSfbr0Pd6NCwgPYBfWEp0yWvtJI9d nz0IG0a9Lr9HES5n+rQPsEXOauAM6+FoxMWEjsPl1WDbtzu8R37OHi/ZecIvw0/SMT xZuLpUEPIbIPg== 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.1 41/52] btrfs: export: handle invalid inode or root reference in btrfs_get_parent() Date: Fri, 29 Mar 2024 08:45:35 -0400 Message-ID: <20240329124605.3091273-41-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124605.3091273-1-sashal@kernel.org> References: <20240329124605.3091273-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.1.83 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 fab7eb76e53b2..58b0f04d7123f 100644 --- a/fs/btrfs/export.c +++ b/fs/btrfs/export.c @@ -161,8 +161,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