public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: kosaki.motohiro@jp.fujitsu.com,
	Linus Torvalds <torvalds@osdl.org>, Andrew Morton <akpm@osdl.org>,
	Nick Piggin <nickpiggin@yahoo.com.au>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Jeff Moyer <jmoyer@redhat.com>,
	linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	Maciej Sosnowski <maciej.sosnowski@intel.com>,
	"David S. Miller" <davem@davemloft.net>,
	Chris Leech <christopher.leech@intel.com>,
	netdev@vger.kernel.org
Subject: [RFC][PATCH v3 6/6] fix wrong get_user_pages usage in iovlock.c
Date: Tue, 14 Apr 2009 15:23:13 +0900 (JST)	[thread overview]
Message-ID: <20090414152151.C659.A69D9226@jp.fujitsu.com> (raw)
In-Reply-To: <20090414151204.C647.A69D9226@jp.fujitsu.com>

I don't have NET-DMA usable device. I hope to get expert review.

=========================
Subject: [Untested][RFC][PATCH] fix wrong get_user_pages usage in iovlock.c

	down_read(mmap_sem)
	get_user_pages()
	up_read(mmap_sem)

is fork unsafe.
fix it.

Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Maciej Sosnowski <maciej.sosnowski@intel.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Chris Leech <christopher.leech@intel.com>
Cc: netdev@vger.kernel.org
---
 drivers/dma/iovlock.c |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

Index: b/drivers/dma/iovlock.c
===================================================================
--- a/drivers/dma/iovlock.c	2009-02-21 16:53:23.000000000 +0900
+++ b/drivers/dma/iovlock.c	2009-04-13 04:46:02.000000000 +0900
@@ -94,18 +94,10 @@ struct dma_pinned_list *dma_pin_iovec_pa
 		pages += page_list->nr_pages;
 
 		/* pin pages down */
-		down_read(&current->mm->mmap_sem);
-		ret = get_user_pages(
-			current,
-			current->mm,
-			(unsigned long) iov[i].iov_base,
-			page_list->nr_pages,
-			1,	/* write */
-			0,	/* force */
-			page_list->pages,
-			NULL);
-		up_read(&current->mm->mmap_sem);
-
+		down_read(&current->mm->mm_pinned_sem);
+		ret = get_user_pages_fast((unsigned long) iov[i].iov_base,
+					  page_list->nr_pages, 1,
+					  page_list->pages);
 		if (ret != page_list->nr_pages)
 			goto unpin;
 
@@ -127,6 +119,8 @@ void dma_unpin_iovec_pages(struct dma_pi
 	if (!pinned_list)
 		return;
 
+	up_read(&current->mm->mm_pinned_sem);
+
 	for (i = 0; i < pinned_list->nr_iovecs; i++) {
 		struct dma_page_list *page_list = &pinned_list->page_list[i];
 		for (j = 0; j < page_list->nr_pages; j++) {



       reply	other threads:[~2009-04-14  6:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090414151204.C647.A69D9226@jp.fujitsu.com>
2009-04-14  6:23 ` KOSAKI Motohiro [this message]
2009-04-14  6:56   ` [RFC][PATCH v3 6/6] fix wrong get_user_pages usage in iovlock.c Nick Piggin
2009-04-14  6:58     ` KOSAKI Motohiro
2009-04-15  8:48       ` KOSAKI Motohiro
2009-04-17 15:07         ` Sosnowski, Maciej
2009-04-19 12:37           ` KOSAKI Motohiro
2009-04-23 12:48             ` Sosnowski, Maciej
2009-04-14  8:41 ` [RFC][PATCH 0/6] IO pinning(get_user_pages()) vs fork race fix Nick Piggin
2009-04-14  9:19   ` KOSAKI Motohiro
2009-04-14  9:37     ` Nick Piggin

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=20090414152151.C659.A69D9226@jp.fujitsu.com \
    --to=kosaki.motohiro@jp.fujitsu.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@osdl.org \
    --cc=christopher.leech@intel.com \
    --cc=davem@davemloft.net \
    --cc=jmoyer@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=maciej.sosnowski@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=nickpiggin@yahoo.com.au \
    --cc=torvalds@osdl.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