* [PATCH] dma: fix error handling on out of memory
@ 2010-10-11 9:44 Michael S. Tsirkin
2010-10-14 0:10 ` Dan Williams
0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2010-10-11 9:44 UTC (permalink / raw)
To: Dan Williams, Tejun Heo, linux-kernel, Maciej Sosnowski,
David S. Miller
Cc: stable
get_user_pages might return less pages than requested. If this happens
for the first iovec in dma_pin_iovec_pages, then nr_iovecs is 0 and so
dma_unpin_iovec_pages will not unpin any pages, leaking pinned memory.
A similar off by one would trigger for any of the following entries.
Fix by updating nr_iovecs and nr_pages in this case.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
Error handling in dma_pin_iovec_pages still looks wrong to me. Am I
missing something? The following patch against 2.6.36-rc7 was under
some very light testing by me.
Thanks,
drivers/dma/iovlock.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/drivers/dma/iovlock.c b/drivers/dma/iovlock.c
index bb48a57..21ed8f3 100644
--- a/drivers/dma/iovlock.c
+++ b/drivers/dma/iovlock.c
@@ -107,10 +107,16 @@ struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len)
NULL);
up_read(¤t->mm->mmap_sem);
- if (ret != page_list->nr_pages)
+ if (unlikely(ret < 0))
goto unpin;
local_list->nr_iovecs = i + 1;
+
+ if (unlikely(ret != page_list->nr_pages)) {
+ page_list->nr_pages = ret;
+ goto unpin;
+ }
+
}
return local_list;
--
MST
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] dma: fix error handling on out of memory
2010-10-11 9:44 [PATCH] dma: fix error handling on out of memory Michael S. Tsirkin
@ 2010-10-14 0:10 ` Dan Williams
2010-10-14 8:11 ` Michael S. Tsirkin
0 siblings, 1 reply; 3+ messages in thread
From: Dan Williams @ 2010-10-14 0:10 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Tejun Heo, linux-kernel, Maciej Sosnowski, David S. Miller,
stable
On Mon, Oct 11, 2010 at 2:44 AM, Michael S. Tsirkin <mst@redhat.com> wrote:
> get_user_pages might return less pages than requested. If this happens
> for the first iovec in dma_pin_iovec_pages, then nr_iovecs is 0 and so
> dma_unpin_iovec_pages will not unpin any pages, leaking pinned memory.
> A similar off by one would trigger for any of the following entries.
>
> Fix by updating nr_iovecs and nr_pages in this case.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>
> Error handling in dma_pin_iovec_pages still looks wrong to me. Am I
> missing something?
Still looks wrong it what way? You make sure that nr_iovecs is
incremented so that the partial page list is freed, and we only walk
the initialized entries in pinned_list.
--
Dan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dma: fix error handling on out of memory
2010-10-14 0:10 ` Dan Williams
@ 2010-10-14 8:11 ` Michael S. Tsirkin
0 siblings, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2010-10-14 8:11 UTC (permalink / raw)
To: Dan Williams
Cc: Tejun Heo, linux-kernel, Maciej Sosnowski, David S. Miller,
stable
On Wed, Oct 13, 2010 at 05:10:25PM -0700, Dan Williams wrote:
> On Mon, Oct 11, 2010 at 2:44 AM, Michael S. Tsirkin <mst@redhat.com> wrote:
> > get_user_pages might return less pages than requested. If this happens
> > for the first iovec in dma_pin_iovec_pages, then nr_iovecs is 0 and so
> > dma_unpin_iovec_pages will not unpin any pages, leaking pinned memory.
> > A similar off by one would trigger for any of the following entries.
> >
> > Fix by updating nr_iovecs and nr_pages in this case.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >
> > Error handling in dma_pin_iovec_pages still looks wrong to me. Am I
> > missing something?
>
> Still looks wrong it what way? You make sure that nr_iovecs is
> incremented so that the partial page list is freed, and we only walk
> the initialized entries in pinned_list.
In that before the patch, if get_user_pages returns less pages than
requested, we would leak pinned memory. Right?
> --
> Dan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-10-14 8:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-11 9:44 [PATCH] dma: fix error handling on out of memory Michael S. Tsirkin
2010-10-14 0:10 ` Dan Williams
2010-10-14 8:11 ` Michael S. Tsirkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox