ovl: refuse pseudo filesystem layers in some setups
Subsystems (2)
Amir Goldstein
maintainerPATCH 1/1 ovl: refuse pseudo filesystem layers in some setups
From: Christian Brauner <[email protected]>
Using pseudo filesystems as overlayfs layers is a questionable practice. Copy up requires that the size of the lower file correctly represents the expected data size, which is not always the case with pseudo filesystems.
None of the pseudo filesystems can act as a functional upper layer. Most of them fail to create the work dir and the overlayfs mount falls back to read-only (e.g. sysfs, cgroup, debugfs). Others (bpffs, configfs, tracefs) create the work dir, but fail the mount later on. So let's stop pretending and explicitly deny pseudo fs as upper layer. Setups that used to fall back to a read-only mount now fail to mount.
Pseudo filesystems should have probably been classified as ovl_dentry_weird() and disallowed as any overlayfs layer, but until the introduction of the SB_I_PSEUDO flag, there was no way to identify them, so we do not know if existing setups are using them as overlayfs layers.
Data-only layers were introduced to facilitate the setup of images built with the composefs tool. The data-only layer is expected to be a filesystem backed by real storage and the lower layers are expected to be loop mounted read-only images, typically erofs.
In a composefs setup, pseudo filesystems do not make sense and there is no reason at all that those setups would exist in the wild. So let's refuse overlayfs mount with data-only layers if any of the lower layers are pseudo filesystems.
Data-only layers can be added via the "::" separator in "lowerdir=" and via "datadir+" by path or by file descriptor. All of them end up at the end of ctx->lower. So a single check in ovl_get_lowerstack() covers all of them.
Note that regular lower layers on pseudo filesystems are left alone. Stacking overlayfs on top of sysfs without data-only layers keeps working (for now).
---
Christian,
This patch applies on top of your patch to ban pseudo datadir [1] and expands the ban to more setups.
I got carried away and did a survey of the pseudo fs as upper fs and found that it is worth banning a pseudo upper fs early on, regardless of datadir.
Note that the selftest will now fail for some setups that used to be acceptable (e.g. pseudo_lower::datadir in lowerdir_sysfs) and it does not test for rejection of a pseudo upperdir.
I will send you a patch for the test shortly.
Thanks,
Amir.
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
fs/overlayfs/params.c | 3 ++- fs/overlayfs/super.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-)
fs/overlayfs/params.c +2 -1
@@ -347,7 +347,8 @@ static int ovl_mount_dir_check(struct fs_context *fc, const struct path *path,* as the mount attributes could change. */ if (upper) { -if (path->dentry->d_flags &DCACHE_OP_REAL ) +if ((path->dentry->d_flags &DCACHE_OP_REAL ) || + (path->dentry->d_sb->s_iflags &SB_I_PSEUDO ))return invalfc (fc,"filesystem on %s not supported as upperdir" , name);if (__mnt_is_readonly (path->mnt))return invalfc (fc,"filesystem on %s is read-only" , name);
fs/overlayfs/super.c +3 -3
@@ -1259,10 +1259,10 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,for (i =0 ; i < ctx->nr; i++) { l = &ctx->lower[i]; -/* Pseudo filesystems don't hold data for metacopy files. */ -if (i >= ctx->nr - ctx->nr_data && +/* Pseudo filesystems don't belong in composefs setup */ +if (ctx->nr_data && (l->path.dentry->d_sb->s_iflags &SB_I_PSEUDO )) { -pr_err ("filesystem on %s not supported as data-only layer\n" , +pr_err ("pseudo filesystem on %s not supported along with data-only layers\n" , l->name);return ERR_PTR (-EINVAL ); }
Signature · 1 line
2.56.1