From patchwork Mon Dec 4 05:46:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenyu Wang X-Patchwork-Id: 10089687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 99E6160329 for ; Mon, 4 Dec 2017 05:52:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8224328F84 for ; Mon, 4 Dec 2017 05:52:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7695428F86; Mon, 4 Dec 2017 05:52:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A645028F84 for ; Mon, 4 Dec 2017 05:52:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1813E6E2BB; Mon, 4 Dec 2017 05:52:11 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6AB256E12A; Mon, 4 Dec 2017 05:52:09 +0000 (UTC) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Dec 2017 21:52:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,357,1508828400"; d="asc'?scan'208";a="183252704" Received: from zhen-hp.sh.intel.com (HELO zhen-hp) ([10.239.159.159]) by fmsmga005.fm.intel.com with ESMTP; 03 Dec 2017 21:52:07 -0800 Date: Mon, 4 Dec 2017 13:46:17 +0800 From: Zhenyu Wang To: Chris Wilson Message-ID: <20171204054617.tcqu4kzab2k6b7nd@zhen-hp.sh.intel.com> References: <20171120211516.30014-1-chris@chris-wilson.co.uk> <20171121031951.q4whdbgq5stjmqxf@zhen-hp.sh.intel.com> <151125956185.27169.17094450868712378763@mail.alporthouse.com> MIME-Version: 1.0 In-Reply-To: <151125956185.27169.17094450868712378763@mail.alporthouse.com> User-Agent: NeoMutt/20170609 (1.8.3) Cc: intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org Subject: Re: [Intel-gfx] [PATCH] drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[] X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Zhenyu Wang Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP 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 > > > Cc: Xiong Zhang > > > Cc: Zhenyu Wang > > > Cc: Zhi Wang > > > 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 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 Cc: Xiong Zhang Cc: Zhenyu Wang Cc: Zhi Wang Cc: intel-gvt-dev@lists.freedesktop.org Signed-off-by: Zhenyu Wang --- 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;