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 410792D7B5; Fri, 5 Jan 2024 14:43:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="oyppc5Lr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3107C433C8; Fri, 5 Jan 2024 14:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1704465785; bh=tnvTmYWe0j8zxQmAIKklTUv2ZA/UL8v+lYrQXazrTvQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oyppc5Lrf6akYnd1+MLs5IU3oTt5REJJ1nPj4uLrbdb34wtqjPGWIphwSi+KebjlV LXEyFSOz7o+WlFIkIpWU3HdP9/j9iKBDrlc0KCMw5oxyNna7/FsJmBBGQCjleFOX7C JpFu99M0qiTQtiU6mOOCCFZPJxtUu9P/5f1cYTq4= 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.4 25/47] btrfs: do not allow non subvolume root targets for snapshot Date: Fri, 5 Jan 2024 15:39:12 +0100 Message-ID: <20240105143816.504643366@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240105143815.541462991@linuxfoundation.org> References: <20240105143815.541462991@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-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 1575992d1f14c..9f1efd5c24f1a 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1847,6 +1847,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