[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20200914210141.GD878166@iweiny-DESK2.sc.intel.com>
Date: Mon, 14 Sep 2020 14:01:41 -0700
From: Ira Weiny <ira.weiny@...el.com>
To: Souptick Joarder <jrdr.linux@...il.com>
Cc: Jason Gunthorpe <jgg@...pe.ca>,
Matthew Wilcox <willy@...radead.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Linux-MM <linux-mm@...ck.org>, linux-kernel@...r.kernel.org,
John Hubbard <jhubbard@...dia.com>
Subject: Re: [PATCH] mm/gup.c: Handling ERR within unpin_user_pages()
On Tue, Sep 15, 2020 at 02:22:33AM +0530, Souptick Joarder wrote:
> On Mon, Sep 14, 2020 at 7:38 PM Jason Gunthorpe <jgg@...pe.ca> wrote:
> >
> > On Mon, Sep 14, 2020 at 07:20:34AM +0530, Souptick Joarder wrote:
> > > On Sun, Sep 13, 2020 at 8:25 PM Matthew Wilcox <willy@...radead.org> wrote:
> > > >
> > > > On Sun, Sep 13, 2020 at 08:02:35PM +0530, Souptick Joarder wrote:
> > > > > It is possible that a buggy caller of unpin_user_pages()
> > > > > (specially in error handling path) may end up calling it with
> > > > > npages < 0 which is unnecessary.
> > > > > @@ -328,6 +328,9 @@ void unpin_user_pages(struct page **pages, unsigned long npages)
> > > > > {
> > > > > unsigned long index;
> > > > >
> > > > > + if (WARN_ON_ONCE(npages < 0))
> > > > > + return;
> > > >
> > > > But npages is unsigned long. So it can't be less than zero.
> > >
> > > Sorry, I missed it.
> > >
> > > Then, it means if npages is assigned with -ERRNO by caller, unpin_user_pages()
> > > may end up calling a big loop, which is unnecessary.
> >
> > How will a caller allocate memory of the right size and still manage
> > to call with the wrong npages? Do you have an example of a broken caller?
>
> These are two broken callers which might end up calling unpin_user_pages()
> with -ERRNO.
> drivers/rapidio/devices/rio_mport_cdev.c#L952
The error here is that nr_pages should not be set to pinned if pinned is < 0.
Why not fix the logic there? Because it is inherently dangerous to set an
unsigned from a signed variable like that.
> drivers/misc/mic/scif/scif_rma.c#L1399
Again this is a caller who is not properly checking error conditions.
>
> They both are in error handling paths, so might not have any serious impact.
> But theoretically possible.
Actually I think they might have serious problems so they both should be fixed.
In the end this patch just can't work because npages can't be < 0 like Matthew
said.
Ira
Powered by blists - more mailing lists