All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhenyu Wang <zhenyuw@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[]
Date: Mon, 4 Dec 2017 13:46:17 +0800	[thread overview]
Message-ID: <20171204054617.tcqu4kzab2k6b7nd@zhen-hp.sh.intel.com> (raw)
In-Reply-To: <151125956185.27169.17094450868712378763@mail.alporthouse.com>


[-- Attachment #1.1: Type: text/plain, Size: 3986 bytes --]

On 2017.11.21 10:19:21 +0000, Chris Wilson wrote:
> Quoting Zhenyu Wang (2017-11-21 03:19:51)
> > On 2017.11.20 21:15:16 +0000, Chris Wilson wrote:
> > > sparse spots
> > > 
> > > drivers/gpu/drm/i915/gvt/opregion.c:234 alloc_and_init_virt_opregion() error: memcpy() 'header->signature' too small (16 vs 17)
> > > 
> > > as gvt is indeed trying to memcpy a string longer than the signature[].
> > > 
> > > Fixes: b2d6ef70614e ("drm/i915/gvt: Let each vgpu has separate opregion memory")
> > > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > > Cc: Xiong Zhang <xiong.y.zhang@intel.com>
> > > Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
> > > Cc: Zhi Wang <zhi.a.wang@intel.com>
> > > Cc: intel-gvt-dev@lists.freedesktop.org
> > > ---
> > >  drivers/gpu/drm/i915/gvt/opregion.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
> > > index 80720e59723a..3cf4c6f18152 100644
> > > --- a/drivers/gpu/drm/i915/gvt/opregion.c
> > > +++ b/drivers/gpu/drm/i915/gvt/opregion.c
> > > @@ -232,7 +232,7 @@ static int alloc_and_init_virt_opregion(struct intel_vgpu *vgpu)
> > >       buf = (u8 *)vgpu_opregion(vgpu)->va;
> > >       header = (struct opregion_header *)buf;
> > >       memcpy(header->signature, OPREGION_SIGNATURE,
> > > -                     sizeof(OPREGION_SIGNATURE));
> > > +                     sizeof(OPREGION_SIGNATURE) - 1);
> > >       header->size = 0x8;
> > >       header->opregion_ver = 0x02000000;
> > >       header->mboxes = MBOX_VBT;
> > > -- 
> > 
> > applied this, thanks!
> 
> It's not the best patch; after sleep I think you want
> 
> static const char opregion_signature[16] = "IntelFooBar";
> 
> memcpy(header->signature, opregion_signature, sizeof(opregion_signature));

yeah, I applied below one instead. Thanks.

From ea26c96d59b27e878fe61e8ef0fed840d2281a2f Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris@chris-wilson.co.uk>
Date: Mon, 4 Dec 2017 11:23:44 +0800
Subject: [PATCH] drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[]

sparse spots

drivers/gpu/drm/i915/gvt/opregion.c:234 alloc_and_init_virt_opregion() error: memcpy() 'header->signature' too small (16 vs 17)

as gvt is indeed trying to memcpy a string longer than the signature[].

Fixes: b2d6ef70614e ("drm/i915/gvt: Let each vgpu has separate opregion memory")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Xiong Zhang <xiong.y.zhang@intel.com>
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Zhi Wang <zhi.a.wang@intel.com>
Cc: intel-gvt-dev@lists.freedesktop.org
Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
---
 drivers/gpu/drm/i915/gvt/opregion.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
index 80720e59723a..bf8e5c49a64a 100644
--- a/drivers/gpu/drm/i915/gvt/opregion.c
+++ b/drivers/gpu/drm/i915/gvt/opregion.c
@@ -218,6 +218,7 @@ static int alloc_and_init_virt_opregion(struct intel_vgpu *vgpu)
 	u8 *buf;
 	struct opregion_header *header;
 	struct vbt v;
+	const char opregion_signature[16] = OPREGION_SIGNATURE;
 
 	gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
 	vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
@@ -231,8 +232,8 @@ static int alloc_and_init_virt_opregion(struct intel_vgpu *vgpu)
 	/* emulated opregion with VBT mailbox only */
 	buf = (u8 *)vgpu_opregion(vgpu)->va;
 	header = (struct opregion_header *)buf;
-	memcpy(header->signature, OPREGION_SIGNATURE,
-			sizeof(OPREGION_SIGNATURE));
+	memcpy(header->signature, opregion_signature,
+	       sizeof(opregion_signature));
 	header->size = 0x8;
 	header->opregion_ver = 0x02000000;
 	header->mboxes = MBOX_VBT;
-- 
2.15.0


-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

      reply	other threads:[~2017-12-04  5:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-20 21:15 [PATCH] drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[] Chris Wilson
2017-11-20 21:58 ` ✗ Fi.CI.BAT: warning for " Patchwork
2017-11-21  3:19 ` [PATCH] " Zhenyu Wang
2017-11-21 10:19   ` Chris Wilson
2017-12-04  5:46     ` Zhenyu Wang [this message]

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=20171204054617.tcqu4kzab2k6b7nd@zhen-hp.sh.intel.com \
    --to=zhenyuw@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-gvt-dev@lists.freedesktop.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.