linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Cc: dledford@redhat.com, linux-rdma@vger.kernel.org,
	Mike Marciniszyn <mike.marciniszyn@cornelisnetworks.com>,
	stable@vger.kernel.org, linux-mm@kvack.org,
	Ira Weiny <ira.weiny@intel.com>
Subject: Re: [PATCH for-rc v4] IB/hfi1: Ensure correct mm is used at all times
Date: Wed, 25 Nov 2020 11:02:24 -0400	[thread overview]
Message-ID: <20201125150224.GO5487@ziepe.ca> (raw)
In-Reply-To: <20201123165024.158913.71029.stgit@awfm-01.aw.intel.com>

On Mon, Nov 23, 2020 at 11:50:24AM -0500, Dennis Dalessandro wrote:
> @@ -133,8 +121,16 @@ void hfi1_mmu_rb_unregister(struct mmu_rb_handler *handler)
>  	unsigned long flags;
>  	struct list_head del_list;
>  
> +	/*
> +	 * do_exit() calls exit_mm() before exit_files() which would call close
> +	 * and end up in here. If there is no mm, then its a kernel thread and
> +	 * we need to let it continue the removal.
> +	 */
> +	if (current->mm && (handler->mn.mm != current->mm))
> +		return;
> +
>  	/* Unregister first so we don't get any more notifications. */
> -	mmu_notifier_unregister(&handler->mn, handler->mm);
> +	mmu_notifier_unregister(&handler->mn, handler->mn.mm);

This logic cannot be right.. The only caller does:

		if (pq->handler)
			hfi1_mmu_rb_unregister(pq->handler);
[..]
		kfree(pq);

So this is leaking the mmu_notifier registration if the user manages
to trigger hfi1_user_sdma_free_queues() from another process.

Since hfi1_user_sdma_free_queues() is called from close() it doesn't
look OK.

When the object that creates the notifier is destroyed the notifier
should be deleted unconditionally.

Only accesses to a VA should be qualified to ensure that a notifier is
registered on current->mm before touching the VA.

Jason


  reply	other threads:[~2020-11-25 15:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 16:50 [PATCH for-rc v4] IB/hfi1: Ensure correct mm is used at all times Dennis Dalessandro
2020-11-25 15:02 ` Jason Gunthorpe [this message]
2020-11-25 19:15   ` Dennis Dalessandro

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=20201125150224.GO5487@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=dledford@redhat.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-mm@kvack.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mike.marciniszyn@cornelisnetworks.com \
    --cc=stable@vger.kernel.org \
    /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).