From patchwork Wed Nov 16 17:03:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 13045593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1BCDC4332F for ; Wed, 16 Nov 2022 17:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=NoiUJMuU3lSLcb0NCScxBsklbLbgQyNrmWgs1jv0jEQ=; b=vBm 8tnjuGZmE+65iG7wZbdayP5hGhkTcRr524bzDW1tSpKBQZQwPwg8JLaaydwVFLUllWcbTLxPoYT8v t18ToVsTJwMNy9YnVybM3qWRwxBjzoxBHfxJwZbJcDC7sshu+qpnhLgmvzVV4gvd44C+YuS4D8y2s 0NRBwCFa+ooTK776hoPwffjnKo1DCnrDmlsPqhd1NzQ0QLdlY7O6d/x2e9EQz1jFSUIUXyTkOw5Vx CJIrRmJZ7snx/t2GJ4t1nAqOEaiPsbCuB/+x4n3B/rSW0r8F9a2Q+eXrNdsWfxoV7h8Tco8L+uZSl pOX9uujC52+nr2At31wIpuLXTZFo7mQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovLpG-006Dxg-0c; Wed, 16 Nov 2022 17:03:50 +0000 Received: from mail-ej1-x64a.google.com ([2a00:1450:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovLp7-006Dsr-EY for linux-arm-kernel@lists.infradead.org; Wed, 16 Nov 2022 17:03:43 +0000 Received: by mail-ej1-x64a.google.com with SMTP id xj11-20020a170906db0b00b0077b6ecb23fcso10344420ejb.5 for ; Wed, 16 Nov 2022 09:03:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=cqmymE4F1AzcVr0rAjT0TqGqidpCow5ff2C/QyEftUQ=; b=d5fT1+t1Uo2vlTG633RLZsby5RVVFLgn62ja1ehg00dbGfGQEC4Dclj3otyomMqUPd dRK431qRTVccl0zLA+QR3Sg1k5tDwTP8ZvlufaosrJTeU3I9SGP6OP3RA3fRRBtnD8Ra 5Bw4S/8y6bjg7zU/jiFNGb7HTGS1TeUhX/xk/4NS1EVllxg4OgkSwcX6hc6UYr74us+Q 7JJL7Zfs2I7Vnj52QpXivh6m59Efsn5pt519MvUQncwPIFm88yDje7J8NmlGrXYMAjTf qIASv6dOtCL/6Kntz4wo0E5kYL/8nDfVYFicos/exbnXSX97JGrG8tez3uP+AGBti+4i s/gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cqmymE4F1AzcVr0rAjT0TqGqidpCow5ff2C/QyEftUQ=; b=Kr9B+8MYEH5OZHgLPyD69rnotWujxc3thQdU7tFpQTkThI0U+VA86q90lOWBnE4du4 jScg9RpoPW9Y0GRRZIWRa26n1jwnZiceo9gNsQZR2NPcpI8cxzHEoCIKLBrbacWh6v0I NQfYQA1cZt5RifGKdHIQ2nN0V0b6RLVXTygkkA6hpFc1tOcTkju851E58r08l4mH18K8 9d3cq6f0IjycVW4EgrNXH/A6bo6p4Gw55GPnXildeHjVHmTpp8KHqtRjUXQqcwnTIdHj BeB/nLzQs1jCOxRzy/A1MXnC01dsPn53SmowwGDb52Gb9wbKrgRI6gAeRGiczpb+S5p6 0Dxg== X-Gm-Message-State: ANoB5pmICHSiPyhbTgRr6le7jmE4ayYHpnO5XUbm/S9Zv0yb9lcVxpsm 1lJi9eN7FUQ1sbCSjSeLSuYoeNVp9riK X-Google-Smtp-Source: AA0mqf4kQcttgHovLZay3IZ5h8ySDasGuaZQArDBf5GZUHdssSgbM3MLRht2rLrBlFf4v9LLwgRpdc7gy3Ky X-Received: from big-boi.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:129]) (user=qperret job=sendgmr) by 2002:a17:906:6893:b0:7ad:14f8:7583 with SMTP id n19-20020a170906689300b007ad14f87583mr19341242ejr.185.1668618218081; Wed, 16 Nov 2022 09:03:38 -0800 (PST) Date: Wed, 16 Nov 2022 17:03:23 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221116170335.2341003-1-qperret@google.com> Subject: [PATCH 00/12] KVM: arm64: FF-A proxy for pKVM From: Quentin Perret To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Catalin Marinas , Will Deacon , Sudeep Holla , Andrew Walbran Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221116_090341_505523_AA1AC05D X-CRM114-Status: GOOD ( 21.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi all, pKVM's primary goal is to protect guest pages from a compromised host by enforcing access control restrictions using stage-2 page-tables. Sadly, this cannot prevent TrustZone from accessing non-secure memory, and a compromised host could, for example, perform a 'confused deputy' attack by asking TrustZone to use pages that have been donated to protected guests. This would effectively allow the host to have TrustZone exfiltrate guest secrets on its behalf, hence breaking the isolation that pKVM intends to provide. This series addresses this problem by providing pKVM with the ability to monitor SMCs following the Arm FF-A protocol. FF-A provides (among other things) a set of memory management APIs allowing the Normal World to share, donate or lend pages with Secure. By monitoring these SMCs, pKVM can ensure that the pages that are shared, lent or donated to Secure by the host kernel are only pages that it owns. It should be noted that the robustness of this approach relies on having all Secure Software on the device use the FF-A protocol for memory management transactions with the normal world, and not use vendor-specific SMCs that pKVM is unable to parse. This is an important software requirement to integrate pKVM correctly on a device. For the record, this work is tractable in real world scenarios -- it was done for the Pixel 7 and Pixel 7 Pro devices, both of which launched recently with pKVM enabled. This series introduces support for monitoring FF-A SMCs in the form of a minimal proxy running in the EL2 hypervisor. This proxy aims to be entirely 'transparent' to both the host kernel and TrustZone when the system behaves correctly (the host is not compromised). The FF-A proxy intercepts the SMCs coming from the host, and verifies that the pages involved in the memory transition can be shared/lent/donated legally before forwarding the SMC to Secure. The proxy also tracks which pages have been made accessible to TrustZone at any point in time using software bits in the stage-2 page-table of the host, to ensure they can't be subsequently donated to guests. The patch series is divided as follows: - patches 01-02 refactor existing FF-A header to allow code re-use; - patches 03-07 provide the initial infrastructure at EL2 to handle FF-A SMCs; - patches 08-12 use the previously introduced infrastructure to intercept the main memory management operations to share, reclaim and lend memory to/with Secure, and implement the core of the memory tracking logic. Since this series depends on Will's recent pKVM series [1], it is based on today's kvmarm/next: eb8be68e907e ("Merge branch kvm-arm64/misc-6.2 into kvmarm-master/next") A branch with all the goodies applied can also be found here: https://android-kvm.googlesource.com/linux qperret/ffa-proxy Feedback welcome! Cheers, Quentin [1] https://lore.kernel.org/kvm/20221110190259.26861-1-will@kernel.org/ Fuad Tabba (1): KVM: arm64: Handle FFA_FEATURES call from the host Quentin Perret (1): ANDROID: KVM: arm64: pkvm: Add support for fragmented FF-A descriptors Will Deacon (10): firmware: arm_ffa: Move constants to header file firmware: arm_ffa: Move comment before the field it is documenting KVM: arm64: Block unsafe FF-A calls from the host KVM: arm64: Probe FF-A version and host/hyp partition ID during init KVM: arm64: Allocate pages for hypervisor FF-A mailboxes KVM: arm64: Handle FFA_RXTX_MAP and FFA_RXTX_UNMAP calls from the host KVM: arm64: Add FF-A helpers to share/unshare memory with secure world KVM: arm64: Handle FFA_MEM_SHARE calls from the host KVM: arm64: Handle FFA_MEM_RECLAIM calls from the host KVM: arm64: Handle FFA_MEM_LEND calls from the host arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/include/asm/kvm_pkvm.h | 21 + arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/hyp/include/nvhe/ffa.h | 17 + arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 3 + arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/ffa.c | 741 ++++++++++++++++++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 3 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 68 ++ arch/arm64/kvm/hyp/nvhe/setup.c | 11 + arch/arm64/kvm/pkvm.c | 1 + drivers/firmware/arm_ffa/driver.c | 101 +-- include/linux/arm_ffa.h | 93 ++- 13 files changed, 970 insertions(+), 93 deletions(-) create mode 100644 arch/arm64/kvm/hyp/include/nvhe/ffa.h create mode 100644 arch/arm64/kvm/hyp/nvhe/ffa.c