From: Jason Gunthorpe <jgg@nvidia.com>
To: Jann Horn <jannh@google.com>
Cc: Mike Marciniszyn <mike.marciniszyn@intel.com>,
Dennis Dalessandro <dennis.dalessandro@intel.com>,
Ira Weiny <ira.weiny@intel.com>, Linux-MM <linux-mm@kvack.org>,
Doug Ledford <dledford@redhat.com>, <linux-rdma@vger.kernel.org>,
Dean Luick <dean.luick@intel.com>
Subject: Re: buggy-looking mm_struct refcounting in HFI1 infiniband driver
Date: Mon, 31 Aug 2020 21:21:09 -0300 [thread overview]
Message-ID: <20200901002109.GG1152540@nvidia.com> (raw)
In-Reply-To: <CAG48ez2EFXnDEue=bOs6n01FHGa4rUnwET6hBVNjcKoMjR9Y_Q@mail.gmail.com>
On Tue, Sep 01, 2020 at 01:45:06AM +0200, Jann Horn wrote:
> struct hfi1_filedata has a member ->mm that holds a ->mm_count reference:
>
> static int hfi1_file_open(struct inode *inode, struct file *fp)
> {
> struct hfi1_filedata *fd;
> [...]
> fd->mm = current->mm;
> mmgrab(fd->mm); // increments ->mm_count
> [...]
> }
Yikes, gross.
> However, e.g. the call chain hfi1_file_ioctl() -> user_exp_rcv_setup()
> -> hfi1_user_exp_rcv_setup() -> pin_rcv_pages() ->
> hfi1_acquire_user_pages() -> pin_user_pages_fast() can end up
> traversing VMAs without holding any ->mm_users reference, as far as I
> can tell. That will probably result in kernel memory corruption if
> that races the wrong way with an exiting task (with the ioctl() call
> coming from a task whose ->mm is different from fd->mm).
It looks like this path should be using current and storing the grab'd
mm in the tidbuf for later use by hfi1_release_user_pages()
The only other use of file->mm is to setup a notifier, but this is
also under hfi1_user_exp_rcv_setup() so it should just use tidbuf->mm
== current anyhow.
The pq->mm looks similar, looks like the pq should use current->mm,
and it sets up an old-style notifier, but I didn't check carefully if
all the call paths are linked back to an ioctl..
It doesn't make sense that a RDMA driver would do any page pinning
outside an ioctl, so it should always use current.
> Disclaimer: I haven't actually tested this - I just stumbled over it
> while working on some other stuff, and I don't have any infiniband
> hardware to test with. So it might well be that I just missed an
> mmget_not_zero() somewhere, or something like that.
It looks wrong to me too.
Dennis?
Jason
next prev parent reply other threads:[~2020-09-01 0:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-31 23:45 buggy-looking mm_struct refcounting in HFI1 infiniband driver Jann Horn
2020-09-01 0:21 ` Jason Gunthorpe [this message]
2020-09-01 12:58 ` Dennis Dalessandro
2020-09-01 13:00 ` Jason Gunthorpe
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=20200901002109.GG1152540@nvidia.com \
--to=jgg@nvidia.com \
--cc=dean.luick@intel.com \
--cc=dennis.dalessandro@intel.com \
--cc=dledford@redhat.com \
--cc=ira.weiny@intel.com \
--cc=jannh@google.com \
--cc=linux-mm@kvack.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mike.marciniszyn@intel.com \
/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).