All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zheng Wang <zyytlz.wz@163.com>
To: bskeggs@redhat.com
Cc: kherbst@redhat.com, lyude@redhat.com, airlied@gmail.com,
	hackerzheng666@gmail.com, alex000young@gmail.com,
	security@kernel.org, daniel@ffwll.ch,
	dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, Zheng Wang <zyytlz.wz@163.com>
Subject: [PATCH] drm/nouveau/mmu: fix Use after Free bug in nvkm_vmm_node_split
Date: Fri, 30 Dec 2022 15:27:58 +0800	[thread overview]
Message-ID: <20221230072758.443644-1-zyytlz.wz@163.com> (raw)

Here is a function call chain.
nvkm_vmm_pfn_map->nvkm_vmm_pfn_split_merge->nvkm_vmm_node_split
If nvkm_vma_tail return NULL in nvkm_vmm_node_split, it will
finally invoke nvkm_vmm_node_merge->nvkm_vmm_node_delete, which
will free the vma. However, nvkm_vmm_pfn_map didn't notice that.
It goes into next label and UAF happens.

Fix it by returning the return-value of nvkm_vmm_node_merge
instead of NULL.

Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
index ae793f400ba1..84d6fc87b2e8 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
@@ -937,8 +937,8 @@ nvkm_vmm_node_split(struct nvkm_vmm *vmm,
 	if (vma->size != size) {
 		struct nvkm_vma *tmp;
 		if (!(tmp = nvkm_vma_tail(vma, vma->size - size))) {
-			nvkm_vmm_node_merge(vmm, prev, vma, NULL, vma->size);
-			return NULL;
+			tmp = nvkm_vmm_node_merge(vmm, prev, vma, NULL, vma->size);
+			return tmp;
 		}
 		tmp->part = true;
 		nvkm_vmm_node_insert(vmm, tmp);
-- 
2.25.1


WARNING: multiple messages have this Message-ID (diff)
From: Zheng Wang <zyytlz.wz@163.com>
To: bskeggs@redhat.com
Cc: alex000young@gmail.com, security@kernel.org, kherbst@redhat.com,
	nouveau@lists.freedesktop.org, hackerzheng666@gmail.com,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Zheng Wang <zyytlz.wz@163.com>
Subject: [PATCH] drm/nouveau/mmu: fix Use after Free bug in nvkm_vmm_node_split
Date: Fri, 30 Dec 2022 15:27:58 +0800	[thread overview]
Message-ID: <20221230072758.443644-1-zyytlz.wz@163.com> (raw)

Here is a function call chain.
nvkm_vmm_pfn_map->nvkm_vmm_pfn_split_merge->nvkm_vmm_node_split
If nvkm_vma_tail return NULL in nvkm_vmm_node_split, it will
finally invoke nvkm_vmm_node_merge->nvkm_vmm_node_delete, which
will free the vma. However, nvkm_vmm_pfn_map didn't notice that.
It goes into next label and UAF happens.

Fix it by returning the return-value of nvkm_vmm_node_merge
instead of NULL.

Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
index ae793f400ba1..84d6fc87b2e8 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
@@ -937,8 +937,8 @@ nvkm_vmm_node_split(struct nvkm_vmm *vmm,
 	if (vma->size != size) {
 		struct nvkm_vma *tmp;
 		if (!(tmp = nvkm_vma_tail(vma, vma->size - size))) {
-			nvkm_vmm_node_merge(vmm, prev, vma, NULL, vma->size);
-			return NULL;
+			tmp = nvkm_vmm_node_merge(vmm, prev, vma, NULL, vma->size);
+			return tmp;
 		}
 		tmp->part = true;
 		nvkm_vmm_node_insert(vmm, tmp);
-- 
2.25.1


WARNING: multiple messages have this Message-ID (diff)
From: Zheng Wang <zyytlz.wz@163.com>
To: bskeggs@redhat.com
Cc: alex000young@gmail.com, security@kernel.org,
	nouveau@lists.freedesktop.org, hackerzheng666@gmail.com,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	daniel@ffwll.ch, Zheng Wang <zyytlz.wz@163.com>
Subject: [Nouveau] [PATCH] drm/nouveau/mmu: fix Use after Free bug in nvkm_vmm_node_split
Date: Fri, 30 Dec 2022 15:27:58 +0800	[thread overview]
Message-ID: <20221230072758.443644-1-zyytlz.wz@163.com> (raw)

Here is a function call chain.
nvkm_vmm_pfn_map->nvkm_vmm_pfn_split_merge->nvkm_vmm_node_split
If nvkm_vma_tail return NULL in nvkm_vmm_node_split, it will
finally invoke nvkm_vmm_node_merge->nvkm_vmm_node_delete, which
will free the vma. However, nvkm_vmm_pfn_map didn't notice that.
It goes into next label and UAF happens.

Fix it by returning the return-value of nvkm_vmm_node_merge
instead of NULL.

Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
index ae793f400ba1..84d6fc87b2e8 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
@@ -937,8 +937,8 @@ nvkm_vmm_node_split(struct nvkm_vmm *vmm,
 	if (vma->size != size) {
 		struct nvkm_vma *tmp;
 		if (!(tmp = nvkm_vma_tail(vma, vma->size - size))) {
-			nvkm_vmm_node_merge(vmm, prev, vma, NULL, vma->size);
-			return NULL;
+			tmp = nvkm_vmm_node_merge(vmm, prev, vma, NULL, vma->size);
+			return tmp;
 		}
 		tmp->part = true;
 		nvkm_vmm_node_insert(vmm, tmp);
-- 
2.25.1


             reply	other threads:[~2022-12-30  7:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-30  7:27 Zheng Wang [this message]
2022-12-30  7:27 ` [Nouveau] [PATCH] drm/nouveau/mmu: fix Use after Free bug in nvkm_vmm_node_split Zheng Wang
2022-12-30  7:27 ` Zheng Wang
2023-01-03 14:07 ` Takashi Iwai
2023-01-03 14:07   ` Takashi Iwai
2023-01-03 14:07   ` [Nouveau] " Takashi Iwai
2023-01-27 12:10   ` Takashi Iwai
2023-01-27 12:10     ` Takashi Iwai
2023-01-27 12:10     ` Takashi Iwai
2023-01-28  2:17     ` [Nouveau] " Danilo Krummrich
2023-01-28  2:17       ` Danilo Krummrich
2023-01-28  2:17       ` Danilo Krummrich
2023-01-28  8:13       ` Takashi Iwai
2023-01-28  8:13         ` Takashi Iwai
2023-01-28  8:13         ` [Nouveau] " Takashi Iwai

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=20221230072758.443644-1-zyytlz.wz@163.com \
    --to=zyytlz.wz@163.com \
    --cc=airlied@gmail.com \
    --cc=alex000young@gmail.com \
    --cc=bskeggs@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hackerzheng666@gmail.com \
    --cc=kherbst@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyude@redhat.com \
    --cc=nouveau@lists.freedesktop.org \
    --cc=security@kernel.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 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.