Skip to content

Commit abe6acf

Browse files
gnoackbrauner
authored andcommitted
fs: Return ENOTTY directly if FS_IOC_GETUUID or FS_IOC_GETFSSYSFSPATH fail
These IOCTL commands should be implemented by setting attributes on the superblock, rather than in the IOCTL hooks in struct file_operations. By returning -ENOTTY instead of -ENOIOCTLCMD, we instruct the fs/ioctl.c logic to return -ENOTTY immediately, rather than attempting to call f_op->unlocked_ioctl() or f_op->compat_ioctl() as a fallback. Why this is safe: Before this change, fs/ioctl.c would unsuccessfully attempt calling the IOCTL hooks, and then return -ENOTTY. By returning -ENOTTY directly, we return the same error code immediately, but save ourselves the fallback attempt. Motivation: This simplifies the logic for these IOCTL commands and lets us reason about the side effects of these IOCTLs more easily. It will be possible to permit these IOCTLs under LSM IOCTL policies, without having to worry about them getting dispatched to problematic device drivers (which sometimes do work before looking at the IOCTL command number). Link: https://lore.kernel.org/all/cnwpkeovzbumhprco7q2c2y6zxzmxfpwpwe3tyy6c3gg2szgqd@vfzjaw5v5imr/ Cc: Kent Overstreet <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Jan Kara <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Darrick J. Wong <[email protected]> Cc: Theodore Ts'o <[email protected]> Cc: Josef Bacik <[email protected]> Signed-off-by: Günther Noack <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Kent Overstreet <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent fec50db commit abe6acf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ static int ioctl_getfsuuid(struct file *file, void __user *argp)
769769
struct fsuuid2 u = { .len = sb->s_uuid_len, };
770770

771771
if (!sb->s_uuid_len)
772-
return -ENOIOCTLCMD;
772+
return -ENOTTY;
773773

774774
memcpy(&u.uuid[0], &sb->s_uuid, sb->s_uuid_len);
775775

@@ -781,7 +781,7 @@ static int ioctl_get_fs_sysfs_path(struct file *file, void __user *argp)
781781
struct super_block *sb = file_inode(file)->i_sb;
782782

783783
if (!strlen(sb->s_sysfs_name))
784-
return -ENOIOCTLCMD;
784+
return -ENOTTY;
785785

786786
struct fs_sysfs_path u = {};
787787

0 commit comments

Comments
 (0)