From patchwork Fri Oct 4 16:42:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 175243 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp949180ill; Fri, 4 Oct 2019 09:44:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWyYymBdFRP1hAmVTMmfDPLQQJa4H0WaNVPHqYNVGbiy0XrHSZW+I39gfqY3tmxRhNu3F8 X-Received: by 2002:a6b:5b0a:: with SMTP id v10mr13872567ioh.80.1570207478192; Fri, 04 Oct 2019 09:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570207478; cv=none; d=google.com; s=arc-20160816; b=vBYlR9G/4FPLE58No+MHrLEVMGNQfGWZVPvi9ijseiMmOkq8Ui181Vces0CuXUDEgI NdQ6iE9ItLbBYF1QgfJfQb2rbMytBA8sptP8mOQ8MNFaGifn0NJQhOPjeZYV5I1ZNUgv uyqSheigsz4j8sRxXYtZ+ColRKtpDMCmEhJ7fMgK50LouZoAHYijjMg8flnDN7BR27/9 ipA7TN7DUJz98ZeNtLwTJquKQDrB9xhBNLNW6kN8vKyBLEld6guyvQ6l1HiDtLzwd9tS gJFOx0+uTLrXjQVdUSndTOI+EWaODZlTZ4xbCcP1XqHdHq0mnVTJfKKZQkZ3K4eris56 TkUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:message-id:date:to:from; bh=IpOrT+IMgbVYIo36qzoXhdprepZtqHMzoTmwHjA6luQ=; b=r+TRQf/DrrT9G9qTmJHtP1z3XmngfAGu76uDFezc6W4dOeqWkS8voPwquQV/IiQswi s2LIj2iJRC1s4J/Ua8Oj6X8G4fhO4alsnHmFPT/tA8BbMxh23TLGIZohrUP3//61L27+ kLhFP/cWr/QvNiz99LdIix/LWsp8XjV/A6k3dVAEGpCN/hWyPxG+PpDUTge96DpuMAYf qtArRAsGo3xIQCsNbbrYqzXNZhce6FRIE/+V3V6KNg4B2amzUroRczg0Lf9eGjSIlmye m/3N6QGmPW6v4qgWJbpjGRqMHD2bCIDUQG6w0abWIs3eY0Oau+YyBIMjkBiLqZBoNh19 1Hkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id i17si7403028ioj.124.2019.10.04.09.44.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Oct 2019 09:44:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iGQfM-0002z5-1X; Fri, 04 Oct 2019 16:42:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iGQfK-0002z0-90 for xen-devel@lists.xenproject.org; Fri, 04 Oct 2019 16:42:50 +0000 X-Inumbo-ID: fffd7842-e6c5-11e9-80e3-bc764e2007e4 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id fffd7842-e6c5-11e9-80e3-bc764e2007e4; Fri, 04 Oct 2019 16:42:49 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 98DBC15AB; Fri, 4 Oct 2019 09:42:48 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CBFC73F68E; Fri, 4 Oct 2019 09:42:47 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 4 Oct 2019 17:42:43 +0100 Message-Id: <20191004164243.30822-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Subject: [Xen-devel] [PATCH for-4.13] xen/xsm: flask: Prevent NULL deference in flask_assign_{, dt}device() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: jgross@suse.com, Julien Grall , Daniel De Graaf , paul@xen.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" flask_assign_{, dt}device() may be used to check whether you can test if a device is assigned. In this case, the domain will be NULL. However, flask_iommu_resource_use_perm() will be called and may end up to deference a NULL pointer. This can be prevented by moving the call after we check the validity for the domain pointer. Coverity-ID: 1486741 Fixes: 71e617a6b8 ('use is_iommu_enabled() where appropriate...') Signed-off-by: Julien Grall Acked-by: Daniel De Graaf Reviewed-by: Paul Durrant --- xen/xsm/flask/hooks.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 3b30827764..cf7f25cda2 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -1296,11 +1296,13 @@ static int flask_assign_device(struct domain *d, uint32_t machine_bdf) u32 dsid, rsid; int rc = -EPERM; struct avc_audit_data ad; - u32 dperm = flask_iommu_resource_use_perm(d); + u32 dperm; if ( !d ) return flask_test_assign_device(machine_bdf); + dperm = flask_iommu_resource_use_perm(d); + rc = current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD); if ( rc ) return rc; @@ -1355,11 +1357,13 @@ static int flask_assign_dtdevice(struct domain *d, const char *dtpath) u32 dsid, rsid; int rc = -EPERM; struct avc_audit_data ad; - u32 dperm = flask_iommu_resource_use_perm(d); + u32 dperm; if ( !d ) return flask_test_assign_dtdevice(dtpath); + dperm = flask_iommu_resource_use_perm(d); + rc = current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD); if ( rc ) return rc;