From patchwork Wed Apr 3 07:21:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gstir X-Patchwork-Id: 13615066 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 E5723C6FD1F for ; Wed, 3 Apr 2024 07:22:05 +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:MIME-Version:Message-ID:Date:Subject:Cc :To:From: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=+sC7WVs9X5ptrwmXxe42fqQj4TZfuVedh8M2LqJsbEs=; b=z2HRsMY4/DGCH1 BCiW46KWVr2BCgPM/V6KESpnBDuas7YllDz8h4sxzWnLAGQ6JcYeRSEVzC9HAI/SjvlF2tR+ubvk6 kMlCbdUb4Z8JNSeiyWy5XdW1KQn6UYZZeTOp8qPMjZdpDI3sR+WiFujDGvUwm7xsiapLGZaOA8Y76 FeKTBAcOtLIFz7u65AdECSv/8HzcG7UJ+QFbbK24BZyqF8Je5ZkI9uOgWADGFqbiPLEom0WIClDKd A6LG+8Mpxwg8rxs0llfLyoP/PGzM9EBG44EvJV2eg3J6+TZodkx5wv+UP8tIhiL6zv54J8sVDgiy6 cfuGfie1nd2bcUEOnjFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rruwK-0000000ET9A-2v62; Wed, 03 Apr 2024 07:21:44 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rruwG-0000000ET6b-3t1W for linux-arm-kernel@lists.infradead.org; Wed, 03 Apr 2024 07:21:42 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-41624fd9af6so240675e9.2 for ; Wed, 03 Apr 2024 00:21:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sigma-star.at; s=google; t=1712128898; x=1712733698; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=s6o/FOMMgtA6Efh2lZOLXQIlSvJPNil2JE+ZCOQOQcY=; b=unmJcuIBJrPI8MkJ49UHD0+1v9Ry9SzqOk6nDzp86BKJfM+VEt7+Tpp8FnznvDaSmr 8GYpa2La/L9lgWML7eLnjSzgcU1jAoboZOU884Zd9LkBS1SxSAHO4hgEzMGtKtGwDQ5s oV5avDgpHfy4zuXYJE7vqoGurts+kAXR3nNlEKzyJ13HU69b9hLTBaEGJLBmcWl2flPA g5prWf1hDUMRPQQzoApjpkuenocsl582oqKPmp6cQNwsMU/JXQaAOeFgitYj6nJ2s48p yqKdriPwsoN0aBjlza9DJ3JUeq5yHE1/C1SKJQ7l2nvF50/0Lkjy/2ahPBIm44xNkKCK XQjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712128898; x=1712733698; 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=s6o/FOMMgtA6Efh2lZOLXQIlSvJPNil2JE+ZCOQOQcY=; b=o0njXc5SeogQTusiyFjytKtZpqF8ezxJkt72inK14YhwbLwtiDbyKEvGTWGZnHRb7c c1U0+VM1dmhuAP9p+w4epTk+UINSQLbkZPnOHnhggFGIygGq8wKvgEE3hTNeX6wMq3OJ 7w9L3i602xOxEhy6sz+ZaZf2UAXf3eDMvfkRSM6byMSboCSXMnPOsLJ+V9D+Ovw6XWSS LTo2ikZUvmEJAy27KhsrLlAloeFLUkLGvSnDhMoHl/b0O1xib0yPFlW4Jv3WsELlERHr 2TIkRJZPngg+fs9apE+HUhrd4Q2snJb+qKJjfVuwGSVzZNuvd78awo4NHnAcTHmJj1fR CThA== X-Forwarded-Encrypted: i=1; AJvYcCWGlP6kYOMTF2DW7T0Ily9mKWKTcsJAp5UPDCGSVAcyXIs4XNra6yQBPoY34wbC9RVMOG8ReXddoB0kfG57O7xVy8S7yl59VinV5/j69wzxFOrBbic= X-Gm-Message-State: AOJu0YwJ1joaS/KCMbt8jTukLpF/G0ZjAbJXOqhh0E/UYKvVG3w6yX8S LQIKkbppaGK1gRahcmeJI0PfXT7Q3awvBR5GT618ZoigxdsiR/o12GJOvSukWw8= X-Google-Smtp-Source: AGHT+IE/9Err26oBHnEgT5MkWJu1wDbsY5yCN4Hvc9o++TppeTxaNTSGe+M4pKLLv7eHhFdjLQngyw== X-Received: by 2002:a05:600c:35c5:b0:414:22b5:c33a with SMTP id r5-20020a05600c35c500b0041422b5c33amr10417809wmq.1.1712128898557; Wed, 03 Apr 2024 00:21:38 -0700 (PDT) Received: from localhost ([82.150.214.1]) by smtp.gmail.com with UTF8SMTPSA id r5-20020a056000014500b00341dc343e21sm16328599wrx.65.2024.04.03.00.21.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Apr 2024 00:21:38 -0700 (PDT) From: David Gstir To: Mimi Zohar , James Bottomley , Jarkko Sakkinen , Herbert Xu , "David S. Miller" Cc: David Gstir , Shawn Guo , Jonathan Corbet , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Ahmad Fatoum , sigma star Kernel Team , David Howells , Li Yang , Paul Moore , James Morris , "Serge E. Hallyn" , "Paul E. McKenney" , Randy Dunlap , Catalin Marinas , "Rafael J. Wysocki" , Tejun Heo , "Steven Rostedt (Google)" , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-security-module@vger.kernel.org Subject: [PATCH v8 0/6] DCP as trusted keys backend Date: Wed, 3 Apr 2024 09:21:16 +0200 Message-ID: <20240403072131.54935-1-david@sigma-star.at> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240403_002141_269156_8B12E6A1 X-CRM114-Status: GOOD ( 24.27 ) 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 This is a revival of the previous patch set submitted by Richard Weinberger: https://lore.kernel.org/linux-integrity/20210614201620.30451-1-richard@nod.at/ After having been thoroughly reviewed by Jarkko, it would be great if this could go into 6.10. :-) v7 is here: https://lore.kernel.org/keyrings/20240327082454.13729-1-david@sigma-star.at/ v7 -> v8: - Add Reviewed-by from Jarkko Sakkinen for patches #2 and #5 - Use kernel-doc for DCP blob format documentation instead of copy-pasting as suggested by Jarkko Sakkinen - Fix wording in docs for trusted.dcp_skip_zk_test kernel param v6 -> v7: - Add Reviewed-by from Jarkko Sakkinen for patches #1 and #3 - Improved commit messages - Changed log level for non-trusted/secure mode check from error to warning v5 -> v6: - Cleaned up coding style and commit messages to make the whole series more coherent as suggested by Jarkko Sakkinen - Added Acked-By from Jarkko Sakkinen to patch #4 - thanks! - Rebased against next-20240307 v4 -> v5: - Make Kconfig for trust source check scalable as suggested by Jarkko Sakkinen - Add Acked-By from Herbert Xu to patch #1 - thanks! v3 -> v4: - Split changes on MAINTAINERS and documentation into dedicated patches - Use more concise wording in commit messages as suggested by Jarkko Sakkinen v2 -> v3: - Addressed review comments from Jarkko Sakkinen v1 -> v2: - Revive and rebase to latest version - Include review comments from Ahmad Fatoum The Data Co-Processor (DCP) is an IP core built into many NXP SoCs such as i.mx6ull. Similar to the CAAM engine used in more powerful SoCs, DCP can AES- encrypt/decrypt user data using a unique, never-disclosed, device-specific key. Unlike CAAM though, it cannot directly wrap and unwrap blobs in hardware. As DCP offers only the bare minimum feature set and a blob mechanism needs aid from software. A blob in this case is a piece of sensitive data (e.g. a key) that is encrypted and authenticated using the device-specific key so that unwrapping can only be done on the hardware where the blob was wrapped. This patch series adds a DCP based, trusted-key backend and is similar in spirit to the one by Ahmad Fatoum [0] that does the same for CAAM. It is of interest for similar use cases as the CAAM patch set, but for lower end devices, where CAAM is not available. Because constructing and parsing the blob has to happen in software, we needed to decide on a blob format and chose the following: struct dcp_blob_fmt { __u8 fmt_version; __u8 blob_key[AES_KEYSIZE_128]; __u8 nonce[AES_KEYSIZE_128]; __le32 payload_len; __u8 payload[]; } __packed; The `fmt_version` is currently 1. The encrypted key is stored in the payload area. It is AES-128-GCM encrypted using `blob_key` and `nonce`, GCM auth tag is attached at the end of the payload (`payload_len` does not include the size of the auth tag). The `blob_key` itself is encrypted in AES-128-ECB mode by DCP using the OTP or UNIQUE device key. A new `blob_key` and `nonce` are generated randomly, when sealing/exporting the DCP blob. This patchset was tested with dm-crypt on an i.MX6ULL board. [0] https://lore.kernel.org/keyrings/20220513145705.2080323-1-a.fatoum@pengutronix.de/ David Gstir (6): crypto: mxs-dcp: Add support for hardware-bound keys KEYS: trusted: improve scalability of trust source config KEYS: trusted: Introduce NXP DCP-backed trusted keys MAINTAINERS: add entry for DCP-based trusted keys docs: document DCP-backed trusted keys kernel params docs: trusted-encrypted: add DCP as new trust source .../admin-guide/kernel-parameters.txt | 13 + .../security/keys/trusted-encrypted.rst | 53 +++ MAINTAINERS | 9 + drivers/crypto/mxs-dcp.c | 104 +++++- include/keys/trusted_dcp.h | 11 + include/soc/fsl/dcp.h | 20 ++ security/keys/trusted-keys/Kconfig | 18 +- security/keys/trusted-keys/Makefile | 2 + security/keys/trusted-keys/trusted_core.c | 6 +- security/keys/trusted-keys/trusted_dcp.c | 332 ++++++++++++++++++ 10 files changed, 554 insertions(+), 14 deletions(-) create mode 100644 include/keys/trusted_dcp.h create mode 100644 include/soc/fsl/dcp.h create mode 100644 security/keys/trusted-keys/trusted_dcp.c