From patchwork Wed Jan 5 13:49:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 530168 Delivered-To: patch@linaro.org Received: by 2002:ad5:544f:0:0:0:0:0 with SMTP id a15csp334000imp; Wed, 5 Jan 2022 06:37:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxksu17IX3iB503GjNnSaUyGzgZ/jtnV2lhdGsmKkTdR67pb0AzUFrja3RQUHA5iRedBX/M X-Received: by 2002:a25:6741:: with SMTP id b62mr21310095ybc.625.1641393440855; Wed, 05 Jan 2022 06:37:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641393440; cv=none; d=google.com; s=arc-20160816; b=KFNPnHTL2vM15JUp7rvTmAyQLFiD1/fuO1HWHeqJmYOCMScMS25a6pGiAS5xti8JxL 2CkrVL+SyaVyjmy7WcQur77VAu7mlOSIFrmVYjagvBdRUWauOO9vaTwOFwlud/cuKweO CA+dn3uuJp6HGcdV3t3+Mirm/eTTguYXHcuwn1i4XbmHunz9r8t0GevR5jTIezX9YWWy JnpjrR0eWBqYVMQJKs5u39mTE8AfRHe2+MddzH28b+Da2gGXPJtxFyt8DB17QxKEPjSh dNrdei32JLteMECrNd19mMoKcrRH7oW6WSKqV7JtxF9gkIip5DiLTEEJUcaoytOhIhgK iT2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=PR+qxQ2shEV/A+tfSEgZk9rUCgVOrjyYAYISimz0Tis=; b=u+tV71tPRK6G78m69qTR+pWbcXnjYu6igBKJAL4lDsmq3+Xjs8HtOQhKB49jZxlwow M3WNbX3U1XnMfZPki3YEF18wvFhp5cz1J7nkzTvgoV05Zi/pWewkGrSNydpJ32ybdh6K VA8mIqwPzKc1wTJf1t2CcIp/OG7eyLkfLYckN4h0xaP8BJDvkW15nxz+v/uL9vkoIQsN xuk4STLSTVcjHKLkn1nAMKr0ZjaLMJ63B2yln6g4Hhe9MkW38hTo7QC1x1g7v6Mf6YI0 HTPK3gPfPBZ4j5fvlyLd/qHgfXSyaJKk60XkHeLP1gAppSnV7woQnegJJsiVen2G62O1 DDqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GVMFC3O4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t9si22306861ybu.715.2022.01.05.06.37.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jan 2022 06:37:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GVMFC3O4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n57Pk-0007FL-BJ for patch@linaro.org; Wed, 05 Jan 2022 09:37:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n56q6-0004cn-FX for qemu-devel@nongnu.org; Wed, 05 Jan 2022 09:00:33 -0500 Received: from [2a00:1450:4864:20::334] (port=40756 helo=mail-wm1-x334.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n56q4-0006Sp-0g for qemu-devel@nongnu.org; Wed, 05 Jan 2022 09:00:29 -0500 Received: by mail-wm1-x334.google.com with SMTP id m14-20020a7bcb8e000000b00346da381d59so557172wmi.5 for ; Wed, 05 Jan 2022 06:00:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PR+qxQ2shEV/A+tfSEgZk9rUCgVOrjyYAYISimz0Tis=; b=GVMFC3O4RlmooLTibiHBxnIbIg+K3MyuA7x/bxsy7tf0c0Ra4rbk+ZJCmHwZyOMmrN PBIDHeoMWlDO0GA7cH1ig2rJYOs3fEAzpAvaaEHHO62QoosnZlHqB47MYYNpw/xpR15f SmG8x5rNpBxCtJC6NeElcoP9MvWTYiUxKa2nhKW2CCCc7zv45tcphSGaZlTINcEGuiHN U7UmZ8iDYyedbYbGf4jipg0hKzjKUKwXwbIJwTy7qgJbjlsIhGKfaTBrBTGmV9UkNZU0 UgVsSkOkeP6pexvvYIZ3lWIAmo8m1+wt43NF47VXuOTWEkOrPd1qkxp7meUeDEVwtxoF EB2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PR+qxQ2shEV/A+tfSEgZk9rUCgVOrjyYAYISimz0Tis=; b=w3V3Lz7N5bS1uE7o/9Ph7H+JIqh/TKLZDaa1a9MloEnyzFC/DSZPwDJw6EXXYldg+F bWa3KXYhyszLsdQxpbxTN1tkODE5K1dDoMflVSAFEUOiKr1KgotkfLuP1FbnCl0BC/Y0 b4YEaPloDVcWeKNb51mmtRg5758PaoJRFS3ttklwJ2NiW8pLiGR2tqUkNhpgmu+nAQR9 zBWBLrlwGCQIWDp58nv/tYXWAXnzeN7Y/MmjkFquDRokhm7c0lD/GSnb0i7uA5rPbFZx C0J/tWUtqF6MhPR2YjmXjKlA9lce34fUfDcD0JDbAoZEHvTkkvifXOU5NYO7dP5FLe4O /8Fg== X-Gm-Message-State: AOAM533FseRXzrGx7xqaknLyTHrKt/Vm0BAWosvSZkauD3oLqaAVSZm1 oI95ljKDh1JL/rkOXUL/C4KfQOTFclhFNA== X-Received: by 2002:a1c:4d04:: with SMTP id o4mr2898678wmh.161.1641391226634; Wed, 05 Jan 2022 06:00:26 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id k33sm2765825wms.21.2022.01.05.06.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jan 2022 06:00:19 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0B4571FFCD; Wed, 5 Jan 2022 13:50:11 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 21/34] hw/arm: add control knob to disable kaslr_seed via DTB Date: Wed, 5 Jan 2022 13:49:56 +0000 Message-Id: <20220105135009.1584676-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220105135009.1584676-1-alex.bennee@linaro.org> References: <20220105135009.1584676-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::334 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, WEIRD_QUOTING=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, Peter Maydell , berrange@redhat.com, Heinrich Schuchardt , Ilias Apalodimas , f4bug@amsat.org, Jerome Forissier , stefanha@redhat.com, crosa@redhat.com, pbonzini@redhat.com, "open list:Virt" , =?utf-8?q?Alex_Benn=C3=A9e?= , aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Generally a guest needs an external source of randomness to properly enable things like address space randomisation. However in a trusted boot environment where the firmware will cryptographically verify components having random data in the DTB will cause verification to fail. Add a control knob so we can prevent this being added to the system DTB. Signed-off-by: Alex Bennée Tested-by: Heinrich Schuchardt Acked-by: Ilias Apalodimas Acked-by: Jerome Forissier Message-Id: <20211215120926.1696302-1-alex.bennee@linaro.org> Reviewed-by: Andrew Jones --- docs/system/arm/virt.rst | 7 +++++++ include/hw/arm/virt.h | 1 + hw/arm/virt.c | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst index 850787495b..c86a4808df 100644 --- a/docs/system/arm/virt.rst +++ b/docs/system/arm/virt.rst @@ -121,6 +121,13 @@ ras Set ``on``/``off`` to enable/disable reporting host memory errors to a guest using ACPI and guest external abort exceptions. The default is off. +kaslr-dtb-seed + Set ``on``/``off`` to pass a random seed via the guest dtb to use for features + like address space randomisation. The default is ``on``. You will want + to disable it if your trusted boot chain will verify the DTB it is + passed. It would be the responsibility of the firmware to come up + with a seed and pass it on if it wants to. + Linux guest kernel configuration """""""""""""""""""""""""""""""" diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index dc6b66ffc8..acd0665fe7 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -148,6 +148,7 @@ struct VirtMachineState { bool virt; bool ras; bool mte; + bool kaslr_dtb_seed; OnOffAuto acpi; VirtGICType gic_version; VirtIOMMUType iommu; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 6bce595aba..1781e47c76 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -247,11 +247,15 @@ static void create_fdt(VirtMachineState *vms) /* /chosen must exist for load_dtb to fill in necessary properties later */ qemu_fdt_add_subnode(fdt, "/chosen"); - create_kaslr_seed(ms, "/chosen"); + if (vms->kaslr_dtb_seed) { + create_kaslr_seed(ms, "/chosen"); + } if (vms->secure) { qemu_fdt_add_subnode(fdt, "/secure-chosen"); - create_kaslr_seed(ms, "/secure-chosen"); + if (vms->kaslr_dtb_seed) { + create_kaslr_seed(ms, "/secure-chosen"); + } } /* Clock node, for the benefit of the UART. The kernel device tree @@ -2235,6 +2239,20 @@ static void virt_set_its(Object *obj, bool value, Error **errp) vms->its = value; } +static bool virt_get_kaslr_dtb_seed(Object *obj, Error **errp) +{ + VirtMachineState *vms = VIRT_MACHINE(obj); + + return vms->kaslr_dtb_seed; +} + +static void virt_set_kaslr_dtb_seed(Object *obj, bool value, Error **errp) +{ + VirtMachineState *vms = VIRT_MACHINE(obj); + + vms->kaslr_dtb_seed = value; +} + static char *virt_get_oem_id(Object *obj, Error **errp) { VirtMachineState *vms = VIRT_MACHINE(obj); @@ -2764,6 +2782,13 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) "Set on/off to enable/disable " "ITS instantiation"); + object_class_property_add_bool(oc, "kaslr-dtb-seed", + virt_get_kaslr_dtb_seed, + virt_set_kaslr_dtb_seed); + object_class_property_set_description(oc, "kaslr-dtb-seed", + "Set off to disable passing of kaslr " + "dtb node to guest"); + object_class_property_add_str(oc, "x-oem-id", virt_get_oem_id, virt_set_oem_id); @@ -2828,6 +2853,9 @@ static void virt_instance_init(Object *obj) /* MTE is disabled by default. */ vms->mte = false; + /* Supply a kaslr-seed by default */ + vms->kaslr_dtb_seed = true; + vms->irqmap = a15irqmap; virt_flash_create(vms);