From patchwork Mon Nov 21 14:12:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolaus Voss X-Patchwork-Id: 23781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1620218wrr; Mon, 21 Nov 2022 06:27:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf6SIRGRR7PGYkNPpyhSUxR7ukljgs8CwdCneBe+qUWmodd9E99cIUqQIkS+OIJjB5nQWCBt X-Received: by 2002:a05:6402:3892:b0:454:cbef:c161 with SMTP id fd18-20020a056402389200b00454cbefc161mr17172528edb.365.1669040866579; Mon, 21 Nov 2022 06:27:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669040866; cv=none; d=google.com; s=arc-20160816; b=IVsf0PKSgvo5BJ5289dON7D7l2bbdrMKo99kEnXei4r6YQ5uF//eSjkgBnXlRRL06y 2BlnuBxJE8ek4s/35y1khfrfjxxDqvG96/HS2rgmOpr5q2NHhWLa3R/416332arXU5gu cy09jjLSMk5BxpSKVfQ6U2RfeEVFGi302qr2qfeO4l8fGM0RNPWEQvSdh9+/EeNOKfK8 oFPzp84TfoD6/P5sFeRPCE3xL0kyl4SqtZR2oZkDX9R9MY8OVmSDOo/ip04ERVKu1tF2 qctJVCZC2+kFBiAPf8M7ymzeuSYkBeQdKqOS3db9hwpA3hNYMIPlNTU4/JGKSAdPj7ob pDSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:subject:date:cc:to:from; bh=JGkyQGpMkpIf5bgSljSYYi4lIe7AImsEwgRJaQB+6lk=; b=ZhRKfR6jPJpwbrrfvEMUn+UW8l9fNSSFL20a9uGNWGEDPGeGJslsP9vDbVKGNEWwKE tOpvDI9Q04ts8mfXnxjxyyUR7xfTKiTMPHSiR70QEvohYj2pSANpU8Ac49e7T+GeQiYY VCCJkI6zFT5VYI8xU48Eab1EqFOgWWaDuQatgz4Joi9eU3Lt1Xbkux1ybzI9tkk6fnjp uT59ro9NtDqEXfpO/LDvo+/p5yqiv5RjhssHiPgYjiEUT8ioxmytNwkhX7lNS/jT9nBq VJTcRGtrBOCeTujRxr70+wU4H8XdPCCDO4wLp5CZPin759ugpYKl6AOH9SeJEK/u6Yyi +++g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=haag-streit.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf21-20020a1709077f1500b007ae4ed41508si9755703ejc.738.2022.11.21.06.27.21; Mon, 21 Nov 2022 06:27:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=haag-streit.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229864AbiKUOTk (ORCPT + 99 others); Mon, 21 Nov 2022 09:19:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbiKUOTj (ORCPT ); Mon, 21 Nov 2022 09:19:39 -0500 Received: from mail.steuer-voss.de (mail.steuer-voss.de [85.183.69.95]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B281126; Mon, 21 Nov 2022 06:19:36 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at mail.steuer-voss.de Received: by mail.steuer-voss.de (Postfix, from userid 1000) id 2E36427E9; Mon, 21 Nov 2022 15:19:29 +0100 (CET) From: Nikolaus Voss To: "Horia Geanta" , Pankaj Gupta , Gaurav Jain , Herbert Xu , "David S. Miller" , Ahmad Fatoum , David Gstir , Steffen Trumtrar , Nikolaus Voss Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 21 Nov 2022 15:12:41 +0100 Subject: [PATCH v3] crypto: caam: blob_gen.c: warn if key is insecure Message-Id: <20221121141929.2E36427E9@mail.steuer-voss.de> X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750116195903658244?= X-GMAIL-MSGID: =?utf-8?q?1750116195903658244?= If CAAM is not in "trusted" or "secure" state, a fixed non-volatile key is used instead of the unique device key. This is the default mode of operation without secure boot (HAB). In this scenario, CAAM encrypted blobs should be used only for testing but not in a production environment, so issue a warning. Signed-off-by: Nikolaus Voss Reviewed-by: Ahmad Fatoum --- CHANGES ======= v2: make warning more verbose, correct register, style fixes v3: fix sparse warning "dereference of noderef expression" by using ioread32() to dereference iomem pointer drivers/crypto/caam/blob_gen.c | 9 +++++++++ drivers/crypto/caam/regs.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/drivers/crypto/caam/blob_gen.c b/drivers/crypto/caam/blob_gen.c index 6345c7269eb03..1f65df4898478 100644 --- a/drivers/crypto/caam/blob_gen.c +++ b/drivers/crypto/caam/blob_gen.c @@ -6,6 +6,7 @@ #define pr_fmt(fmt) "caam blob_gen: " fmt +#include #include #include @@ -61,12 +62,14 @@ static void caam_blob_job_done(struct device *dev, u32 *desc, u32 err, void *con int caam_process_blob(struct caam_blob_priv *priv, struct caam_blob_info *info, bool encap) { + const struct caam_drv_private *ctrlpriv; struct caam_blob_job_result testres; struct device *jrdev = &priv->jrdev; dma_addr_t dma_in, dma_out; int op = OP_PCLID_BLOB; size_t output_len; u32 *desc; + u32 moo; int ret; if (info->key_mod_len > CAAM_BLOB_KEYMOD_LENGTH) @@ -100,6 +103,12 @@ int caam_process_blob(struct caam_blob_priv *priv, goto out_unmap_in; } + ctrlpriv = dev_get_drvdata(jrdev->parent); + moo = FIELD_GET(CSTA_MOO, ioread32(&ctrlpriv->ctrl->perfmon.status)); + if (moo != CSTA_MOO_SECURE && moo != CSTA_MOO_TRUSTED) + dev_warn(jrdev, + "using insecure test key, enable HAB to use unique device key!\n"); + /* * A data blob is encrypted using a blob key (BK); a random number. * The BK is used as an AES-CCM key. The initial block (B0) and the diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h index 66d6dad841bb2..66928f8a0c4b1 100644 --- a/drivers/crypto/caam/regs.h +++ b/drivers/crypto/caam/regs.h @@ -426,6 +426,9 @@ struct caam_perfmon { u32 rsvd2; #define CSTA_PLEND BIT(10) #define CSTA_ALT_PLEND BIT(18) +#define CSTA_MOO GENMASK(9, 8) +#define CSTA_MOO_SECURE 1 +#define CSTA_MOO_TRUSTED 2 u32 status; /* CSTA - CAAM Status */ u64 rsvd3;