From patchwork Mon Apr 10 22:59:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chang S. Bae" X-Patchwork-Id: 81660 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2207622vqo; Mon, 10 Apr 2023 16:13:02 -0700 (PDT) X-Google-Smtp-Source: AKy350ZkNYLTkgmRemcrs7Iv5gGApDdfe+bNkiNYj50+4N4t86VJlQD4gTIYITk8O1CMN8eSLqsz X-Received: by 2002:a17:907:9626:b0:947:92c9:6aa4 with SMTP id gb38-20020a170907962600b0094792c96aa4mr10624247ejc.4.1681168382580; Mon, 10 Apr 2023 16:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681168382; cv=none; d=google.com; s=arc-20160816; b=g8Sg3kzu/4pINopV2KztBPa1OJlvRgpP+YmjBWNFrkcIwsYthN/9zep5OAKgc+Y6Si nOoHpGwm0l4EYNxqqPbbyES0Nw8J46iE1gkzISXRyswbL/XToxynOaxFvqKBx74bl/RA BZ/0dYso+ho9n/e45gzYySDXFmj0XuZyoSRh+tVyBckGOCAtNu7YRtfw9qIJ0G+A+zP6 0sDC7cYg7XCOvKBgF3rgy+DCsajXPpLXt5FCjX1OmWQv3lLjttPvxrWyuG9Es7FtccQ5 Y9XyxruILGK3G37yXW93I/ox5yo3Vv0cV1Eypwun/yIFzClnN6ayHq3ElN5x5dKzCcjH w2dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=XARnkFDl10S53DYnCzCj0Vo90c4Ap9Itp3j/y5Ky/+Q=; b=zoto9pHV7BhcF8bF7TNNCZil2eEcgwoOodUgmTtsfIq43vZxG6PyD9GI01Q5UymvwD zgUuLbqUBd0z1uwp3UDJYT/+uGzotvP9Zsp6YhWB/U5sCrjpwhs6Il9Pidj8LJaDozgE 6oecqyPdnyT1jodw1jakMWS2yxoVqgBp+0S/rRhE0Y5nebaqmnlWVsgXy+vr/+DR+b+B Y//9FqQ7IIZhzlnBlOgwBC93rr6oSm/2tCwJ6eyNqnJH5Pr8nczg42tzS2vfv8MlmOex CLVHbuZny5/qjJ0el+xMPZTQQxGk81NCnAnutBLQ0LuRJxg+oJ7tFyODS8usvczVA/xT KB1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C0JE0NVk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr41-20020a1709073fa900b009453c587601si11029618ejc.782.2023.04.10.16.12.38; Mon, 10 Apr 2023 16:13:02 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=C0JE0NVk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229844AbjDJXLs (ORCPT + 99 others); Mon, 10 Apr 2023 19:11:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbjDJXLl (ORCPT ); Mon, 10 Apr 2023 19:11:41 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 966C9211E; Mon, 10 Apr 2023 16:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681168300; x=1712704300; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=mh7LCZtK7qkc4vQH6KmOZnQFKL0O2wmnvhs6j7yyDS8=; b=C0JE0NVkNGEb+cCe3ou21/2FHVsGxTgg3sMl0BuGuoPsg+7ntQPQyx8+ ioT0L8a+hqPkFEmSL7QJwTgZ0ASmN952ysE8N2i5KEJQLl03sgrMNg5vF j1cSdvL7yLvJUJp2vlOSZY6QG5/1hcNfLsc5lv6c7oWsY5Wk1N74CoJPw s5wxOGdeb8zH+hQBWGGpfbaDkJN/ry72KSR9Lp43+SY9cdObnUjEUClLB PjIqFgwxtcteItwJPMPqLKDzgksqXddNP68UwNu4Cp9kkRXosUtedQ90F 28KXl4xL7fhugSfYn4/EGrAgAPqpBxeDZQLAfL9yGghlJGoXgeG50Sw9Z w==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="340962491" X-IronPort-AV: E=Sophos;i="5.98,335,1673942400"; d="scan'208";a="340962491" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 16:11:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="757607990" X-IronPort-AV: E=Sophos;i="5.98,335,1673942400"; d="scan'208";a="757607990" Received: from chang-linux-3.sc.intel.com ([172.25.66.173]) by fmsmga004.fm.intel.com with ESMTP; 10 Apr 2023 16:11:38 -0700 From: "Chang S. Bae" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, dm-devel@redhat.com Cc: ebiggers@kernel.org, gmazyland@gmail.com, luto@kernel.org, dave.hansen@linux.intel.com, tglx@linutronix.de, bp@suse.de, mingo@kernel.org, x86@kernel.org, herbert@gondor.apana.org.au, ardb@kernel.org, dan.j.williams@intel.com, bernie.keany@intel.com, charishma1.gairuboyina@intel.com, lalithambika.krishnakumar@intel.com, chang.seok.bae@intel.com, Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Jonathan Corbet , linux-doc@vger.kernel.org Subject: [PATCH v6 01/12] Documentation/x86: Document Key Locker Date: Mon, 10 Apr 2023 15:59:25 -0700 Message-Id: <20230410225936.8940-2-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230410225936.8940-1-chang.seok.bae@intel.com> References: <20220112211258.21115-1-chang.seok.bae@intel.com> <20230410225936.8940-1-chang.seok.bae@intel.com> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=unavailable 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?1762832818291668582?= X-GMAIL-MSGID: =?utf-8?q?1762832818291668582?= Document the overview of the feature along with relevant consideration when provisioning dm-crypt volumes with AES-KL instead of AES-NI. Signed-off-by: Chang S. Bae Reviewed-by: Dan Williams Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Jonathan Corbet Cc: x86@kernel.org Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- Changes from v5: * Fix a typo: 'feature feature' -> 'feature' Changes from RFC v2: * Add as a new patch. The preview is available here: https://htmlpreview.github.io/?https://github.com/intel-staging/keylocker/kdoc/x86/keylocker.html --- Documentation/x86/index.rst | 1 + Documentation/x86/keylocker.rst | 98 +++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 Documentation/x86/keylocker.rst diff --git a/Documentation/x86/index.rst b/Documentation/x86/index.rst index 8ac64d7de4dc..669c239c009f 100644 --- a/Documentation/x86/index.rst +++ b/Documentation/x86/index.rst @@ -43,3 +43,4 @@ x86-specific Documentation features elf_auxvec xstate + keylocker diff --git a/Documentation/x86/keylocker.rst b/Documentation/x86/keylocker.rst new file mode 100644 index 000000000000..3b405fade7d8 --- /dev/null +++ b/Documentation/x86/keylocker.rst @@ -0,0 +1,98 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============== +x86 Key Locker +============== + +Introduction +============ + +Key Locker is a CPU feature to reduce key exfiltration opportunities +while maintaining a programming interface similar to AES-NI. It +converts the AES key into an encoded form, called the 'key handle'. +The key handle is a wrapped version of the clear-text key where the +wrapping key has limited exposure. Once converted, all subsequent data +encryption using new AES instructions (AES-KL) uses this key handle, +reducing the exposure of private key material in memory. + +Internal Wrapping Key (IWKey) +============================= + +The CPU-internal wrapping key is an entity in a software-invisible CPU +state. On every system boot, a new key is loaded. So the key handle that +was encoded by the old wrapping key is no longer usable on system shutdown +or reboot. + +And the key may be lost on the following exceptional situation upon wakeup: + +IWKey Restore Failure +--------------------- + +The CPU state is volatile with the ACPI S3/4 sleep states. When the system +supports those states, the key has to be backed up so that it is restored +on wake up. The kernel saves the key in non-volatile media. + +The event of an IWKey restore failure upon resume from suspend, all +established key handles become invalid. In flight dm-crypt operations +receive error results from pending operations. In the likely scenario that +dm-crypt is hosting the root filesystem the recovery is identical to if a +storage controller failed to resume from suspend, reboot. If the volume +impacted by an IWKey restore failure is a data-volume then it is possible +that I/O errors on that volume do not bring down the rest of the system. +However, a reboot is still required because the kernel will have +soft-disabled Key Locker. Upon the failure, the crypto library code will +return -ENODEV on every AES-KL function call. The Key Locker implementation +only loads a new IWKey at initial boot, not any time after like resume from +suspend. + +Use Case and Non-use Cases +========================== + +Bare metal disk encryption is the only intended use case. + +Userspace usage is not supported because there is no ABI provided to +communicate and coordinate wrapping-key restore failure to userspace. For +now, key restore failures are only coordinated with kernel users. But the +kernel can not prevent userspace from using the feature's AES instructions +('AES-KL') when the feature has been enabled. So, the lack of userspace +support is only documented, not actively enforced. + +Key Locker is not expected to be advertised to guest VMs and the kernel +implementation ignores it even if the VMM enumerates the capability. The +expectation is that a guest VM wants private IWKey state, but the +architecture does not provide that. An emulation of that capability, by +caching per VM IWKeys in memory, defeats the purpose of Key Locker. The +backup / restore facility is also not performant enough to be suitable for +guest VM context switches. + +AES Instruction Set +=================== + +The feature accompanies a new AES instruction set. This instruction set is +analogous to AES-NI. A set of AES-NI instructions can be mapped to an +AES-KL instruction. For example, AESENC128KL is responsible for ten rounds +of transformation, which is equivalent to nine times AESENC and one +AESENCLAST in AES-NI. + +But they have some notable differences: + +* AES-KL provides a secure data transformation using an encrypted key. + +* If an invalid key handle is provided, e.g. a corrupted one or a handle + restriction failure, the instruction fails with setting RFLAGS.ZF. The + crypto library implementation includes the flag check to return an error + code. Note that the flag is also set when the internal wrapping key is + changed because of missing backup. + +* AES-KL implements support for 128-bit and 256-bit keys, but there is no + AES-KL instruction to process an 192-bit key. But there is no AES-KL + instruction to process a 192-bit key. The AES-KL cipher implementation + logs a warning message with a 192-bit key and then falls back to AES-NI. + So, this 192-bit key-size limitation is only documented, not enforced. It + means the key will remain in clear-text in memory. This is to meet Linux + crypto-cipher expectation that each implementation must support all the + AES-compliant key sizes. + +* Some AES-KL hardware implementation may have noticeable performance + overhead when compared with AES-NI instructions. +