FAILED: patch "[PATCH] ovl: look up the index by the decoded origin" failed to apply to 6.6-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-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.6.y
git checkout FETCH_HEAD
git cherry-pick -x 520ef67f47f69255695859b0008281a384d0bc20
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 520ef67f47f69255695859b0008281a384d0bc20 Mon Sep 17 00:00:00 2001
From: Chris Mason <[email protected]>
Date: Fri, 16 Oct 2026 21:17:22 +0000
Subject: [PATCH] ovl: look up the index by the decoded origin
A file opened by file handle on an overlay with nfs_export=on can show the stale lower data of a file that was copied up to the upper layer. While the file opened this way stays in the inode cache, a lookup of the copied up file by path fails with ESTALE for all users. The open can also succeed for a file that was removed, where it has to fail with ESTALE. This happens with a handle that has one byte changed. The handle comes from an NFS client, or from a process that calls open_by_handle_at() with CAP_DAC_READ_SEARCH in the initial user namespace.
When a file in a lower layer is about to be modified, overlayfs first copies it to the upper layer (copy up). With nfs_export=on, each copy up also creates an entry in the index directory, a directory that overlayfs keeps for itself on the upper filesystem.
The handle of an overlay file that comes from a lower layer wraps the handle of its lower inode. Overlayfs calls this lower inode the origin. The overlay handle stays valid after a copy up.
To decode such a handle, ovl_lower_fh_to_d() first decodes the wrapped handle to the origin. If no overlay inode is cached for the origin, it looks in the index directory:
- An index entry there leads to the upper file.
- A whiteout, the marker that overlayfs uses for a removed file, means that the overlay file was removed.
The name of an index entry is the handle that copy up encoded for the origin, as a hex string.
ovl_lower_fh_to_d() builds the name for this lookup from the bytes that the caller passed in. But handles with different bytes can decode to the same inode:
- Overlayfs ignores some flag bits of the handle.
- A lower filesystem can accept a different fid type, extra bytes, or generation 0 for any generation.
Such a handle decodes to the origin but misses the index entry or the whiteout. So the decode returns an overlay inode that has only the lower file.
While that inode is cached, a path lookup of a copied up file fails with ESTALE, since the upper file that the lookup finds does not match the cached inode, which has none.
Reproduced on tmpfs and on ext4 with open_by_handle_at(), after a copy up and a mount cycle. A handle in which one flag bit, the fid type, the length or the generation was changed read the old lower data, and path lookups returned ESTALE.
Fix this by re-encoding the decoded origin and building the index name from that handle.
--- Documentation/filesystems/overlayfs.rst | 3 ++- fs/overlayfs/export.c | 4 ++-- fs/overlayfs/namei.c | 13 ++++++++++--- fs/overlayfs/overlayfs.h | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-)
Documentation/filesystems/overlayfs.rst +2 -1
@@ -731,7 +731,8 @@ When decoding an overlay file handle, the following steps are followed: 1. Find underlying layer by UUID and path type information. 2. Decode the underlying filesystem file handle to underlying dentry. - 3. For a lower file handle, lookup the handle in index directory by name. + 3. For a lower file handle, encode the decoded underlying inode again and + lookup that handle in index directory by name. 4. If a whiteout is found in index, return ESTALE. This represents an overlay object that was deleted after its file handle was encoded. 5. For a non-directory, instantiate a disconnected overlay dentry from the
fs/overlayfs/export.c +2 -2
@@ -713,9 +713,9 @@ static struct dentry *ovl_lower_fh_to_d(struct super_block *sb, } } -/* Then lookup indexed upper/whiteout by origin fh */ +/* Then lookup indexed upper/whiteout by origin */ if (ovl_indexdir (sb)) { - index =ovl_get_index_fh (ofs, fh); + index =ovl_get_index_origin (ofs, origin.dentry); err =PTR_ERR (index);if (IS_ERR (index)) { index =NULL ;
fs/overlayfs/namei.c +10 -3
@@ -781,14 +781,21 @@ int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin,return err; } -/* Lookup index by file handle for NFS export */ -struct dentry *ovl_get_index_fh (struct ovl_fs *ofs,struct ovl_fh *fh) +/* +* Lookup index by decoded origin for NFS export. +* +* The name of an index is the hex of the file handle that copy up encoded. +* The bytes of the handle to decode cannot be used as the name, because a +* lower fs may decode many handles to the same inode. For example, it may +* ignore the fid type, extra fid bytes or a zero generation. +*/ +struct dentry *ovl_get_index_origin (struct ovl_fs *ofs,struct dentry *origin) {struct dentry *index;struct qstr name;int err; - err =ovl_get_index_name_fh (fh, &name); + err =ovl_get_index_name (ofs, origin, &name);if (err)return ERR_PTR (err);
fs/overlayfs/overlayfs.h +1 -1
@@ -750,7 +750,7 @@ int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index);int ovl_get_index_name_fh (const struct ovl_fh *fh,struct qstr *name);int ovl_get_index_name (struct ovl_fs *ofs,struct dentry *origin,struct qstr *name); -struct dentry *ovl_get_index_fh (struct ovl_fs *ofs,struct ovl_fh *fh); +struct dentry *ovl_get_index_origin (struct ovl_fs *ofs,struct dentry *origin);struct dentry *ovl_lookup_index (struct ovl_fs *ofs,struct dentry *upper,struct dentry *origin,bool verify); int ovl_path_next(int idx, struct dentry *dentry, struct path *path,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 ovl: look up the index by the decoded origin
From: Chris Mason <[email protected]>
[ Upstream commit 520ef67f47f69255695859b0008281a384d0bc20 ]
A file opened by file handle on an overlay with nfs_export=on can show the stale lower data of a file that was copied up to the upper layer. While the file opened this way stays in the inode cache, a lookup of the copied up file by path fails with ESTALE for all users. The open can also succeed for a file that was removed, where it has to fail with ESTALE. This happens with a handle that has one byte changed. The handle comes from an NFS client, or from a process that calls open_by_handle_at() with CAP_DAC_READ_SEARCH in the initial user namespace.
When a file in a lower layer is about to be modified, overlayfs first copies it to the upper layer (copy up). With nfs_export=on, each copy up also creates an entry in the index directory, a directory that overlayfs keeps for itself on the upper filesystem.
The handle of an overlay file that comes from a lower layer wraps the handle of its lower inode. Overlayfs calls this lower inode the origin. The overlay handle stays valid after a copy up.
To decode such a handle, ovl_lower_fh_to_d() first decodes the wrapped handle to the origin. If no overlay inode is cached for the origin, it looks in the index directory:
- An index entry there leads to the upper file.
- A whiteout, the marker that overlayfs uses for a removed file, means that the overlay file was removed.
The name of an index entry is the handle that copy up encoded for the origin, as a hex string.
ovl_lower_fh_to_d() builds the name for this lookup from the bytes that the caller passed in. But handles with different bytes can decode to the same inode:
- Overlayfs ignores some flag bits of the handle.
- A lower filesystem can accept a different fid type, extra bytes, or generation 0 for any generation.
Such a handle decodes to the origin but misses the index entry or the whiteout. So the decode returns an overlay inode that has only the lower file.
While that inode is cached, a path lookup of a copied up file fails with ESTALE, since the upper file that the lookup finds does not match the cached inode, which has none.
Reproduced on tmpfs and on ext4 with open_by_handle_at(), after a copy up and a mount cycle. A handle in which one flag bit, the fid type, the length or the generation was changed read the old lower data, and path lookups returned ESTALE.
Fix this by re-encoding the decoded origin and building the index name from that handle.
--- Documentation/filesystems/overlayfs.rst | 3 ++- fs/overlayfs/export.c | 4 ++-- fs/overlayfs/namei.c | 13 ++++++++++--- fs/overlayfs/overlayfs.h | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-)
Documentation/filesystems/overlayfs.rst +2 -1
@@ -638,7 +638,8 @@ When decoding an overlay file handle, the following steps are followed: 1. Find underlying layer by UUID and path type information. 2. Decode the underlying filesystem file handle to underlying dentry. -3. For a lower file handle, lookup the handle in index directory by name. +3. For a lower file handle, encode the decoded underlying inode again and + lookup that handle in index directory by name. 4. If a whiteout is found in index, return ESTALE. This represents an overlay object that was deleted after its file handle was encoded. 5. For a non-directory, instantiate a disconnected overlay dentry from the
fs/overlayfs/export.c +2 -2
@@ -746,9 +746,9 @@ static struct dentry *ovl_lower_fh_to_d(struct super_block *sb, } } -/* Then lookup indexed upper/whiteout by origin fh */ +/* Then lookup indexed upper/whiteout by origin */ if (ofs->indexdir) { - index =ovl_get_index_fh (ofs, fh); + index =ovl_get_index_origin (ofs, origin.dentry); err =PTR_ERR (index);if (IS_ERR (index)) { index =NULL ;
fs/overlayfs/namei.c +10 -3
@@ -730,14 +730,21 @@ int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin,return err; } -/* Lookup index by file handle for NFS export */ -struct dentry *ovl_get_index_fh (struct ovl_fs *ofs,struct ovl_fh *fh) +/* +* Lookup index by decoded origin for NFS export. +* +* The name of an index is the hex of the file handle that copy up encoded. +* The bytes of the handle to decode cannot be used as the name, because a +* lower fs may decode many handles to the same inode. For example, it may +* ignore the fid type, extra fid bytes or a zero generation. +*/ +struct dentry *ovl_get_index_origin (struct ovl_fs *ofs,struct dentry *origin) {struct dentry *index;struct qstr name;int err; - err =ovl_get_index_name_fh (fh, &name); + err =ovl_get_index_name (ofs, origin, &name);if (err)return ERR_PTR (err);
fs/overlayfs/overlayfs.h +1 -1
@@ -643,7 +643,7 @@ struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index,int ovl_verify_index (struct ovl_fs *ofs,struct dentry *index);int ovl_get_index_name (struct ovl_fs *ofs,struct dentry *origin,struct qstr *name); -struct dentry *ovl_get_index_fh (struct ovl_fs *ofs,struct ovl_fh *fh); +struct dentry *ovl_get_index_origin (struct ovl_fs *ofs,struct dentry *origin);struct dentry *ovl_lookup_index (struct ovl_fs *ofs,struct dentry *upper,struct dentry *origin,bool verify);int ovl_path_next (int idx,struct dentry *dentry,struct path *path);
Signature · 1 line
2.53.0