From mboxrd@z Thu Jan 1 00:00:00 1970 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 266FD1BDF1; Wed, 3 Jan 2024 17:11:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Xp/5vETT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 986A7C433C7; Wed, 3 Jan 2024 17:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1704301880; bh=XaVXDxyjnTInCSsTFevm7nhtnhRbBe1wdu76p3D5P+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xp/5vETTSi6/eFjB4Yiex12hwZhc4atZNbyjyTd2TAaJn8CTcubZMwJ3eLAkhhFCG IvD2XL2qWLfuUDPApYtZ5YgVET/rbmwyLAObpxY6WRmSEq7bM3lrKHhArWjZ6JYMLA zC7olILRyrhcAkAKzynwuinbPixv2wXubkydydcI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Martin Michaelis , Neal Gompa , Josef Bacik , David Sterba , Sasha Levin Subject: [PATCH 5.10 26/75] btrfs: do not allow non subvolume root targets for snapshot Date: Wed, 3 Jan 2024 17:55:07 +0100 Message-ID: <20240103164847.126718332@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103164842.953224409@linuxfoundation.org> References: <20240103164842.953224409@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit a8892fd71933126ebae3d60aec5918d4dceaae76 ] Our btrfs subvolume snapshot utility enforces that is the root of the subvolume, however this isn't enforced in the kernel. Update the kernel to also enforce this limitation to avoid problems with other users of this ioctl that don't have the appropriate checks in place. Reported-by: Martin Michaelis CC: stable@vger.kernel.org # 4.14+ Reviewed-by: Neal Gompa Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/ioctl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 6da8587e2ae37..f06824bea4686 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1868,6 +1868,15 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file, * are limited to own subvolumes only */ ret = -EPERM; + } else if (btrfs_ino(BTRFS_I(src_inode)) != BTRFS_FIRST_FREE_OBJECTID) { + /* + * Snapshots must be made with the src_inode referring + * to the subvolume inode, otherwise the permission + * checking above is useless because we may have + * permission on a lower directory but not the subvol + * itself. + */ + ret = -EINVAL; } else { ret = btrfs_mksnapshot(&file->f_path, name, namelen, BTRFS_I(src_inode)->root, -- 2.43.0