From patchwork Wed Aug 7 02:20:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 11080923 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 647B61709 for ; Wed, 7 Aug 2019 02:20:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42B0F284D4 for ; Wed, 7 Aug 2019 02:20:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 301D92845C; Wed, 7 Aug 2019 02:20:40 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 D86202845C for ; Wed, 7 Aug 2019 02:20:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 01E2D6E5B1; Wed, 7 Aug 2019 02:20:39 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from gateway32.websitewelcome.com (gateway32.websitewelcome.com [192.185.145.111]) by gabe.freedesktop.org (Postfix) with ESMTPS id B9BF06E5B1 for ; Wed, 7 Aug 2019 02:20:37 +0000 (UTC) Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway32.websitewelcome.com (Postfix) with ESMTP id B717F36798 for ; Tue, 6 Aug 2019 21:20:36 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id vBZ6hXKfI3Qi0vBZ6hGYdR; Tue, 06 Aug 2019 21:20:36 -0500 X-Authority-Reason: nr=8 Received: from [187.192.11.120] (port=51758 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.92) (envelope-from ) id 1hvBZ4-001ybs-Ge; Tue, 06 Aug 2019 21:20:35 -0500 Date: Tue, 6 Aug 2019 21:20:33 -0500 From: "Gustavo A. R. Silva" To: Zhenyu Wang , Zhi Wang , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , Xiong Zhang Subject: [PATCH] drm/i915/gvt: Fix use-after-free in intel_vgpu_create_workload Message-ID: <20190807022033.GA22623@embeddedor> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - lists.freedesktop.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.192.11.120 X-Source-L: No X-Exim-ID: 1hvBZ4-001ybs-Ge X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [187.192.11.120]:51758 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 11 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Type:MIME-Version:Message-ID:Subject: Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=pUxBPsNGWxsRsB7NDgN9eNAS2Hr1pQIZdhHSWzXdg+w=; b=aj9oX8mRps4i4Vhhlaip9MvCwH n2TJQa2tPHp0yCeXUx7ubaJqt3ATHJtoTvFuL15E4IgEQMGX/PUeO4iP2SW4oYPRJz4KKxuJEZdSb sRxpyrEXo+RfUuXFO88hjlGQaiccBvOoaFSfdwUU49SrzJPQINVdQ5IV6DnsvV/0j6EluduHYoxlp iDhS4kdR+KGwXgABQZOCgh9Q/LiCk64Woy0YKhLO6A1C0x1NQMdvxcUU0op67QdgkTtP7ayZCBHCt OF1DBsN5XDVz5WAqzoMDYhuq1E2CKQzs2DzEd60lRzXakFzJc2RUogetxMCSFhJoS2JMGE5IaXAFS hrNBd60A==; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "Gustavo A. R. Silva" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP kmem_cache_free() frees *workload*, hence there is a use-after-free bug when calling function gvt_vgpu_err(). Fix this by storing the value of workload->wa_ctx.indirect_ctx.guest_gma and workload->wa_ctx.per_ctx.guest_gma into automatic variable guest_gma before freeing *workload*, for its further use. Addresses-Coverity-ID: 1452235 ("Read from pointer after free") Fixes: 2089a76ade90 ("drm/i915/gvt: Checking workload's gma earlier") Signed-off-by: Gustavo A. R. Silva --- drivers/gpu/drm/i915/gvt/scheduler.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/scheduler.c b/drivers/gpu/drm/i915/gvt/scheduler.c index 32ae6b5b7e16..c8cdb4a309f6 100644 --- a/drivers/gpu/drm/i915/gvt/scheduler.c +++ b/drivers/gpu/drm/i915/gvt/scheduler.c @@ -1525,9 +1525,11 @@ intel_vgpu_create_workload(struct intel_vgpu *vgpu, int ring_id, if (!intel_gvt_ggtt_validate_range(vgpu, workload->wa_ctx.indirect_ctx.guest_gma, workload->wa_ctx.indirect_ctx.size)) { + unsigned long guest_gma = + workload->wa_ctx.indirect_ctx.guest_gma; kmem_cache_free(s->workloads, workload); gvt_vgpu_err("invalid wa_ctx at: 0x%lx\n", - workload->wa_ctx.indirect_ctx.guest_gma); + guest_gma); return ERR_PTR(-EINVAL); } } @@ -1539,9 +1541,11 @@ intel_vgpu_create_workload(struct intel_vgpu *vgpu, int ring_id, if (!intel_gvt_ggtt_validate_range(vgpu, workload->wa_ctx.per_ctx.guest_gma, CACHELINE_BYTES)) { + unsigned long guest_gma = + workload->wa_ctx.per_ctx.guest_gma; kmem_cache_free(s->workloads, workload); gvt_vgpu_err("invalid per_ctx at: 0x%lx\n", - workload->wa_ctx.per_ctx.guest_gma); + guest_gma); return ERR_PTR(-EINVAL); } }