Skip to content

Commit 974e3fe

Browse files
amir73ilbrauner
authored andcommitted
fs: relax assertions on failure to encode file handles
Encoding file handles is usually performed by a filesystem >encode_fh() method that may fail for various reasons. The legacy users of exportfs_encode_fh(), namely, nfsd and name_to_handle_at(2) syscall are ready to cope with the possibility of failure to encode a file handle. There are a few other users of exportfs_encode_{fh,fid}() that currently have a WARN_ON() assertion when ->encode_fh() fails. Relax those assertions because they are wrong. The second linked bug report states commit 16aac5a ("ovl: support encoding non-decodable file handles") in v6.6 as the regressing commit, but this is not accurate. The aforementioned commit only increases the chances of the assertion and allows triggering the assertion with the reproducer using overlayfs, inotify and drop_caches. Triggering this assertion was always possible with other filesystems and other reasons of ->encode_fh() failures and more particularly, it was also possible with the exact same reproducer using overlayfs that is mounted with options index=on,nfs_export=on also on kernels < v6.6. Therefore, I am not listing the aforementioned commit as a Fixes commit. Backport hint: this patch will have a trivial conflict applying to v6.6.y, and other trivial conflicts applying to stable kernels < v6.6. Reported-by: [email protected] Tested-by: [email protected] Closes: https://lore.kernel.org/linux-unionfs/[email protected]/ Reported-by: Dmitry Safonov <[email protected]> Closes: https://lore.kernel.org/linux-fsdevel/CAGrbwDTLt6drB9eaUagnQVgdPBmhLfqqxAf3F+Juqy_o6oP8uw@mail.gmail.com/ Cc: [email protected] Signed-off-by: Amir Goldstein <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 2b2fc0b commit 974e3fe

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

fs/notify/fdinfo.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ static void show_mark_fhandle(struct seq_file *m, struct inode *inode)
4747
size = f->handle_bytes >> 2;
4848

4949
ret = exportfs_encode_fid(inode, (struct fid *)f->f_handle, &size);
50-
if ((ret == FILEID_INVALID) || (ret < 0)) {
51-
WARN_ONCE(1, "Can't encode file handler for inotify: %d\n", ret);
50+
if ((ret == FILEID_INVALID) || (ret < 0))
5251
return;
53-
}
5452

5553
f->handle_type = ret;
5654
f->handle_bytes = size * sizeof(u32);

fs/overlayfs/copy_up.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,8 @@ struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
442442
buflen = (dwords << 2);
443443

444444
err = -EIO;
445-
if (WARN_ON(fh_type < 0) ||
446-
WARN_ON(buflen > MAX_HANDLE_SZ) ||
447-
WARN_ON(fh_type == FILEID_INVALID))
445+
if (fh_type < 0 || fh_type == FILEID_INVALID ||
446+
WARN_ON(buflen > MAX_HANDLE_SZ))
448447
goto out_err;
449448

450449
fh->fb.version = OVL_FH_VERSION;

0 commit comments

Comments
 (0)