From patchwork Wed Oct 19 12:44:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolaus Voss X-Patchwork-Id: 5640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp379181wrs; Wed, 19 Oct 2022 08:10:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7mX85HizPCw8bMCm4/R6vYU08xn8AYWOjDuBRjAvTbFX8SByCma+R8S8E7epRaCeLyHmc2 X-Received: by 2002:a17:907:60c8:b0:78d:bc56:8f04 with SMTP id hv8-20020a17090760c800b0078dbc568f04mr6978705ejc.560.1666192227478; Wed, 19 Oct 2022 08:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192227; cv=none; d=google.com; s=arc-20160816; b=THjJJPHRNQJyEujxBU+LBadkSTgdhV5RQ4bX64S7bC7MRezCd/W1XCpF2P9fnaA73j IdU3AY2XTCgsw5aVjRkQKIS0kNUH4cSjAxI/gAMki37jIZShKCOn1Wmz08rrYcFq1ESJ Scpjfovs1iG2CwKK/rfT9GtTBKwtNveUfgJgdFeQ0OWmHiuRFMgzcbVGIVRK4Au/D67N 6LRKC4Seyo9Z/e9nPfk2V8nGute6bUCDUOmick2KuYPxZo7Np30hYI0FGPW/p68G4Xhl LbHsqoSe+GR5lYth/tc5yt4/UDPSiMFEljKqTzaxIDk66TSLjN7/2dwRtC0fQ2jlZpGM kYUg== 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=5g6KKaai9koXnPnglSQVElnQDDShWVsd1eAhYo/OvRM=; b=zX+lz6M2YOgneka1z/1nwkEOz6lKZzvv1F9C3N9YJ/FmWcRkweyVvHQ5PVa7Yi9DjR n354VvQA/AhP3+4x4jWify0Zl3hQEpPtDt75nLb95xsT08wmzs/nHbfy4cQAR/+cWnGp SCHAIvr9pTfF0cdQ85vEusJeXGtoawrAdNVWh/KEam1lsRlolco+ggJcknPxMCWv2lfu B1tyfTqs9ShmdZVdpJt5Gye1x5dhan3+5TFShttYd9JTxfVRn1IPAlE67REGJqWJ6x6F LWlnDFYrhAAUy05qFVvGFCQuFG0ZymETh/Q3y8aHB9pJAcvY/H9BFpMjzGinCxasd/jc s1+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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id st11-20020a170907c08b00b007948b932e6bsi675082ejc.227.2022.10.19.08.09.44; Wed, 19 Oct 2022 08:10:27 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231245AbiJSO5n (ORCPT + 99 others); Wed, 19 Oct 2022 10:57:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231761AbiJSO5P (ORCPT ); Wed, 19 Oct 2022 10:57:15 -0400 X-Greylist: delayed 571 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 19 Oct 2022 07:50:45 PDT Received: from mail.steuer-voss.de (mail.steuer-voss.de [85.183.69.95]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 735034BD19; Wed, 19 Oct 2022 07:50:44 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at mail.steuer-voss.de Received: by mail.steuer-voss.de (Postfix, from userid 1000) id 48E1B1B0E; Wed, 19 Oct 2022 16:41:08 +0200 (CEST) From: Nikolaus Voss To: "Horia Geanta" , Pankaj Gupta , Gaurav Jain , Herbert Xu , "David S. Miller" , Ahmad Fatoum , David Gstir , Steffen Trumtrar Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 19 Oct 2022 14:44:56 +0200 Subject: [PATCH] crypto: caam: blob_gen.c: warn if key is insecure Message-Id: <20221019144108.48E1B1B0E@mail.steuer-voss.de> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham 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?1747129181492879769?= X-GMAIL-MSGID: =?utf-8?q?1747129181492879769?= 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 --- drivers/crypto/caam/blob_gen.c | 8 ++++++++ drivers/crypto/caam/regs.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/drivers/crypto/caam/blob_gen.c b/drivers/crypto/caam/blob_gen.c index 6345c7269eb0..f3e741393f65 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 @@ -62,11 +63,13 @@ int caam_process_blob(struct caam_blob_priv *priv, struct caam_blob_info *info, bool encap) { struct caam_blob_job_result testres; + const struct caam_drv_private *ctrlpriv; 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,11 @@ int caam_process_blob(struct caam_blob_priv *priv, goto out_unmap_in; } + ctrlpriv = dev_get_drvdata(jrdev->parent); + moo = FIELD_GET(CSTA_MOO, ctrlpriv->ctrl->perfmon.status); + if (moo != CSTA_MOO_SECURE && moo != CSTA_MOO_TRUSTED) + dev_warn(jrdev, "using insecure test 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 66d6dad841bb..b7de5fb5e056 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 3 u32 status; /* CSTA - CAAM Status */ u64 rsvd3;