FAILED: patch "[PATCH] ovl: follow lower to lowerdata redirects from any lower layer" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x cbf4ccabcbfdda3da70c10b37e21e99cd2ee0946
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026112513-encroach-july-9cbc@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From cbf4ccabcbfdda3da70c10b37e21e99cd2ee0946 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <[email protected]>
Date: Sat, 7 Nov 2026 21:34:13 +0100
Subject: [PATCH] ovl: follow lower to lowerdata redirects from any lower layer
Commit 5ef7bcdeecc9 ("ovl: relax redirect/metacopy requirements for lower -> data redirect") allowed following redirects from a lower layer to a data-only layer without redirect_dir=follow and metacopy=on, so that data-only layers can be used with userxattr.
That fix was incomplete. Without metacopy=on, a metacopy file with an absolute redirect into a data-only layer is followed only from the lowest lower layer. From any other lower layer, the lookup fails with EPERM.
That commit also changed the behavior of redirect_dir=nofollow without making it visible to users. With data-only layers, some redirects are followed, although the mount options show redirect_dir=nofollow, or show nothing when that is the default.
Add redirect_dir=followdata, which follows only redirects from lower to lowerdata, and select it when there are data-only layers, unless redirect_dir=follow or redirect_dir=on is in effect, so the redirect follow mode in effect is shown in /proc/self/mountinfo.
Without metacopy=on, the absolute redirect of a lower metacopy file stops the lookup in the lower layers and the data is looked up in the data-only layers. Data-only layers cannot be used without following redirects, so reject an explicit redirect_dir=nofollow with data-only layers.
Documentation/filesystems/overlayfs.rst +15 -9
@@ -236,14 +236,19 @@ Module options (can also be changed through /sys/module/overlay/parameters/): Mount options: - "redirect_dir=on": - Redirects are enabled. + Redirects are created and followed. - "redirect_dir=follow": Redirects are not created, but followed. +- "redirect_dir=followdata": + Redirects are not created. + Only redirects from lower to lowerdata are followed. - "redirect_dir=nofollow": Redirects are not created and not followed. - "redirect_dir=off": - If "redirect_always_follow" is enabled in the kernel/module config, - this "off" translates to "follow", otherwise it translates to "nofollow". + Redirects are not created. + Which redirects are followed depends on "redirect_always_follow" in the + kernel/module config, on data-only lower layers and on the "userxattr" + mount option. When the NFS export feature is enabled, every copied up directory is indexed by the file handle of the lower inode and a file handle of the
@@ -418,8 +423,8 @@ pointed by REDIRECT. This should not be possible on local system as setting "trusted." xattrs will require CAP_SYS_ADMIN. But it should be possible for untrusted layers like from a pen drive. -Note: redirect_dir={off|nofollow|follow[*]} and nfs_export=on mount options -conflict with metacopy=on, and will result in an error. +Note: redirect_dir={off|nofollow|followdata|follow[*]} and nfs_export=on +mount options conflict with metacopy=on, and will result in an error. [*] redirect_dir=follow only conflicts with metacopy=on if upperdir=... is given.
@@ -460,10 +465,11 @@ to the absolute path of the "lower data" file in the "data-only" lower layer. Instead of explicitly enabling "metacopy=on" it is sufficient to specify at least one data-only layer to enable redirection of data to a data-only layer. -In this case other forms of metacopy are rejected. Note: this way, data-only -layers may be used together with "userxattr", in which case careful attention -must be given to privileges needed to change the "user.overlay.redirect" xattr -to prevent misuse. +In this case other forms of metacopy are rejected. A data-only layer selects +"redirect_dir=followdata", unless "redirect_dir=follow" or "redirect_dir=on" is +in effect. Note: this way, data-only layers may be used together with +"userxattr", in which case careful attention must be given to privileges needed +to change the "user.overlay.redirect" xattr to prevent misuse. Since kernel version v6.8, "data-only" lower layers can also be added using the "datadir+" mount options and the fsconfig syscall from new mount api.
fs/overlayfs/namei.c +21 -3
@@ -1079,7 +1079,8 @@ static bool ovl_check_follow_redirect(struct ovl_lookup_data *d)pr_warn_ratelimited ("refusing to follow metacopy origin for (%pd2)\n" , d->dentry);return false; } -if ((d->redirect || d->upperredirect) && !ovl_redirect_follow (ofs)) { +/* Check follow to lower layer, redirects to lowerdata are not checked here */ +if ((d->redirect || d->upperredirect) && !ovl_redirect_follow_lower (ofs)) {pr_warn_ratelimited ("refusing to follow redirect for (%pd2)\n" , d->dentry);return false; }
@@ -1097,13 +1098,26 @@ struct ovl_lookup_ctx {unsigned int ctr; }; +/* +* Without metacopy=on, the absolute redirect of a lower metacopy file is +* followed only into the data-only layers. +*/ +static bool ovl_is_lowerdata_redirect (struct ovl_lookup_ctx *ctx, +struct ovl_lookup_data *d) +{ +struct ovl_fs *ofs =OVL_FS (d->sb); + +return ofs->numdatalayer && !ofs->config.metacopy && ctx->ctr && + d->metacopy && d->absolute_redirect; +} +static int ovl_lookup_layers (struct ovl_lookup_ctx *ctx,struct ovl_lookup_data *d) {struct dentry *dentry = ctx->dentry;struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct ovl_entry *poe =OVL_E (dentry->d_parent);struct ovl_entry *roe =OVL_E (dentry->d_sb->s_root); -bool check_redirect = (ovl_redirect_follow (ofs) || ofs->numdatalayer); +bool check_redirect =ovl_redirect_follow (ofs);struct dentry *upperdir;struct dentry *this;struct dentry *origin =NULL ;
@@ -1234,6 +1248,10 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data ctx->ctr++; } +/* Lookup of lowerdata in the data-only layers only */ +if (ovl_is_lowerdata_redirect (ctx, d)) + d->stop = true; +if (d->stop)break ;
@@ -1404,7 +1422,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, {struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct ovl_entry *poe =OVL_E (dentry->d_parent); -bool check_redirect = (ovl_redirect_follow (ofs) || ofs->numdatalayer); +bool check_redirect =ovl_redirect_follow (ofs);int err;struct ovl_lookup_ctx ctx = { .dentry = dentry,
fs/overlayfs/overlayfs.h +13 -2
@@ -77,11 +77,13 @@ enum ovl_entry_flag {enum {/* -* "off" mode is never used after mount options are verified. In effect -* it translates to either "follow" or "nofollow". +* "off" mode is never used after mount options are verified. +* In effect it translates to either "follow", "nofollow" or +* "followdata" (with data-only layers). */ OVL_REDIRECT_OFF ,OVL_REDIRECT_FOLLOW , +OVL_REDIRECT_FOLLOWDATA ,OVL_REDIRECT_NOFOLLOW ,OVL_REDIRECT_ON , };
@@ -637,11 +639,20 @@ static inline char ovl_get_opaquedir_val(struct ovl_fs *ofs,return ovl_get_dir_xattr_val (ofs, path,OVL_XATTR_OPAQUE ); } +/* Are redirects followed into lower layers? */ +static inline bool ovl_redirect_follow_lower (struct ovl_fs *ofs) +{ +return ofs->config.redirect_mode ==OVL_REDIRECT_FOLLOW || + ofs->config.redirect_mode ==OVL_REDIRECT_ON ; +} + +/* Are redirects followed into lower or lowerdata layers? */ static inline bool ovl_redirect_follow (struct ovl_fs *ofs) {return ofs->config.redirect_mode !=OVL_REDIRECT_NOFOLLOW ; } +/* Are redirects created in upper dir? */ static inline bool ovl_redirect_dir (struct ovl_fs *ofs) {return ofs->config.redirect_mode ==OVL_REDIRECT_ON ;
fs/overlayfs/params.c +36 -9
95 lines not on this page · raw message
fs/overlayfs/params.h +2 -0
@@ -42,3 +42,5 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, struct ovl_config *config);int ovl_show_options (struct seq_file *m,struct dentry *dentry);const char *ovl_xino_mode (struct ovl_config *config); +const char *ovl_redirect_mode (struct ovl_config *config); +int ovl_redirect_follow_mode (bool follow_lower,size_t nr_data);
fs/overlayfs/super.c +10 -7
@@ -701,7 +701,7 @@ static int ovl_create_volatile_dirty(struct ovl_fs *ofs) }static int ovl_make_workdir (struct super_block *sb,struct ovl_fs *ofs, -const struct path *workpath) +const struct path *workpath,size_t nr_data) {struct vfsmount *mnt =ovl_upper_mnt (ofs);struct dentry *workdir;
@@ -765,9 +765,11 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,if (err) {pr_warn ("failed to set xattr on upper\n" ); ofs->noxattr = true; -if (ovl_redirect_follow (ofs)) { - ofs->config.redirect_mode =OVL_REDIRECT_NOFOLLOW ; -pr_warn ("...falling back to redirect_dir=nofollow.\n" ); +if (ovl_redirect_follow_lower (ofs)) { + ofs->config.redirect_mode = +ovl_redirect_follow_mode (false, nr_data); +pr_warn ("...falling back to redirect_dir=%s.\n" , +ovl_redirect_mode (&ofs->config)); }if (ofs->config.metacopy) { ofs->config.metacopy = false;
@@ -844,7 +846,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,static int ovl_get_workdir (struct super_block *sb,struct ovl_fs *ofs,const struct path *upperpath, -const struct path *workpath) +const struct path *workpath,size_t nr_data) {int err;
@@ -873,7 +875,7 @@ static int ovl_get_workdir(struct super_block *sb, struct ovl_fs *ofs,if (err)return err; -return ovl_make_workdir (sb, ofs, workpath); +return ovl_make_workdir (sb, ofs, workpath, nr_data); } static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs,
@@ -1485,7 +1487,8 @@ static int ovl_fill_super_creds(struct fs_context *fc, struct super_block *sb) } } - err =ovl_get_workdir (sb, ofs, &ctx->upper, &ctx->work); + err =ovl_get_workdir (sb, ofs, &ctx->upper, &ctx->work, + ctx->nr_data);if (err)return err;
Sasha Levin
maintainerPATCH 1/1 ovl: follow lower to lowerdata redirects from any lower layer
From: Giuseppe Scrivano <[email protected]>
[ Upstream commit cbf4ccabcbfdda3da70c10b37e21e99cd2ee0946 ]
Commit 5ef7bcdeecc9 ("ovl: relax redirect/metacopy requirements for lower -> data redirect") allowed following redirects from a lower layer to a data-only layer without redirect_dir=follow and metacopy=on, so that data-only layers can be used with userxattr.
That fix was incomplete. Without metacopy=on, a metacopy file with an absolute redirect into a data-only layer is followed only from the lowest lower layer. From any other lower layer, the lookup fails with EPERM.
That commit also changed the behavior of redirect_dir=nofollow without making it visible to users. With data-only layers, some redirects are followed, although the mount options show redirect_dir=nofollow, or show nothing when that is the default.
Add redirect_dir=followdata, which follows only redirects from lower to lowerdata, and select it when there are data-only layers, unless redirect_dir=follow or redirect_dir=on is in effect, so the redirect follow mode in effect is shown in /proc/self/mountinfo.
Without metacopy=on, the absolute redirect of a lower metacopy file stops the lookup in the lower layers and the data is looked up in the data-only layers. Data-only layers cannot be used without following redirects, so reject an explicit redirect_dir=nofollow with data-only layers.
---
Depends on <[email protected]>
Documentation/filesystems/overlayfs.rst | 24 ++++++++----- fs/overlayfs/namei.c | 24 +++++++++++-- fs/overlayfs/overlayfs.h | 15 +++++++-- fs/overlayfs/params.c | 45 ++++++++++++++++++++----- fs/overlayfs/params.h | 2 ++ fs/overlayfs/super.c | 17 ++++++---- 6 files changed, 97 insertions(+), 30 deletions(-)
Documentation/filesystems/overlayfs.rst +15 -9
@@ -237,14 +237,19 @@ Module options (can also be changed through /sys/module/overlay/parameters/): Mount options: - "redirect_dir=on": - Redirects are enabled. + Redirects are created and followed. - "redirect_dir=follow": Redirects are not created, but followed. +- "redirect_dir=followdata": + Redirects are not created. + Only redirects from lower to lowerdata are followed. - "redirect_dir=nofollow": Redirects are not created and not followed. - "redirect_dir=off": - If "redirect_always_follow" is enabled in the kernel/module config, - this "off" translates to "follow", otherwise it translates to "nofollow". + Redirects are not created. + Which redirects are followed depends on "redirect_always_follow" in the + kernel/module config, on data-only lower layers and on the "userxattr" + mount option. When the NFS export feature is enabled, every copied up directory is indexed by the file handle of the lower inode and a file handle of the
@@ -403,8 +408,8 @@ pointed by REDIRECT. This should not be possible on local system as setting "trusted." xattrs will require CAP_SYS_ADMIN. But it should be possible for untrusted layers like from a pen drive. -Note: redirect_dir={off|nofollow|follow[*]} and nfs_export=on mount options -conflict with metacopy=on, and will result in an error. +Note: redirect_dir={off|nofollow|followdata|follow[*]} and nfs_export=on +mount options conflict with metacopy=on, and will result in an error. [*] redirect_dir=follow only conflicts with metacopy=on if upperdir=... is given.
@@ -445,10 +450,11 @@ to the absolute path of the "lower data" file in the "data-only" lower layer. Instead of explicitly enabling "metacopy=on" it is sufficient to specify at least one data-only layer to enable redirection of data to a data-only layer. -In this case other forms of metacopy are rejected. Note: this way, data-only -layers may be used together with "userxattr", in which case careful attention -must be given to privileges needed to change the "user.overlay.redirect" xattr -to prevent misuse. +In this case other forms of metacopy are rejected. A data-only layer selects +"redirect_dir=followdata", unless "redirect_dir=follow" or "redirect_dir=on" is +in effect. Note: this way, data-only layers may be used together with +"userxattr", in which case careful attention must be given to privileges needed +to change the "user.overlay.redirect" xattr to prevent misuse. Since kernel version v6.8, "data-only" lower layers can also be added using the "datadir+" mount options and the fsconfig syscall from new mount api.
fs/overlayfs/namei.c +21 -3
@@ -1087,7 +1087,8 @@ static bool ovl_check_follow_redirect(struct ovl_lookup_data *d)pr_warn_ratelimited ("refusing to follow metacopy origin for (%pd2)\n" , d->dentry);return false; } -if ((d->redirect || d->upperredirect) && !ovl_redirect_follow (ofs)) { +/* Check follow to lower layer, redirects to lowerdata are not checked here */ +if ((d->redirect || d->upperredirect) && !ovl_redirect_follow_lower (ofs)) {pr_warn_ratelimited ("refusing to follow redirect for (%pd2)\n" , d->dentry);return false; }
@@ -1105,13 +1106,26 @@ struct ovl_lookup_ctx {unsigned int ctr; }; +/* +* Without metacopy=on, the absolute redirect of a lower metacopy file is +* followed only into the data-only layers. +*/ +static bool ovl_is_lowerdata_redirect (struct ovl_lookup_ctx *ctx, +struct ovl_lookup_data *d) +{ +struct ovl_fs *ofs =OVL_FS (d->sb); + +return ofs->numdatalayer && !ofs->config.metacopy && ctx->ctr && + d->metacopy && d->absolute_redirect; +} +static int ovl_lookup_layers (struct ovl_lookup_ctx *ctx,struct ovl_lookup_data *d) {struct dentry *dentry = ctx->dentry;struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct ovl_entry *poe =OVL_E (dentry->d_parent);struct ovl_entry *roe =OVL_E (dentry->d_sb->s_root); -bool check_redirect = (ovl_redirect_follow (ofs) || ofs->numdatalayer); +bool check_redirect =ovl_redirect_follow (ofs);struct dentry *upperdir;struct dentry *this;struct dentry *origin =NULL ;
@@ -1242,6 +1256,10 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data ctx->ctr++; } +/* Lookup of lowerdata in the data-only layers only */ +if (ovl_is_lowerdata_redirect (ctx, d)) + d->stop = true; +if (d->stop)break ;
@@ -1411,7 +1429,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,const struct cred *old_cred;struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct ovl_entry *poe =OVL_E (dentry->d_parent); -bool check_redirect = (ovl_redirect_follow (ofs) || ofs->numdatalayer); +bool check_redirect =ovl_redirect_follow (ofs);int err;struct ovl_lookup_ctx ctx = { .dentry = dentry,
fs/overlayfs/overlayfs.h +13 -2
@@ -75,11 +75,13 @@ enum ovl_entry_flag {enum {/* -* "off" mode is never used after mount options are verified. In effect -* it translates to either "follow" or "nofollow". +* "off" mode is never used after mount options are verified. +* In effect it translates to either "follow", "nofollow" or +* "followdata" (with data-only layers). */ OVL_REDIRECT_OFF ,OVL_REDIRECT_FOLLOW , +OVL_REDIRECT_FOLLOWDATA ,OVL_REDIRECT_NOFOLLOW ,OVL_REDIRECT_ON , };
@@ -632,11 +634,20 @@ static inline char ovl_get_opaquedir_val(struct ovl_fs *ofs,return ovl_get_dir_xattr_val (ofs, path,OVL_XATTR_OPAQUE ); } +/* Are redirects followed into lower layers? */ +static inline bool ovl_redirect_follow_lower (struct ovl_fs *ofs) +{ +return ofs->config.redirect_mode ==OVL_REDIRECT_FOLLOW || + ofs->config.redirect_mode ==OVL_REDIRECT_ON ; +} + +/* Are redirects followed into lower or lowerdata layers? */ static inline bool ovl_redirect_follow (struct ovl_fs *ofs) {return ofs->config.redirect_mode !=OVL_REDIRECT_NOFOLLOW ; } +/* Are redirects created in upper dir? */ static inline bool ovl_redirect_dir (struct ovl_fs *ofs) {return ofs->config.redirect_mode ==OVL_REDIRECT_ON ;
fs/overlayfs/params.c +36 -9
95 lines not on this page · raw message
fs/overlayfs/params.h +2 -0
@@ -42,3 +42,5 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, struct ovl_config *config);int ovl_show_options (struct seq_file *m,struct dentry *dentry);const char *ovl_xino_mode (struct ovl_config *config); +const char *ovl_redirect_mode (struct ovl_config *config); +int ovl_redirect_follow_mode (bool follow_lower,size_t nr_data);
fs/overlayfs/super.c +10 -7
@@ -684,7 +684,7 @@ static int ovl_create_volatile_dirty(struct ovl_fs *ofs) }static int ovl_make_workdir (struct super_block *sb,struct ovl_fs *ofs, -const struct path *workpath) +const struct path *workpath,size_t nr_data) {struct vfsmount *mnt =ovl_upper_mnt (ofs);struct dentry *workdir;
@@ -748,9 +748,11 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,if (err) {pr_warn ("failed to set xattr on upper\n" ); ofs->noxattr = true; -if (ovl_redirect_follow (ofs)) { - ofs->config.redirect_mode =OVL_REDIRECT_NOFOLLOW ; -pr_warn ("...falling back to redirect_dir=nofollow.\n" ); +if (ovl_redirect_follow_lower (ofs)) { + ofs->config.redirect_mode = +ovl_redirect_follow_mode (false, nr_data); +pr_warn ("...falling back to redirect_dir=%s.\n" , +ovl_redirect_mode (&ofs->config)); }if (ofs->config.metacopy) { ofs->config.metacopy = false;
@@ -827,7 +829,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,static int ovl_get_workdir (struct super_block *sb,struct ovl_fs *ofs,const struct path *upperpath, -const struct path *workpath) +const struct path *workpath,size_t nr_data) {int err;
@@ -856,7 +858,7 @@ static int ovl_get_workdir(struct super_block *sb, struct ovl_fs *ofs,if (err)return err; -return ovl_make_workdir (sb, ofs, workpath); +return ovl_make_workdir (sb, ofs, workpath, nr_data); } static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs,
@@ -1510,7 +1512,8 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc) } } - err =ovl_get_workdir (sb, ofs, &ctx->upper, &ctx->work); + err =ovl_get_workdir (sb, ofs, &ctx->upper, &ctx->work, + ctx->nr_data);if (err) goto out_err;
Signature · 1 line
2.53.0