nsfs: handle inode number mismatches gracefully in file handles
PATCH v2 1/1 nsfs: handle inode number mismatches gracefully in file handles
Replace VFS_WARN_ON_ONCE() with graceful error handling when file handles contain inode numbers that don't match the actual namespace inode. This prevents userspace from triggering kernel warnings by providing malformed file handles to open_by_handle_at().
The issue occurs when userspace provides a file handle with valid namespace type and ID that successfully locates a namespace, but specifies an incorrect inode number. Previously, this would trigger VFS_WARN_ON_ONCE() when comparing the real inode number against the provided value.
Since file handle data is user-controllable, inode number mismatches should be treated as invalid input rather than kernel consistency errors. Handle this case by returning NULL to indicate the file handle is invalid, rather than warning about what is essentially user input validation.
Changes in v2:
- Handle all inode number mismatches, not just zero, as suggested by Jan Kara
- Replace warning with graceful error handling for better architecture
--- fs/nsfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/nsfs.c +3 -2
@@ -490,8 +490,9 @@ static struct dentry *nsfs_fh_to_dentry(struct super_block *sb, struct fid *fh,VFS_WARN_ON_ONCE (ns->ns_id != fid->ns_id);VFS_WARN_ON_ONCE (ns->ops->type != fid->ns_type); -VFS_WARN_ON_ONCE (ns->inum != fid->ns_inum); - +/* Someone is playing games and passing invalid file handles? */ +if (ns->inum != fid->ns_inum) +return NULL ;if (!refcount_inc_not_zero (&ns->count))return NULL ; }
Signature · 1 line
2.43.0
Quoted 17 lines · Deepanshu Kartikey
Replace
VFS_WARN_ON_ONCE()with graceful error handling when file handles contain inode numbers that don't match the actual namespace inode. This prevents userspace from triggering kernel warnings by providing malformed file handles toopen_by_handle_at().The issue occurs when userspace provides a file handle with valid namespace type and ID that successfully locates a namespace, but specifies an incorrect inode number. Previously, this would trigger
VFS_WARN_ON_ONCE()when comparing the real inode number against the provided value.Since file handle data is user-controllable, inode number mismatches should be treated as invalid input rather than kernel consistency errors. Handle this case by returning NULL to indicate the file handle is invalid, rather than warning about what is essentially user input validation.
Quoted 3 lines
Changes in v2:
- Handle all inode number mismatches, not just zero, as suggested by Jan Kara
- Replace warning with graceful error handling for better architecture
This 'Changes' bit belongs below the diffstat (so that it doesn't get included in git commit log). Otherwise looks good so feel free to add:
Honza
Quoted 27 lines
Reported-by [email protected]Suggested-by Jan Kara <[email protected]>Signed-off-by Deepanshu Kartikey <[email protected]>--- fs/nsfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/nsfs.c +3
-2@@ -490,8 +490,9 @@ static struct dentry *nsfs_fh_to_dentry(struct super_block *sb, struct fid *fh,VFS_WARN_ON_ONCE (ns->ns_id != fid->ns_id);VFS_WARN_ON_ONCE (ns->ops->type != fid->ns_type); -VFS_WARN_ON_ONCE (ns->inum != fid->ns_inum); - +/* Someone is playing games and passing invalid file handles? */ +if (ns->inum != fid->ns_inum) +return NULL ;if (!refcount_inc_not_zero (&ns->count))return NULL ; }Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR