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 02C932E640; Fri, 5 Jan 2024 14:40:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="xN4M76ni" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C1ABC433C9; Fri, 5 Jan 2024 14:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1704465659; bh=mQupbT/8tUwUMSwUPqxu+oanuFk3QnZbPP5HYXQO1q0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xN4M76niflAFkVqcAaew3MgxwbMgXIp/1DNmp0WPNzGqepvncg2adgAdxZKNbtrmG VKCrIdF1Of2g8Yqc5ajBm7GhWUEAcXTVdhTA0pnM6E/9MEENU9joR4H41bzKWcWKaj fbcqpATKUWptQEQoxL8atrcNX5GbCemgDuqnuKsQ= 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 4.19 21/41] btrfs: do not allow non subvolume root targets for snapshot Date: Fri, 5 Jan 2024 15:39:01 +0100 Message-ID: <20240105143814.881472528@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240105143813.957669139@linuxfoundation.org> References: <20240105143813.957669139@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 4.19-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 23beabb489231..c76277ccf03b0 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1789,6 +1789,15 @@ static noinline int btrfs_ioctl_snap_create_transid(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_mksubvol(&file->f_path, name, namelen, BTRFS_I(src_inode)->root, -- 2.43.0