From: Dennis Dalessandro <dennis.dalessandro@intel.com>
To: Jason Gunthorpe <jgg@nvidia.com>, Jann Horn <jannh@google.com>
Cc: Mike Marciniszyn <mike.marciniszyn@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: Tue, 1 Sep 2020 08:58:18 -0400 [thread overview]
Message-ID: <624472c4-b585-e950-78b2-eff860f24d64@intel.com> (raw)
In-Reply-To: <20200901002109.GG1152540@nvidia.com>
On 8/31/2020 8:21 PM, Jason Gunthorpe wrote:
> 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.
I sort of recall a bug where we were trusting current and it wasn't
correct. I'll have to see if I can dig up the details and figure out
what's going on here.
>> 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?
I'll look at it closer and either send a patch or an explanation. Thanks
for bringing it to our attention Jann!
-Denny
next prev parent reply other threads:[~2020-09-01 12:58 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
2020-09-01 12:58 ` Dennis Dalessandro [this message]
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=624472c4-b585-e950-78b2-eff860f24d64@intel.com \
--to=dennis.dalessandro@intel.com \
--cc=dean.luick@intel.com \
--cc=dledford@redhat.com \
--cc=ira.weiny@intel.com \
--cc=jannh@google.com \
--cc=jgg@nvidia.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).