Skip to contentSkip to conversation

Reporting a use-after-free read bug in userfaultfd_release()

DISCUSSION Peilin Ye 1 participant 1 message Jul 17, 2020

Subsystems (4)
lore
Share & tools
lore

Peilin Ye

author
#0 lore raw

Hi all,

Syzbot reported the following use-after-free bug in userfaultfd_release():

	https://syzkaller.appspot.com/bug?id=4b9e5aea757b678d9939c364e50212354a3480a6

It seems to be caused by this patch. I took a look at the stack trace. In the patch:

	fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
	if (fd < 0) {
		fput(file);
		goto out;
	}

If get_unused_fd_flags() fails, ctx is freed. Later however, before returning back to userland, userfaultfd_release() is called and tries to use ctx again, causing a use-after-free bug.

The syzbot reproducer does a setrlimit() then a userfaultfd(). The former sets a hard limit on number of open files to zero, which causes get_unused_fd_flags() to fail.

Thank you,

Peilin Ye