[PATCH v4 8/9] ovl: Check for casefold consistency when creating new dentries

André Almeida posted 9 patches 1 month, 3 weeks ago
[PATCH v4 8/9] ovl: Check for casefold consistency when creating new dentries
Posted by André Almeida 1 month, 3 weeks ago
In a overlayfs with casefold enabled, all new dentries should have
casefold enabled as well. Check this at ovl_create_real()

Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
Changes from v3:
- New patch
---
 fs/overlayfs/dir.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 70b8687dc45e8e33079c865ae302ac58464224a6..be8c5d02302de7a3ee63220a69f99a808fde3128 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -187,6 +187,11 @@ struct dentry *ovl_create_real(struct ovl_fs *ofs, struct dentry *parent,
 			/* mkdir is special... */
 			newdentry =  ovl_do_mkdir(ofs, dir, newdentry, attr->mode);
 			err = PTR_ERR_OR_ZERO(newdentry);
+			/* expect to inherit casefolding from workdir/upperdir */
+			if (!err && ofs->casefold != ovl_dentry_casefolded(newdentry)) {
+				dput(newdentry);
+				err = -EINVAL;
+			}
 			break;
 
 		case S_IFCHR:

-- 
2.50.1

Re: [PATCH v4 8/9] ovl: Check for casefold consistency when creating new dentries
Posted by Amir Goldstein 1 month, 3 weeks ago
On Thu, Aug 14, 2025 at 12:37 AM André Almeida <andrealmeid@igalia.com> wrote:
>
> In a overlayfs with casefold enabled, all new dentries should have
> casefold enabled as well. Check this at ovl_create_real()
>
> Signed-off-by: André Almeida <andrealmeid@igalia.com>
> ---
> Changes from v3:
> - New patch
> ---
>  fs/overlayfs/dir.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
> index 70b8687dc45e8e33079c865ae302ac58464224a6..be8c5d02302de7a3ee63220a69f99a808fde3128 100644
> --- a/fs/overlayfs/dir.c
> +++ b/fs/overlayfs/dir.c
> @@ -187,6 +187,11 @@ struct dentry *ovl_create_real(struct ovl_fs *ofs, struct dentry *parent,
>                         /* mkdir is special... */
>                         newdentry =  ovl_do_mkdir(ofs, dir, newdentry, attr->mode);
>                         err = PTR_ERR_OR_ZERO(newdentry);
> +                       /* expect to inherit casefolding from workdir/upperdir */
> +                       if (!err && ofs->casefold != ovl_dentry_casefolded(newdentry)) {
> +                               dput(newdentry);
> +                               err = -EINVAL;
> +                       }

If we do encounter a filesystem that does not inherit casefolding
(which is perfectly legal) the reason for this error is going to be very
hard for users to track down.

I think this calls for pr_warn_ratelimited() like we did for the lookup
warnings with inconsistent casefloding.

Thanks,
Amir.