Commit 8b26d84a authored by Amir Goldstein's avatar Amir Goldstein Committed by Wen Zhiwei
Browse files

fs: relax assertions on failure to encode file handles

stable inclusion
from stable-v6.6.74
commit f47c834a9131ae64bee3c462f4e610c67b0a000f
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBSPQB

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=f47c834a9131ae64bee3c462f4e610c67b0a000f



--------------------------------

commit 974e3fe0ac61de85015bbe5a4990cf4127b304b2 upstream.

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 16aac5ad ("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: default avatar <syzbot+ec07f6f5ce62b858579f@syzkaller.appspotmail.com>
Tested-by: default avatar <syzbot+ec07f6f5ce62b858579f@syzkaller.appspotmail.com>
Closes: https://lore.kernel.org/linux-unionfs/671fd40c.050a0220.4735a.024f.GAE@google.com/


Reported-by: default avatarDmitry Safonov <dima@arista.com>
Closes: https://lore.kernel.org/linux-fsdevel/CAGrbwDTLt6drB9eaUagnQVgdPBmhLfqqxAf3F+Juqy_o6oP8uw@mail.gmail.com/


Cc: stable@vger.kernel.org
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Link: https://lore.kernel.org/r/20241219115301.465396-1-amir73il@gmail.com


Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarWen Zhiwei <wenzhiwei@kylinos.cn>
parent 64d3173b
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -51,10 +51,8 @@ static void show_mark_fhandle(struct seq_file *m, struct inode *inode)
	size = f.handle.handle_bytes >> 2;

	ret = exportfs_encode_fid(inode, (struct fid *)f.handle.f_handle, &size);
	if ((ret == FILEID_INVALID) || (ret < 0)) {
		WARN_ONCE(1, "Can't encode file handler for inotify: %d\n", ret);
	if ((ret == FILEID_INVALID) || (ret < 0))
		return;
	}

	f.handle.handle_type = ret;
	f.handle.handle_bytes = size * sizeof(u32);
+2 −3
Original line number Diff line number Diff line
@@ -399,9 +399,8 @@ struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct inode *realinode,
	buflen = (dwords << 2);

	err = -EIO;
	if (WARN_ON(fh_type < 0) ||
	    WARN_ON(buflen > MAX_HANDLE_SZ) ||
	    WARN_ON(fh_type == FILEID_INVALID))
	if (fh_type < 0 || fh_type == FILEID_INVALID ||
	    WARN_ON(buflen > MAX_HANDLE_SZ))
		goto out_err;

	fh->fb.version = OVL_FH_VERSION;