All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alistair Popple <apopple@nvidia.com>
To: <akpm@linux-foundation.org>
Cc: <bsingharora@gmail.com>, <dan.j.williams@intel.com>,
	<daniel.vetter@ffwll.ch>, <david@redhat.com>,
	<gregkh@linuxfoundation.org>, <jglisse@redhat.com>,
	<jhubbard@nvidia.com>, <linux-mm@kvack.org>, <smuchun@gmail.com>,
	<linux-kernel@vger.kernel.org>,
	Alistair Popple <apopple@nvidia.com>,
	kernel test robot <oliver.sang@intel.com>
Subject: [PATCH] kernel/resource: Fix return code check in __request_free_mem_region
Date: Wed, 12 May 2021 17:35:28 +1000	[thread overview]
Message-ID: <20210512073528.22334-1-apopple@nvidia.com> (raw)

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;
 
-- 
2.20.1


             reply	other threads:[~2021-05-12  7:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12  7:35 Alistair Popple [this message]
2021-05-12 12:16 ` [PATCH] kernel/resource: Fix return code check in __request_free_mem_region David Hildenbrand
2021-05-12 13:47   ` Alistair Popple

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=20210512073528.22334-1-apopple@nvidia.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.