Skip to content

Commit bf0fbf5

Browse files
braunergregkh
authored andcommitted
pidfs: validate extensible ioctls
[ Upstream commit 3c17001b21b9f168c957ced9384abe969019b609 ] Validate extensible ioctls stricter than we do now. Reviewed-by: Aleksa Sarai <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 9f0f659 commit bf0fbf5

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

fs/pidfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ static bool pidfs_ioctl_valid(unsigned int cmd)
440440
* erronously mistook the file descriptor for a pidfd.
441441
* This is not perfect but will catch most cases.
442442
*/
443-
return (_IOC_TYPE(cmd) == _IOC_TYPE(PIDFD_GET_INFO));
443+
return extensible_ioctl_valid(cmd, PIDFD_GET_INFO, PIDFD_INFO_SIZE_VER0);
444444
}
445445

446446
return false;

include/linux/fs.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4025,4 +4025,18 @@ static inline bool vfs_empty_path(int dfd, const char __user *path)
40254025

40264026
int generic_atomic_write_valid(struct kiocb *iocb, struct iov_iter *iter);
40274027

4028+
static inline bool extensible_ioctl_valid(unsigned int cmd_a,
4029+
unsigned int cmd_b, size_t min_size)
4030+
{
4031+
if (_IOC_DIR(cmd_a) != _IOC_DIR(cmd_b))
4032+
return false;
4033+
if (_IOC_TYPE(cmd_a) != _IOC_TYPE(cmd_b))
4034+
return false;
4035+
if (_IOC_NR(cmd_a) != _IOC_NR(cmd_b))
4036+
return false;
4037+
if (_IOC_SIZE(cmd_a) < min_size)
4038+
return false;
4039+
return true;
4040+
}
4041+
40284042
#endif /* _LINUX_FS_H */

0 commit comments

Comments
 (0)