linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peilin Ye <yepeilin.cs@gmail.com>
To: Daniel Colascione <dancol@google.com>
Cc: timmurray@google.com, selinux@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, viro@zeniv.linux.org.uk,
	paul@paul-moore.com, nnk@google.com, sds@tycho.nsa.gov,
	lokeshgidra@google.com, jmorris@namei.org
Subject: Reporting a use-after-free read bug in userfaultfd_release()
Date: Fri, 17 Jul 2020 07:45:32 -0400	[thread overview]
Message-ID: <20200717114532.GA688728@PWN> (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

                 reply	other threads:[~2020-07-17 11:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200717114532.GA688728@PWN \
    --to=yepeilin.cs@gmail.com \
    --cc=20200401213903.182112-4-dancol@google.com \
    --cc=dancol@google.com \
    --cc=jmorris@namei.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=lokeshgidra@google.com \
    --cc=nnk@google.com \
    --cc=paul@paul-moore.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@vger.kernel.org \
    --cc=timmurray@google.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).