diff --git a/fs/verity/enable.c b/fs/verity/enable.c index 94c2bebfb756..6e31d512d76a 100644 --- a/fs/verity/enable.c +++ b/fs/verity/enable.c @@ -358,6 +358,13 @@ int fsverity_ioctl_enable(struct file *filp, const void __user *uarg) err = file_permission(filp, MAY_WRITE); if (err) return err; + /* + * __kernel_read() is used while building the Merkle tree. So, we can't + * allow file descriptors that were opened for ioctl access only, using + * the special nonstandard access mode 3. O_RDONLY only, please! + */ + if (!(filp->f_mode & FMODE_READ)) + return -EBADF; if (IS_APPEND(inode)) return -EPERM;