From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0786FECAAD8 for ; Fri, 16 Sep 2022 06:40:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EEE1F10ECCC; Fri, 16 Sep 2022 06:40:52 +0000 (UTC) Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by gabe.freedesktop.org (Postfix) with ESMTPS id B813110ECC6; Fri, 16 Sep 2022 06:40:49 +0000 (UTC) Received: by mail-ej1-x62f.google.com with SMTP id l14so47228392eja.7; Thu, 15 Sep 2022 23:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date; bh=7qw7zTJBliZzCUFRh7uRC/j1d4UKOuRGnko9pDRJCJg=; b=GQC1aj9JcqAr/n1JEaVzllQ+WJR4Y6kF3WvjxAzdbFAnpeTTyY8VaBTy2Ww15/PipO oB+ieOjKBoaaq21zkzgkX+hdS6ZYi/zxNPj1h3rCCYWNNtuORc2MviXxDJsbOwaYcZf/ fBWWwQLZ6cgjypPruO4qjyolXKvYNPR1c3T3CbiqcFt66KpSm+3Vu5O9iOta1/wIqKxb zB5yW9qpfmG8ouAvKCygVtRUDxBfdDaGxDpzjOjY+W5U0STc9TJA002J/H6Rax3okGzq X3mSOmYIAfGufm0Vc6YaUqHj4XF+7YRNE2HtA+n0LSrU7iew8BoF0lqpU0n0m0LwhU4T mNWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date; bh=7qw7zTJBliZzCUFRh7uRC/j1d4UKOuRGnko9pDRJCJg=; b=rx5r/AsVA2sPNZKr0t+8NiGssKGGwNAxgZuM1q8W4mOPgIBQqI02TrAMiGrRtaetDP Rt/EHyQqA5xrkqgTHwk0Ekp6111QvoEA4EYke8abSLcSs+NHSNSLVjFYO3xChi2xFvyI UCfmgqIsmQ60d089BxHZUPguPzgW6BX50eSb6A7UGbedO9V3R1lrFHM3GrAnxkK+xK1W cbM2RKnMke8UkO3PSFsVj5yzq/JxCMIW2yVMvjyt1yLRm8sbOkCn1asI4p0kdYuyu++0 lsKFWXtdD4Td6fuwNzOA+J3dZXZaoU6ouYsKVBsiEgdYkNhhhybbHZkGpAtljJsAFEnR bvLw== X-Gm-Message-State: ACrzQf0B4nezQLBaWy1oRj+vzGjxNAyoMcjcysSHN3GLztp2UbRKhhCE a38Ugbtt5dhO3vzPgRdHe316I8clCDhdnA5tOmQ= X-Google-Smtp-Source: AMsMyM6JajyBfscpsfrP8P1If2mpqnSWaqdzR5KjBSjX+DS0oFjEdifZTTOj406HyyX2HmVTTuBjFrAG3K6JuaTKc44= X-Received: by 2002:a17:907:1de0:b0:770:8670:6a6a with SMTP id og32-20020a1709071de000b0077086706a6amr2613381ejc.588.1663310448243; Thu, 15 Sep 2022 23:40:48 -0700 (PDT) MIME-Version: 1.0 References: <20220907030754.GU1089@zhen-hp.sh.intel.com> In-Reply-To: From: Zheng Hacker Date: Fri, 16 Sep 2022 14:40:36 +0800 Message-ID: Subject: Re: [PATCH] drm/i915/gvt: fix double-free bug in split_2MB_gtt_entry. To: Greg KH Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alex000young@gmail.com" , "security@kernel.org" , "tvrtko.ursulin@linux.intel.com" , "airlied@linux.ie" , "intel-gfx@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , xmzyshypnc <1002992920@qq.com>, "rodrigo.vivi@intel.com" , "intel-gvt-dev@lists.freedesktop.org" , "zhi.a.wang@intel.com" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Here I introduced is_error to judge if the ppgtt_invalidate_spt is called from good case or not. Only free spt in good case, leave it to handle for the error path of caller. Zheng Hacker =E4=BA=8E2022=E5=B9=B49=E6=9C=8816= =E6=97=A5=E5=91=A8=E4=BA=94 14:39=E5=86=99=E9=81=93=EF=BC=9A > > From 8d95c1399e3ff345500a575e21254a73b0c89144 Mon Sep 17 00:00:00 2001 > From: xmzyshypnc <1002992920@qq.com> > Date: Fri, 16 Sep 2022 14:37:48 +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->ppgtt_populate_shadow_entry->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 <1002992920@qq.com> > --- > 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/gt= t.c > index 9f14fded8c0c..31d2a8d56384 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(&spt->refcount); > } > > -static int ppgtt_invalidate_spt(struct intel_vgpu_ppgtt_spt *spt); > +static int ppgtt_invalidate_spt(struct intel_vgpu_ppgtt_spt *sptm, > 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->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 << 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 =3D spt->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->vgpu->id, "release", spt, > + if (!is_error) { > + trace_spt_change(spt->vgpu->id, "release", spt, > spt->guest_page.gfn, spt->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 *v= gpu, > ret =3D intel_gvt_dma_map_guest_page(vgpu, start_gfn + sub_index, > PAGE_SIZE, &dma_addr); > if (ret) { > - ret =3D ppgtt_invalidate_spt(spt); > + ret =3D ppgtt_invalidate_spt(spt, 1); > return ret; > } > sub_se.val64 =3D se->val64; > @@ -1393,7 +1395,7 @@ static int > ppgtt_handle_guest_entry_removal(struct intel_vgpu_ppgtt_spt *spt, > ret =3D -ENXIO; > goto fail; > } > - ret =3D ppgtt_invalidate_spt(s); > + ret =3D ppgtt_invalidate_spt(s, 0); > if (ret) > goto fail; > } else { > -- > 2.25.1 > > Zheng Hacker =E4=BA=8E2022=E5=B9=B49=E6=9C=888= =E6=97=A5=E5=91=A8=E5=9B=9B 19:59=E5=86=99=E9=81=93=EF=BC=9A > > > > Hi Greg, > > > > I got it, Greg. > > > > Mid-Autumn Festival is coming and I will have a couple of days off. > > I'll see what I can do after holiday :) > > > > Regards, > > > > Zheng Wang > > > > =E5=9C=A8 2022=E5=B9=B49=E6=9C=888=E6=97=A5=E6=98=9F=E6=9C=9F=E5=9B=9B= =EF=BC=8CGreg KH =E5=86=99=E9=81=93=EF=BC=9A > >> > >> On Thu, Sep 08, 2022 at 05:09:40PM +0800, Zheng Hacker wrote: > >> > Hi Zhenyu, > >> > > >> > This issue has been open for a few days. Could you plz write a patch > >> > for that :) I'm not familiar with the logical code here. > >> > >> As this is only able to be hit in a theoretical system, it isn't that > >> high of a priority, if any priority at all. Why not try to write a > >> patch for it yourself to help resolve the issue faster? > >> > >> thanks, > >> > >> greg k-h