dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: =?gb18030?B?s68=?= <1002992920@qq.com>
To: =?gb18030?B?R3JlZyBLSA==?= <gregkh@linuxfoundation.org>,
	=?gb18030?B?WmhlbmcgSGFja2Vy?= <hackerzheng666@gmail.com>
Cc: =?gb18030?B?YWxleDAwMHlvdW5nQGdtYWlsLmNvbQ==?=
	<alex000young@gmail.com>,
	=?gb18030?B?c2VjdXJpdHlAa2VybmVsLm9yZw==?= <security@kernel.org>,
	=?gb18030?B?dHZydGtvLnVyc3VsaW5AbGludXguaW50ZWwuY29t?=
	<tvrtko.ursulin@linux.intel.com>,
	=?gb18030?B?YWlybGllZEBsaW51eC5pZQ==?= <airlied@linux.ie>,
	=?gb18030?B?aW50ZWwtZ2Z4QGxpc3RzLmZyZWVkZXNrdG9wLm9yZw==?=
	<intel-gfx@lists.freedesktop.org>,
	=?gb18030?B?bGludXgta2VybmVsQHZnZXIua2VybmVsLm9yZw==?=
	<linux-kernel@vger.kernel.org>,
	=?gb18030?B?ZHJpLWRldmVsQGxpc3RzLmZyZWVkZXNrdG9wLm9yZw==?=
	<dri-devel@lists.freedesktop.org>,
	=?gb18030?B?cm9kcmlnby52aXZpQGludGVsLmNvbQ==?=
	<rodrigo.vivi@intel.com>,
	=?gb18030?B?aW50ZWwtZ3Z0LWRldkBsaXN0cy5mcmVlZGVza3RvcC5vcmc=?=
	<intel-gvt-dev@lists.freedesktop.org>,
	=?gb18030?B?emhpLmEud2FuZ0BpbnRlbC5jb20=?= <zhi.a.wang@intel.com>
Subject: Re: [PATCH] drm/i915/gvt: fix double-free bug in split_2MB_gtt_entry.
Date: Mon, 19 Sep 2022 01:08:44 +0800	[thread overview]
Message-ID: <tencent_36196E8CD75A09D21A47CE65C842E97EF805@qq.com> (raw)
In-Reply-To: <YyWOh+jGvmSdrHqz@kroah.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 3114 bytes --]

From afe79848cb74cc8e45ab426d13fa2394c87e0422 Mon Sep 17 00:00:00 2001
From: xmzyshypnc &lt;1002992920@qq.com&gt;
Date: Fri, 16 Sep 2022 23:48:23 +0800
Subject: [PATCH] drm/i915/gvt: fix double-free bug in split_2MB_gtt_entry

There is a double-free security bug in split_2MB_gtt_entry.

Here is a calling chain :
ppgtt_populate_spt-&gt;ppgtt_populate_shadow_entry-&gt;split_2MB_gtt_entry.

If intel_gvt_dma_map_guest_page failed, it will call
ppgtt_invalidate_spt, which will finally call ppgtt_free_spt and
kfree(spt). But the caller does not notice that, and it will call
ppgtt_free_spt again in error path.

Fix this by only freeing spt in ppgtt_invalidate_spt in good case.

Signed-off-by: xmzyshypnc &lt;1002992920@qq.com&gt;
---
 drivers/gpu/drm/i915/gvt/gtt.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
index ce0eb03709c3..550519f0acca 100644
--- a/drivers/gpu/drm/i915/gvt/gtt.c
+++ b/drivers/gpu/drm/i915/gvt/gtt.c
@@ -959,7 +959,7 @@ static inline int ppgtt_put_spt(struct intel_vgpu_ppgtt_spt *spt)
 	return atomic_dec_return(&amp;spt-&gt;refcount);
 }
 
-static int ppgtt_invalidate_spt(struct intel_vgpu_ppgtt_spt *spt);
+static int ppgtt_invalidate_spt(struct intel_vgpu_ppgtt_spt *spt, int is_error);
 
 static int ppgtt_invalidate_spt_by_shadow_entry(struct intel_vgpu *vgpu,
 		struct intel_gvt_gtt_entry *e)
@@ -995,7 +995,7 @@ static int ppgtt_invalidate_spt_by_shadow_entry(struct intel_vgpu *vgpu,
 				ops-&gt;get_pfn(e));
 		return -ENXIO;
 	}
-	return ppgtt_invalidate_spt(s);
+	return ppgtt_invalidate_spt(s, 0);
 }
 
 static inline void ppgtt_invalidate_pte(struct intel_vgpu_ppgtt_spt *spt,
@@ -1016,7 +1016,7 @@ static inline void ppgtt_invalidate_pte(struct intel_vgpu_ppgtt_spt *spt,
 	intel_gvt_dma_unmap_guest_page(vgpu, pfn &lt;&lt; PAGE_SHIFT);
 }
 
-static int ppgtt_invalidate_spt(struct intel_vgpu_ppgtt_spt *spt)
+static int ppgtt_invalidate_spt(struct intel_vgpu_ppgtt_spt *spt, int is_error)
 {
 	struct intel_vgpu *vgpu = spt-&gt;vgpu;
 	struct intel_gvt_gtt_entry e;
@@ -1059,9 +1059,11 @@ static int ppgtt_invalidate_spt(struct intel_vgpu_ppgtt_spt *spt)
 		}
 	}
 
-	trace_spt_change(spt-&gt;vgpu-&gt;id, "release", spt,
+	if (!is_error) {
+		trace_spt_change(spt-&gt;vgpu-&gt;id, "release", spt,
 			 spt-&gt;guest_page.gfn, spt-&gt;shadow_page.type);
-	ppgtt_free_spt(spt);
+		ppgtt_free_spt(spt);
+	}
 	return 0;
 fail:
 	gvt_vgpu_err("fail: shadow page %p shadow entry 0x%llx type %d\n",
@@ -1215,7 +1217,7 @@ static int split_2MB_gtt_entry(struct intel_vgpu *vgpu,
 		ret = intel_gvt_dma_map_guest_page(vgpu, start_gfn + sub_index,
 						   PAGE_SIZE, &amp;dma_addr);
 		if (ret) {
-			ppgtt_invalidate_spt(spt);
+			ppgtt_invalidate_spt(spt, 1);
 			return ret;
 		}
 		sub_se.val64 = se-&gt;val64;
@@ -1393,7 +1395,7 @@ static int ppgtt_handle_guest_entry_removal(struct intel_vgpu_ppgtt_spt *spt,
 			ret = -ENXIO;
 			goto fail;
 		}
-		ret = ppgtt_invalidate_spt(s);
+		ret = ppgtt_invalidate_spt(s, 0);
 		if (ret)
 			goto fail;
 	} else {
-- 
2.25.1

  parent reply	other threads:[~2022-09-19  7:18 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <tencent_E1BBF05904DFB73C478DCD592740AAE0780A@qq.com>
2022-09-05  4:47 ` [PATCH] drm/i915/gvt: fix double-free bug in split_2MB_gtt_entry Zheng Hacker
2022-09-05  6:11   ` Zheng Hacker
2022-09-05  7:35   ` Zheng Hacker
2022-09-05  7:46     ` Zheng Hacker
2022-09-05  8:04       ` Greg KH
2022-09-05  8:53         ` Alex Young
2022-09-06 11:36         ` Zheng Hacker
2022-09-07  3:07           ` Zhenyu Wang
2022-09-07  6:47             ` Zheng Hacker
2022-09-08  9:09             ` Zheng Hacker
2022-09-08  9:19               ` Greg KH
2022-09-08 11:59                 ` Zheng Hacker
2022-09-16  6:39                   ` Zheng Hacker
2022-09-16  6:40                     ` Zheng Hacker
2022-09-16  8:25                     ` Greg KH
2022-09-16 15:21                       ` Zheng Hacker
2022-09-16 15:54                       ` Zheng Hacker
2022-09-17  9:08                         ` Greg KH
2022-09-17  9:10                           ` Zheng Hacker
2022-09-18 17:08                           ` =?gb18030?B?s68=?= [this message]
2022-09-18 17:17                           ` Zheng Hacker
2022-09-18 19:24 Zheng Wang
2022-09-19  9:30 ` Jani Nikula
2022-09-19  9:55   ` Zheng Hacker
2022-09-21  9:13   ` Zheng Hacker

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=tencent_36196E8CD75A09D21A47CE65C842E97EF805@qq.com \
    --to=1002992920@qq.com \
    --cc=airlied@linux.ie \
    --cc=alex000young@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hackerzheng666@gmail.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-gvt-dev@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=security@kernel.org \
    --cc=tvrtko.ursulin@linux.intel.com \
    --cc=zhi.a.wang@intel.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;
as well as URLs for NNTP newsgroup(s).