From 816538f93090e6ccf25cdc5e660e6bb9216ce177 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 23 Feb 2023 10:11:46 +0100 Subject: [PATCH] 5.15-stable patches added patches: drm-i915-gvt-fix-double-free-bug-in-split_2mb_gtt_entry.patch --- ...uble-free-bug-in-split_2mb_gtt_entry.patch | 63 +++++++++++++++++++ queue-5.15/series | 1 + 2 files changed, 64 insertions(+) create mode 100644 queue-5.15/drm-i915-gvt-fix-double-free-bug-in-split_2mb_gtt_entry.patch diff --git a/queue-5.15/drm-i915-gvt-fix-double-free-bug-in-split_2mb_gtt_entry.patch b/queue-5.15/drm-i915-gvt-fix-double-free-bug-in-split_2mb_gtt_entry.patch new file mode 100644 index 00000000000..d24b681e956 --- /dev/null +++ b/queue-5.15/drm-i915-gvt-fix-double-free-bug-in-split_2mb_gtt_entry.patch @@ -0,0 +1,63 @@ +From 4a61648af68f5ba4884f0e3b494ee1cabc4b6620 Mon Sep 17 00:00:00 2001 +From: Zheng Wang +Date: Fri, 30 Dec 2022 00:56:41 +0800 +Subject: drm/i915/gvt: fix double free bug in split_2MB_gtt_entry + +From: Zheng Wang + +commit 4a61648af68f5ba4884f0e3b494ee1cabc4b6620 upstream. + +If intel_gvt_dma_map_guest_page failed, it will call +ppgtt_invalidate_spt, which will finally free the spt. +But the caller function ppgtt_populate_spt_by_guest_entry +does not notice that, it will free spt again in its error +path. + +Fix this by canceling the mapping of DMA address and freeing sub_spt. +Besides, leave the handle of spt destroy to caller function instead +of callee function when error occurs. + +Fixes: b901b252b6cf ("drm/i915/gvt: Add 2M huge gtt support") +Signed-off-by: Zheng Wang +Reviewed-by: Zhenyu Wang +Signed-off-by: Zhenyu Wang +Link: http://patchwork.freedesktop.org/patch/msgid/20221229165641.1192455-1-zyytlz.wz@163.com +Signed-off-by: Ovidiu Panait +Signed-off-by: Greg Kroah-Hartman +--- + drivers/gpu/drm/i915/gvt/gtt.c | 17 +++++++++++++---- + 1 file changed, 13 insertions(+), 4 deletions(-) + +--- a/drivers/gpu/drm/i915/gvt/gtt.c ++++ b/drivers/gpu/drm/i915/gvt/gtt.c +@@ -1195,10 +1195,8 @@ static int split_2MB_gtt_entry(struct in + for_each_shadow_entry(sub_spt, &sub_se, sub_index) { + ret = intel_gvt_hypervisor_dma_map_guest_page(vgpu, + start_gfn + sub_index, PAGE_SIZE, &dma_addr); +- if (ret) { +- ppgtt_invalidate_spt(spt); +- return ret; +- } ++ if (ret) ++ goto err; + sub_se.val64 = se->val64; + + /* Copy the PAT field from PDE. */ +@@ -1217,6 +1215,17 @@ static int split_2MB_gtt_entry(struct in + ops->set_pfn(se, sub_spt->shadow_page.mfn); + ppgtt_set_shadow_entry(spt, se, index); + return 0; ++err: ++ /* Cancel the existing addess mappings of DMA addr. */ ++ for_each_present_shadow_entry(sub_spt, &sub_se, sub_index) { ++ gvt_vdbg_mm("invalidate 4K entry\n"); ++ ppgtt_invalidate_pte(sub_spt, &sub_se); ++ } ++ /* Release the new allocated spt. */ ++ trace_spt_change(sub_spt->vgpu->id, "release", sub_spt, ++ sub_spt->guest_page.gfn, sub_spt->shadow_page.type); ++ ppgtt_free_spt(sub_spt); ++ return ret; + } + + static int split_64KB_gtt_entry(struct intel_vgpu *vgpu, diff --git a/queue-5.15/series b/queue-5.15/series index 75e8c98ae27..9c6016ed4db 100644 --- a/queue-5.15/series +++ b/queue-5.15/series @@ -20,3 +20,4 @@ powerpc-vmlinux.lds-add-an-explicit-symbol-for-the-s.patch powerpc-64s-radix-fix-crash-with-unaligned-relocated.patch powerpc-64s-radix-fix-rwx-mapping-with-relocated-ker.patch revert-netfilter-conntrack-fix-bug-in-for_each_sctp_.patch +drm-i915-gvt-fix-double-free-bug-in-split_2mb_gtt_entry.patch -- 2.47.3