Skip to content

Commit 2824083

Browse files
committed
ovl: Always reject mounting over case-insensitive directories
overlayfs relies on the filesystem setting DCACHE_OP_HASH or DCACHE_OP_COMPARE to reject mounting over case-insensitive directories. Since commit bb9cd91 ("fscrypt: Have filesystems handle their d_ops"), we set ->d_op through a hook in ->d_lookup, which means the root dentry won't have them, causing the mount to accidentally succeed. In v6.7-rc7, the following sequence will succeed to mount, but any dentry other than the root dentry will be a "weird" dentry to ovl and fail with EREMOTE. mkfs.ext4 -O casefold lower.img mount -O loop lower.img lower mount -t overlay -o lowerdir=lower,upperdir=upper,workdir=work ovl /mnt Mounting on a subdirectory fails, as expected, because DCACHE_OP_HASH and DCACHE_OP_COMPARE are properly set by ->lookup. Fix by explicitly rejecting superblocks that allow case-insensitive dentries. Yes, this will be solved when we move d_op configuration back to ->s_d_op. Yet, we better have an explicit fix to avoid messing up again. While there, re-sort the entries to have more descriptive error messages first. Fixes: bb9cd91 ("fscrypt: Have filesystems handle their d_ops") Acked-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Eric Biggers <ebiggers@google.com> Link: https://lore.kernel.org/r/20240221171412.10710-2-krisman@suse.de Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
1 parent 0906fbb commit 2824083

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

fs/overlayfs/params.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,20 @@ static int ovl_mount_dir_check(struct fs_context *fc, const struct path *path,
280280
{
281281
struct ovl_fs_context *ctx = fc->fs_private;
282282

283-
if (ovl_dentry_weird(path->dentry))
284-
return invalfc(fc, "filesystem on %s not supported", name);
285-
286283
if (!d_is_dir(path->dentry))
287284
return invalfc(fc, "%s is not a directory", name);
288285

286+
/*
287+
* Root dentries of case-insensitive capable filesystems might
288+
* not have the dentry operations set, but still be incompatible
289+
* with overlayfs. Check explicitly to prevent post-mount
290+
* failures.
291+
*/
292+
if (sb_has_encoding(path->mnt->mnt_sb))
293+
return invalfc(fc, "case-insensitive capable filesystem on %s not supported", name);
294+
295+
if (ovl_dentry_weird(path->dentry))
296+
return invalfc(fc, "filesystem on %s not supported", name);
289297

290298
/*
291299
* Check whether upper path is read-only here to report failures

include/linux/fs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,6 +3282,15 @@ extern int generic_check_addressable(unsigned, u64);
32823282

32833283
extern void generic_set_encrypted_ci_d_ops(struct dentry *dentry);
32843284

3285+
static inline bool sb_has_encoding(const struct super_block *sb)
3286+
{
3287+
#if IS_ENABLED(CONFIG_UNICODE)
3288+
return !!sb->s_encoding;
3289+
#else
3290+
return false;
3291+
#endif
3292+
}
3293+
32853294
int may_setattr(struct mnt_idmap *idmap, struct inode *inode,
32863295
unsigned int ia_valid);
32873296
int setattr_prepare(struct mnt_idmap *, struct dentry *, struct iattr *);

0 commit comments

Comments
 (0)