FAILED: patch "[PATCH] ovl: bump the impure dir version when linking a file with" failed to apply to 6.18-stable tree
Subsystems (2)
[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 86e2facd8630cc2fdec6ea80c53e370b26b441d9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026112548-vowed-carded-1ef2@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 86e2facd8630cc2fdec6ea80c53e370b26b441d9 Mon Sep 17 00:00:00 2001
From: Daejun Park <[email protected]>
Date: Thu, 12 Nov 2026 12:58:09 +0900
Subject: [PATCH] ovl: bump the impure dir version when linking a file with
origin
Linking a file with copy up origin into a non-merge impure dir does not bump the dir version. readdir then reuses the impure dir cache built before the link. It reports the upper inode number as d_ino of the new link, not st_ino.
Pass whether the linked file has an origin to ovl_dir_modified(), as rename and unlink do.
fs/overlayfs/dir.c +11 -9
@@ -368,7 +368,7 @@ static bool ovl_type_origin(struct dentry *dentry) }static int ovl_create_upper (struct dentry *dentry,struct inode *inode, -struct ovl_cattr *attr) +struct ovl_cattr *attr,bool origin) {struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct dentry *upperdir =ovl_dentry_upper (dentry->d_parent);
@@ -393,7 +393,7 @@ static int ovl_create_upper(struct dentry *dentry, struct inode *inode,ovl_set_opaque (dentry, newdentry); } -ovl_dir_modified (dentry->d_parent, false); +ovl_dir_modified (dentry->d_parent, origin); err =ovl_instantiate (dentry, inode, newdentry, !!attr->hardlink,NULL );if (err) goto out_cleanup;
@@ -491,7 +491,7 @@ static int ovl_set_upper_acl(struct ovl_fs *ofs, struct dentry *upperdentry, }static int ovl_create_over_whiteout (struct dentry *dentry,struct inode *inode, -struct ovl_cattr *cattr) +struct ovl_cattr *cattr,bool origin) {struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct dentry *workdir =ovl_workdir (dentry);
@@ -582,7 +582,7 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,if (err) goto out_cleanup_unlocked; } -ovl_dir_modified (dentry->d_parent, false); +ovl_dir_modified (dentry->d_parent, origin); err =ovl_instantiate (dentry, inode, newdentry, hardlink,NULL );if (err) {ovl_cleanup (ofs, upperdir, newdentry);
@@ -647,12 +647,12 @@ DEFINE_CLASS(ovl_override_creator_creds,static int ovl_create_handle_whiteouts (struct dentry *dentry,struct inode *inode, -struct ovl_cattr *attr) +struct ovl_cattr *attr,bool origin) {if (!ovl_dentry_is_whiteout (dentry)) -return ovl_create_upper (dentry, inode, attr); +return ovl_create_upper (dentry, inode, attr, origin); -return ovl_create_over_whiteout (dentry, inode, attr); +return ovl_create_over_whiteout (dentry, inode, attr, origin); } static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
@@ -687,12 +687,14 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,*/ if (attr->hardlink) -return ovl_create_handle_whiteouts (dentry, inode, attr); +return ovl_create_handle_whiteouts (dentry, inode, attr, + origin); scoped_class(ovl_override_creator_creds, cred, original_creds, dentry, inode, attr->mode) {if (IS_ERR (cred))return PTR_ERR (cred); -return ovl_create_handle_whiteouts (dentry, inode, attr); +return ovl_create_handle_whiteouts (dentry, inode, attr, + origin); } }return err;
Sasha Levin
maintainerPATCH 1/6 cred: add prepare credential guard
From: Christian Brauner <[email protected]>
[ Upstream commit c8ad3098e1272444b6c75910d6196a36f5c8bc17 ]
A lot of code uses the following pattern:
* prepare new credentials
* modify them for their use-case
* drop them
Support that easier with the new guard infrastructure.
Stable-dep-of: 86e2facd8630 ("ovl: bump the impure dir version when linking a file with origin")
--- include/linux/cred.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/cred.h +5 -0
@@ -278,6 +278,11 @@ static inline void put_cred(const struct cred *cred)put_cred_many (cred,1 ); } +DEFINE_CLASS (prepare_creds, + struct cred *, + if (_T) put_cred(_T), + prepare_creds(), void) + DEFINE_FREE(put_cred, struct cred *, if (!IS_ERR_OR_NULL(_T)) put_cred(_T))/**
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/6 ovl: port ovl_create_or_link() to cred guard
From: Christian Brauner <[email protected]>
[ Upstream commit 8c9531edcf60014b7e36739697f5cc15d5e853a1 ]
Use the scoped ovl cred guard.
Stable-dep-of: 86e2facd8630 ("ovl: bump the impure dir version when linking a file with origin")
--- fs/overlayfs/dir.c | 70 ++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 39 deletions(-)
fs/overlayfs/dir.c +31 -39
@@ -617,52 +617,44 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode, struct ovl_cattr *attr, bool origin) { int err; -const struct cred *old_cred, *new_cred =NULL ; + const struct cred *new_cred __free(put_cred) = NULL;struct dentry *parent = dentry->d_parent; - old_cred =ovl_override_creds (dentry->d_sb); - -/* -* When linking a file with copy up origin into a new parent, mark the -* new parent dir "impure". -*/ -if (origin) { - err =ovl_set_impure (parent,ovl_dentry_upper (parent)); -if (err) - goto out_revert_creds; - } - -if (!attr->hardlink) { + scoped_class(override_creds_ovl, old_cred, dentry->d_sb) {/* -* In the creation cases(create, mkdir, mknod, symlink), -* ovl should transfer current's fs{u,g}id to underlying -* fs. Because underlying fs want to initialize its new -* inode owner using current's fs{u,g}id. And in this -* case, the @inode is a new inode that is initialized -* in inode_init_owner() to current's fs{u,g}id. So use -* the inode's i_{u,g}id to override the cred's fs{u,g}id. -* -* But in the other hardlink case, ovl_link() does not -* create a new inode, so just use the ovl mounter's -* fs{u,g}id. +* When linking a file with copy up origin into a new parent, mark the +* new parent dir "impure". */ - new_cred =ovl_setup_cred_for_create (dentry, inode, attr->mode, - old_cred); - err =PTR_ERR (new_cred); -if (IS_ERR (new_cred)) { - new_cred =NULL ; - goto out_revert_creds; +if (origin) { + err =ovl_set_impure (parent,ovl_dentry_upper (parent)); +if (err) +return err; } - } -if (!ovl_dentry_is_whiteout (dentry)) - err =ovl_create_upper (dentry, inode, attr); -else - err =ovl_create_over_whiteout (dentry, inode, attr); +if (!attr->hardlink) { +/* +* In the creation cases(create, mkdir, mknod, symlink), +* ovl should transfer current's fs{u,g}id to underlying +* fs. Because underlying fs want to initialize its new +* inode owner using current's fs{u,g}id. And in this +* case, the @inode is a new inode that is initialized +* in inode_init_owner() to current's fs{u,g}id. So use +* the inode's i_{u,g}id to override the cred's fs{u,g}id. +* +* But in the other hardlink case, ovl_link() does not +* create a new inode, so just use the ovl mounter's +* fs{u,g}id. +*/ + new_cred =ovl_setup_cred_for_create (dentry, inode, attr->mode, old_cred); +if (IS_ERR (new_cred)) +return PTR_ERR (new_cred); + } -out_revert_creds: -ovl_revert_creds (old_cred); -put_cred (new_cred); +if (!ovl_dentry_is_whiteout (dentry)) +return ovl_create_upper (dentry, inode, attr); + +return ovl_create_over_whiteout (dentry, inode, attr); + }return err; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/6 ovl: add ovl_override_creator_creds cred guard
In reply to Sasha LevinFrom: Christian Brauner <[email protected]>
[ Upstream commit f37b334728814b14745e15d46f9eab73750b67ec ]
The current code to override credentials for creation operations is pretty difficult to understand. We effectively override the credentials twice:
(1) override with the mounter's credentials
(2) copy the mounts credentials and override the fs{g,u}id with the inode {u,g}id
And then we elide the revert because it would be an idempotent revert. That elision doesn't buy us anything anymore though because I've made it all work without any reference counting anyway. All it does is mix the two credential overrides together.
We can use a cleanup guard to clarify the creation codepaths and make them easier to understand.
This just introduces the cleanup guard keeping the patch reviewable. We'll convert the caller in follow-up patches and then drop the duplicated code.
Stable-dep-of: 86e2facd8630 ("ovl: bump the impure dir version when linking a file with origin")
--- fs/overlayfs/dir.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
fs/overlayfs/dir.c +36 -0
@@ -580,6 +580,42 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode, goto out_dput; } +static const struct cred *ovl_override_creator_creds (struct dentry *dentry,struct inode *inode,umode_t mode) +{ +int err; + +if (WARN_ON_ONCE (current->cred !=ovl_creds (dentry->d_sb))) +return ERR_PTR (-EINVAL ); + +CLASS (prepare_creds, override_cred)(); +if (!override_cred) +return ERR_PTR (-ENOMEM ); + + override_cred->fsuid = inode->i_uid; + override_cred->fsgid = inode->i_gid; + + err =security_dentry_create_files_as (dentry, mode, &dentry->d_name, + current->cred, override_cred); +if (err) +return ERR_PTR (err); + +return override_creds (no_free_ptr (override_cred)); +} + +static void ovl_revert_creator_creds (const struct cred *old_cred) +{ +const struct cred *override_cred; + + override_cred =revert_creds (old_cred); +put_cred (override_cred); +} + +DEFINE_CLASS (ovl_override_creator_creds, + const struct cred *, + if (!IS_ERR_OR_NULL(_T)) ovl_revert_creator_creds(_T), +ovl_override_creator_creds (dentry, inode, mode), + struct dentry *dentry, struct inode *inode, umode_t mode) + static const struct cred *ovl_setup_cred_for_create(struct dentry *dentry, struct inode *inode, umode_t mode,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/6 ovl: reflow ovl_create_or_link()
In reply to Sasha LevinFrom: Christian Brauner <[email protected]>
[ Upstream commit d6ef072d09b2341e606aeeaf14c3510dec329c63 ]
Reflow the creation routine in preparation of porting it to a guard.
Stable-dep-of: 86e2facd8630 ("ovl: bump the impure dir version when linking a file with origin")
--- fs/overlayfs/dir.c | 51 +++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-)
fs/overlayfs/dir.c +30 -21
@@ -649,6 +649,16 @@ static const struct cred *ovl_setup_cred_for_create(struct dentry *dentry,return override_cred; } +static int ovl_create_handle_whiteouts (struct dentry *dentry, +struct inode *inode, +struct ovl_cattr *attr) +{ +if (!ovl_dentry_is_whiteout (dentry)) +return ovl_create_upper (dentry, inode, attr); + +return ovl_create_over_whiteout (dentry, inode, attr); +} +static int ovl_create_or_link (struct dentry *dentry,struct inode *inode,struct ovl_cattr *attr,bool origin) {
@@ -667,29 +677,28 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,return err; } -if (!attr->hardlink) { -/* -* In the creation cases(create, mkdir, mknod, symlink), -* ovl should transfer current's fs{u,g}id to underlying -* fs. Because underlying fs want to initialize its new -* inode owner using current's fs{u,g}id. And in this -* case, the @inode is a new inode that is initialized -* in inode_init_owner() to current's fs{u,g}id. So use -* the inode's i_{u,g}id to override the cred's fs{u,g}id. -* -* But in the other hardlink case, ovl_link() does not -* create a new inode, so just use the ovl mounter's -* fs{u,g}id. -*/ - new_cred =ovl_setup_cred_for_create (dentry, inode, attr->mode, old_cred); -if (IS_ERR (new_cred)) -return PTR_ERR (new_cred); - } +/* +* In the creation cases(create, mkdir, mknod, symlink), +* ovl should transfer current's fs{u,g}id to underlying +* fs. Because underlying fs want to initialize its new +* inode owner using current's fs{u,g}id. And in this +* case, the @inode is a new inode that is initialized +* in inode_init_owner() to current's fs{u,g}id. So use +* the inode's i_{u,g}id to override the cred's fs{u,g}id. +* +* But in the other hardlink case, ovl_link() does not +* create a new inode, so just use the ovl mounter's +* fs{u,g}id. +*/ + +if (attr->hardlink) +return ovl_create_handle_whiteouts (dentry, inode, attr); -if (!ovl_dentry_is_whiteout (dentry)) -return ovl_create_upper (dentry, inode, attr); + new_cred =ovl_setup_cred_for_create (dentry, inode, attr->mode, old_cred); +if (IS_ERR (new_cred)) +return PTR_ERR (new_cred); -return ovl_create_over_whiteout (dentry, inode, attr); +return ovl_create_handle_whiteouts (dentry, inode, attr); }return err; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 5/6 ovl: port ovl_create_or_link() to new ovl_override_creator_creds cleanup guard
In reply to Sasha LevinFrom: Christian Brauner <[email protected]>
[ Upstream commit e566bff963220ba0f740da42d46dd55c34ef745e ]
This clearly indicates the double-credential override and makes the code a lot easier to grasp with one glance.
Stable-dep-of: 86e2facd8630 ("ovl: bump the impure dir version when linking a file with origin")
--- fs/overlayfs/dir.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
fs/overlayfs/dir.c +6 -7
@@ -663,10 +663,9 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode, struct ovl_cattr *attr, bool origin) { int err; - const struct cred *new_cred __free(put_cred) = NULL;struct dentry *parent = dentry->d_parent; - scoped_class(override_creds_ovl, old_cred, dentry->d_sb) { + with_ovl_creds(dentry->d_sb) {/* * When linking a file with copy up origin into a new parent, mark the * new parent dir "impure".
@@ -694,11 +693,11 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,if (attr->hardlink)return ovl_create_handle_whiteouts (dentry, inode, attr); - new_cred =ovl_setup_cred_for_create (dentry, inode, attr->mode, old_cred); -if (IS_ERR (new_cred)) -return PTR_ERR (new_cred); - -return ovl_create_handle_whiteouts (dentry, inode, attr); + scoped_class(ovl_override_creator_creds, cred, dentry, inode, attr->mode) { +if (IS_ERR (cred)) +return PTR_ERR (cred); +return ovl_create_handle_whiteouts (dentry, inode, attr); + } }return err; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 6/6 ovl: bump the impure dir version when linking a file with origin
In reply to Sasha LevinFrom: Daejun Park <[email protected]>
[ Upstream commit 86e2facd8630cc2fdec6ea80c53e370b26b441d9 ]
Linking a file with copy up origin into a non-merge impure dir does not bump the dir version. readdir then reuses the impure dir cache built before the link. It reports the upper inode number as d_ino of the new link, not st_ino.
Pass whether the linked file has an origin to ovl_dir_modified(), as rename and unlink do.
--- fs/overlayfs/dir.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
fs/overlayfs/dir.c +11 -9
@@ -355,7 +355,7 @@ static bool ovl_type_origin(struct dentry *dentry) }static int ovl_create_upper (struct dentry *dentry,struct inode *inode, -struct ovl_cattr *attr) +struct ovl_cattr *attr,bool origin) {struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct dentry *upperdir =ovl_dentry_upper (dentry->d_parent);
@@ -378,7 +378,7 @@ static int ovl_create_upper(struct dentry *dentry, struct inode *inode,ovl_set_opaque (dentry, newdentry); } -ovl_dir_modified (dentry->d_parent, false); +ovl_dir_modified (dentry->d_parent, origin); err =ovl_instantiate (dentry, inode, newdentry, !!attr->hardlink,NULL );if (err) goto out_cleanup;
@@ -471,7 +471,7 @@ static int ovl_set_upper_acl(struct ovl_fs *ofs, struct dentry *upperdentry, }static int ovl_create_over_whiteout (struct dentry *dentry,struct inode *inode, -struct ovl_cattr *cattr) +struct ovl_cattr *cattr,bool origin) {struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct dentry *workdir =ovl_workdir (dentry);
@@ -557,7 +557,7 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,if (err) goto out_cleanup_unlocked; } -ovl_dir_modified (dentry->d_parent, false); +ovl_dir_modified (dentry->d_parent, origin); err =ovl_instantiate (dentry, inode, newdentry, hardlink,NULL );if (err) {ovl_cleanup (ofs, upperdir, newdentry);
@@ -651,12 +651,12 @@ static const struct cred *ovl_setup_cred_for_create(struct dentry *dentry,static int ovl_create_handle_whiteouts (struct dentry *dentry,struct inode *inode, -struct ovl_cattr *attr) +struct ovl_cattr *attr,bool origin) {if (!ovl_dentry_is_whiteout (dentry)) -return ovl_create_upper (dentry, inode, attr); +return ovl_create_upper (dentry, inode, attr, origin); -return ovl_create_over_whiteout (dentry, inode, attr); +return ovl_create_over_whiteout (dentry, inode, attr, origin); } static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
@@ -691,12 +691,14 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,*/ if (attr->hardlink) -return ovl_create_handle_whiteouts (dentry, inode, attr); +return ovl_create_handle_whiteouts (dentry, inode, attr, + origin); scoped_class(ovl_override_creator_creds, cred, dentry, inode, attr->mode) {if (IS_ERR (cred))return PTR_ERR (cred); -return ovl_create_handle_whiteouts (dentry, inode, attr); +return ovl_create_handle_whiteouts (dentry, inode, attr, + origin); } }return err;
Signature · 1 line
2.53.0