Skip to content

Commit e6485a4

Browse files
aagittorvalds
authored andcommitted
userfaultfd: require UFFDIO_API before other ioctls
UFFDIO_API was already forced before read/poll could work. This makes the code more strict to force it also for all other ioctls. All users would already have been required to call UFFDIO_API before invoking other ioctls but this makes it more explicit. This will ensure we can change all ioctls (all but UFFDIO_API/struct uffdio_api) with a bump of uffdio_api.api. There's no actual plan or need to change the API or the ioctl, the current API already should cover fine even the non cooperative usage, but this is just for the longer term future just in case. Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Cc: Pavel Emelyanov <xemul@parallels.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ad465ca commit e6485a4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/userfaultfd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ static ssize_t userfaultfd_read(struct file *file, char __user *buf,
577577

578578
if (ctx->state == UFFD_STATE_WAIT_API)
579579
return -EINVAL;
580-
BUG_ON(ctx->state != UFFD_STATE_RUNNING);
581580

582581
for (;;) {
583582
if (count < sizeof(msg))
@@ -1115,6 +1114,9 @@ static long userfaultfd_ioctl(struct file *file, unsigned cmd,
11151114
int ret = -EINVAL;
11161115
struct userfaultfd_ctx *ctx = file->private_data;
11171116

1117+
if (cmd != UFFDIO_API && ctx->state == UFFD_STATE_WAIT_API)
1118+
return -EINVAL;
1119+
11181120
switch(cmd) {
11191121
case UFFDIO_API:
11201122
ret = userfaultfd_api(ctx, arg);

0 commit comments

Comments
 (0)