From: Alistair Popple <apopple@nvidia.com>
To: David Hildenbrand <david@redhat.com>
Cc: <akpm@linux-foundation.org>, <bsingharora@gmail.com>,
<dan.j.williams@intel.com>, <daniel.vetter@ffwll.ch>,
<gregkh@linuxfoundation.org>, <jglisse@redhat.com>,
<jhubbard@nvidia.com>, <linux-mm@kvack.org>, <smuchun@gmail.com>,
<linux-kernel@vger.kernel.org>,
kernel test robot <oliver.sang@intel.com>
Subject: Re: [PATCH] kernel/resource: Fix return code check in __request_free_mem_region
Date: Wed, 12 May 2021 23:47:26 +1000 [thread overview]
Message-ID: <4030894.8IlaYux4iE@nvdebian> (raw)
In-Reply-To: <7f86af3c-15ba-6ad4-8f6e-1e814a6eac1f@redhat.com>
On Wednesday, 12 May 2021 10:16:41 PM AEST David Hildenbrand wrote:
> On 12.05.21 09:35, Alistair Popple wrote:
> > Splitting an earlier version of a patch that allowed calling
> > __request_region() while holding the resource lock into a series of
> > patches required changing the return code for the newly introduced
> > __request_region_locked().
> >
> > Unfortunately this change was not carried through to a subsequent
> > commit 56fd94919b8b ("kernel/resource: fix locking in
> > request_free_mem_region") in the series. This resulted in a
> > use-after-free due to freeing the struct resource without properly
> > releasing it. Fix this by correcting the return code check so that the
> > struct is not freed if the request to add it was successful.
> >
> > Reported-by: kernel test robot <oliver.sang@intel.com>
> > Fixes: 56fd94919b8b ("kernel/resource: fix locking in
request_free_mem_region")
> > Signed-off-by: Alistair Popple <apopple@nvidia.com>
> > ---
> > kernel/resource.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/resource.c b/kernel/resource.c
> > index 028a5ab18818..ca9f5198a01f 100644
> > --- a/kernel/resource.c
> > +++ b/kernel/resource.c
> > @@ -1805,7 +1805,7 @@ static struct resource
*__request_free_mem_region(struct device *dev,
> > REGION_DISJOINT)
> > continue;
> >
> > - if (!__request_region_locked(res, &iomem_resource, addr,
size,
> > + if (__request_region_locked(res, &iomem_resource, addr,
size,
> > name, 0))
> > break;
> >
> >
>
> Ouch, missed that, would have expected this pops up right away when testing.
Yes, ouch indeed. I am still trying to figure out why I didn't catch this
right away as well. I retested locally and the HMM tests do complete without
causing an oops although they don't all pass. I guess I must have been in a
rush and didn't check the test output properly to see if they actually passed.
> Reviewed-by: David Hildenbrand <david@redhat.com>
Thanks, and sorry for the extra noise.
> --
> Thanks,
>
> David / dhildenb
>
prev parent reply other threads:[~2021-05-12 13:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-12 7:35 Alistair Popple
2021-05-12 12:16 ` David Hildenbrand
2021-05-12 13:47 ` Alistair Popple [this message]
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=4030894.8IlaYux4iE@nvdebian \
--to=apopple@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=bsingharora@gmail.com \
--cc=dan.j.williams@intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=david@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=jglisse@redhat.com \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=oliver.sang@intel.com \
--cc=smuchun@gmail.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