Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp390819lqh; Tue, 7 May 2024 02:16:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVFFMQ+25qpwnfAA/Abqkpz0HKNGtxHOFIuB2/idcCYref+pURb0xG9MD8DC70+pTjGBCSck++1vu3Xg5YZIdGIYIXixo4Sk7T6V13CmQ== X-Google-Smtp-Source: AGHT+IGbJ5nf9Zaz3v88cIEnmNI0zLQANdE5G2twn+Lp0tQHsDQBf6sTKu8XMQ19EwkTRZatt2uE X-Received: by 2002:a17:906:5d7:b0:a55:5e89:a158 with SMTP id t23-20020a17090605d700b00a555e89a158mr7143632ejt.68.1715073415135; Tue, 07 May 2024 02:16:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715073415; cv=pass; d=google.com; s=arc-20160816; b=GB0IOoaTx0FbTE1kJkG/rVHbm/Xqvc5r9O1OWa+znjZYpAYOEuXmkk15kbmFCVBWQ+ xg6uwaKb9uKUH71PJoqlZ/LXSqWbaxkAJODJOaA6aCyhiC92Kova+7OS3dSr8Dn8h5A7 A71+JRn5F+O0xPCBwGasn41RxIPDsG+0ypbKitRVJiIOTDHMj23+cQ3jHsYnj9iC27Se fE2WuCSMsuDPnzxmp6zNfVYBp6dOmOF1x5zARFTF1/LvaLq2p4AMJCM/r4lxRbMOASlV estwqCNf9h9MkavooAuPKL4KUBco9RVwt6aBnZAUO0oWZpI69a/4z81ulr4+1c5+TjDJ n2LQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=TWFAIax7VgJLZxRlWO/4+BtD7d88wmBQmcI+YeYknLY=; fh=RlDY2mPKy+HlQ1FzhBaZNhQbzI0xSu49jPq+8ZnZKCc=; b=XEJSnJfJF7bCCc01zy2RjLi0IZT4lV1RVUVU9AGYPGzwhWFoQt6+bYQrPnUn0XQJ8e Z5R/r01L5/zMgN+IRKKnpjl8suCtVCY5h1p6BOOVpY5cvLe0fLVsiGHv60eLlyvkS4Yy Kyck6KvEQ6CagPhrA2hMjRaIoPayZhFm3zS9WaKc0lO6zn8Z4topb+/4ibPnGZJ3Ppmq /f7B9ORofYJh8Poji8Q7E67OaNYLJpYLZ8hJ4wZAErwJHVvIdq+ryB+jECvpGFGxqL55 K2ObW7BPD7FkhG3xwU2WpAw1ZhuB/2Md2k2rGH13tWZPXAmdtU7m7ZMV7WXO/sxHOq3h pkEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fH2yJVU7; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-170921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id by8-20020a170906a2c800b00a59deaa543asi1276888ejb.443.2024.05.07.02.16.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 02:16:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fH2yJVU7; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-170921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AFBD81F226A2 for ; Tue, 7 May 2024 09:16:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D49214D708; Tue, 7 May 2024 09:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fH2yJVU7" Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22CF110E3 for ; Tue, 7 May 2024 09:16:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715073409; cv=none; b=tpVNTtWDk4buknxB+x6klWi9yMZyIYGBa1a3jwzC5WQntd6BnKRt6r1Zf8eG2pexpKt+baZPMaUSlxEU1DMsiTb2wKM9bt7z+WwGTTsiHLxVej1tMRdeEOsOwAG1AWDvCYw2hF6NIUjD017eMIRRLbh1cQeL81IItLCzDl+gAN0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715073409; c=relaxed/simple; bh=ZlFj5mE6OAnUWsN7WRwEHHNDMDdnvkwd2e0VijNGXzs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=qSHzGUU6hmBe4z2bZkX0QDIz7jmW+yVtusRK7WbKG9tisaaQlvdYJCoqhWt9ZjMUWNCNg3OLUvufaB4y7zWQQUfy+zcuswOoqOs/8Kz9jYj1PwABeolg2tol5qMOvPZoQ+G13npbcXSmTJFx4WbUT/sbKVv1+mbvZ/ACjmsOlco= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=fH2yJVU7; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a59a64db066so712173666b.3 for ; Tue, 07 May 2024 02:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715073405; x=1715678205; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TWFAIax7VgJLZxRlWO/4+BtD7d88wmBQmcI+YeYknLY=; b=fH2yJVU77NtsEfkpS6kmlwVNYevL7P1/nR/3Emd4WkumDTh2XBo7kMKPWL0FI38KtO e3mg4xfSLDmxgdteqT82bGrCmDLOc7szuiPi8IhZIl1Gk4zpqaXqh6o+M9VjuAQT2Dpf aLXPxX4LyEsPrynqw0EmeERTmKoCXCm/fImnZmh+AyxwJQgG5TqNGGn/gjlxKFxV/h4C /9aLD/+y/yoYRhq1AjY9G/STGl2X5c4n4jKWSGPUddI7xvzcG1etolo8J3OXu9C5k1ej gfTYzfxDZ/ftVaV8Br6m4DVvTXshBWfGg5XVfayXBGvvZFkNKolcxirDBcENOtqut0YF yU8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715073405; x=1715678205; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TWFAIax7VgJLZxRlWO/4+BtD7d88wmBQmcI+YeYknLY=; b=KsXwQGtDjHEgZPIy9h2aqkzRoNjwalasS/ojGiAowRtSJ16mQNPjiRijCgwXvGqWFQ ZUZyo1jOdwSAoM2Ac8nmFkIxh7HU+tBywF4MEOclBPseUAFeUWck/aHtOchd7AHINO1p S3l+BKYcOp9b0iURBjms5IFxCMGipkl1QN2gJFNSDKIRQ3zJ5WMVIYda8guKo7PY4Gt/ yS6gQ2gCdiihQ1CiYra3iDuERT0A5bXBqi4NltQ8XlRi9eXVWsQALkS8ASZmoWzNq5r1 RvpNFWw5IwCuqYXwlXda6HAAdIkyAv541dY+lhoUCvgNdZzkQiW9h1fqneeyzNN+fWOM dSaA== X-Gm-Message-State: AOJu0YzPizWSDUceinzLQs5I7SAO93oO3G+OVdqh5Tlp+y+EFASvH8FQ eV4JLjbk/pSiEof+zWak7qWuDzql1/EhpgxmGUK1vkMvQlQmjYLwEerXqgKpxtvYMigt9gvk+0N X X-Received: by 2002:a17:907:50f:b0:a59:9c4d:da3c with SMTP id wj15-20020a170907050f00b00a599c4dda3cmr6249505ejb.40.1715073404835; Tue, 07 May 2024 02:16:44 -0700 (PDT) Received: from rayden.urgonet (h-217-31-164-171.A175.priv.bahnhof.se. [217.31.164.171]) by smtp.gmail.com with ESMTPSA id o7-20020a1709061d4700b00a59a93a3ef4sm3976134ejh.149.2024.05.07.02.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 02:16:44 -0700 (PDT) From: Jens Wiklander To: linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, op-tee@lists.trustedfirmware.org Cc: Shyam Saini , Ulf Hansson , Linus Walleij , Jerome Forissier , Sumit Garg , Ilias Apalodimas , Bart Van Assche , Randy Dunlap , Ard Biesheuvel , Arnd Bergmann , Greg Kroah-Hartman , Manuel Traut , Jens Wiklander Subject: [PATCH v6 0/3] Replay Protected Memory Block (RPMB) subsystem Date: Tue, 7 May 2024 11:16:16 +0200 Message-Id: <20240507091619.2208810-1-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi, This patch set introduces a new RPMB subsystem, based on patches from [1], [2], and [3]. The RPMB subsystem aims at providing access to RPMB partitions to other kernel drivers, in particular the OP-TEE driver. A new user space ABI isn't needed, we can instead continue using the already present ABI when writing the RPMB key during production. I've added and removed things to keep only what is needed by the OP-TEE driver. Since the posting of [3], there has been major changes in the MMC subsystem so "mmc: block: register RPMB partition with the RPMB subsystem" is in practice completely rewritten. With this OP-TEE can access RPMB during early boot instead of having to wait for user space to become available as in the current design [4]. This will benefit the efi variables [5] since we wont rely on userspace as well as some TPM issues [6] that were solved. The OP-TEE driver finds the correct RPMB device to interact with by iterating over available devices until one is found with a programmed authentication matching the one OP-TEE is using. This enables coexisting users of other RPMBs since the owner can be determined by who knows the authentication key. The corresponding secure world OP-TEE patches are available at [7]. I've put myself as a maintainer for the RPMB subsystem as I have an interest in the OP-TEE driver to keep this in good shape. However, if you'd rather see someone else taking the maintainership that's fine too. I'll help keep the subsystem updated regardless. [1] https://lore.kernel.org/lkml/20230722014037.42647-1-shyamsaini@linux.microsoft.com/ [2] https://lore.kernel.org/lkml/20220405093759.1126835-2-alex.bennee@linaro.org/ [3] https://lore.kernel.org/linux-mmc/1478548394-8184-2-git-send-email-tomas.winkler@intel.com/ [4] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html#rpmb-secure-storage [5] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c44b6be62e8dd4ee0a308c36a70620613e6fc55f [6] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7269cba53d906cf257c139d3b3a53ad272176bca [7] https://github.com/jenswi-linaro/optee_os/tree/rpmb_probe_v6 Thanks, Jens Changes since v5: Manuel Traut reported and investigated an error on an i.MX8MM, the root cause was identified as insufficient alignment on frames sent to the RPMB device. Fixed in the OP-TEE driver as described below. * "rpmb: add Replay Protected Memory Block (RPMB) subsystem" - Adding a missing EXPORT_SYMBOL_GPL() * "optee: probe RPMB device using RPMB subsystem" - Replacing the old OPTEE_RPC_CMD_RPMB ABI with OPTEE_RPC_CMD_RPMB_FRAMES to get rid of the small header struct rpmb_req (now removed) causing the problem. - Matching changes on the secure side + support for re-initializing RPMB in case a boot stage has used RPMB, the latter also reported by Manuel Traut. Changes since v4: * "rpmb: add Replay Protected Memory Block (RPMB) subsystem" - Describing struct rpmb_descr as RPMB description instead of descriptor * "mmc: block: register RPMB partition with the RPMB subsystem" - Addressing review comments - Adding more comments for struct rpmb_frame - Fixing assignment of reliable_wr_count and capacity in mmc_blk_rpmb_add() * "optee: probe RPMB device using RPMB subsystem" - Updating struct rpmb_dev_info to match changes in "rpmb: add Replay Protected Memory Block (RPMB) subsystem" Changes since v3: * Move struct rpmb_frame into the MMC driver since the format of the RPMB frames depend on the implementation, one format for eMMC, another for UFS, and so on * "rpmb: add Replay Protected Memory Block (RPMB) subsystem" - Adding Reviewed-by: Linus Walleij - Adding more description of the API functions - Removing the set_dev_info() op from struct rpmb_ops, the needed information is supplied in the arguments to rpmb_dev_register() instead. - Getting rid of struct rpmb_ops since only the route_frames() op was remaining, store that op directly in struct rpmb_dev - Changed rpmb_interface_register() and rpmb_interface_unregister() to use notifier_block instead of implementing the same thing ourselves * "mmc: block: register RPMB partition with the RPMB subsystem" - Moving the call to rpmb_dev_register() to be done at the end of mmc_blk_probe() when the device is fully available * "optee: probe RPMB device using RPMB subsystem" - Use IS_REACHABLE(CONFIG_RPMB) to determine if the RPMB subsystem is available - Translate TEE_ERROR_STORAGE_NOT_AVAILABLE if encountered in get_devices() to recognize the error in optee_rpmb_scan() - Simplified optee_rpmb_scan() and optee_rpmb_intf_rdev() Changes since v2: * "rpmb: add Replay Protected Memory Block (RPMB) subsystem" - Fixing documentation issues - Adding a "depends on MMC" in the Kconfig - Removed the class-device and the embedded device, struct rpmb_dev now relies on the parent device for reference counting as requested - Removed the now unneeded rpmb_ops get_resources() and put_resources() since references are already taken in mmc_blk_alloc_rpmb_part() before rpmb_dev_register() is called - Added rpmb_interface_{,un}register() now that class_interface_{,un}register() can't be used ay longer * "mmc: block: register RPMB partition with the RPMB subsystem" - Adding the missing error cleanup in alloc_idata() - Taking the needed reference to md->disk in mmc_blk_alloc_rpmb_part() instead of in mmc_rpmb_chrdev_open() and rpmb_op_mmc_get_resources() * "optee: probe RPMB device using RPMB subsystem" - Registering to get a notification when an RPMB device comes online - Probes for RPMB devices each time an RPMB device comes online, until a usable device is found - When a usable RPMB device is found, call optee_enumerate_devices(PTA_CMD_GET_DEVICES_RPMB) - Pass type of rpmb in return value from OPTEE_RPC_CMD_RPMB_PROBE_NEXT Changes since Shyam's RFC: * Removed the remaining leftover rpmb_cdev_*() function calls * Refactored the struct rpmb_ops with all the previous ops replaced, in some sense closer to [3] with the route_frames() op * Added rpmb_route_frames() * Added struct rpmb_frame, enum rpmb_op_result, and enum rpmb_type from [3] * Removed all functions not needed in the OP-TEE use case * Added "mmc: block: register RPMB partition with the RPMB subsystem", based on the commit with the same name in [3] * Added "optee: probe RPMB device using RPMB subsystem" for integration with OP-TEE * Moved the RPMB driver into drivers/misc/rpmb-core.c * Added my name to MODULE_AUTHOR() in rpmb-core.c * Added an rpmb_mutex to serialize access to the IDA * Removed the target parameter from all rpmb_*() functions since it's currently unused Jens Wiklander (3): rpmb: add Replay Protected Memory Block (RPMB) subsystem mmc: block: register RPMB partition with the RPMB subsystem optee: probe RPMB device using RPMB subsystem MAINTAINERS | 7 + drivers/misc/Kconfig | 10 ++ drivers/misc/Makefile | 1 + drivers/misc/rpmb-core.c | 233 +++++++++++++++++++++++++++++ drivers/mmc/core/block.c | 241 +++++++++++++++++++++++++++++- drivers/tee/optee/core.c | 30 ++++ drivers/tee/optee/device.c | 7 + drivers/tee/optee/ffa_abi.c | 8 + drivers/tee/optee/optee_private.h | 21 ++- drivers/tee/optee/optee_rpc_cmd.h | 35 +++++ drivers/tee/optee/rpc.c | 166 ++++++++++++++++++++ drivers/tee/optee/smc_abi.c | 7 + include/linux/rpmb.h | 136 +++++++++++++++++ 13 files changed, 899 insertions(+), 3 deletions(-) create mode 100644 drivers/misc/rpmb-core.c create mode 100644 include/linux/rpmb.h -- 2.34.1