From patchwork Wed Jan 17 14:13:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 10169355 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 52948603ED for ; Wed, 17 Jan 2018 14:14:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40255285A0 for ; Wed, 17 Jan 2018 14:14:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32CEF285A6; Wed, 17 Jan 2018 14:14:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A3BE285A0 for ; Wed, 17 Jan 2018 14:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753333AbeAQOOV (ORCPT ); Wed, 17 Jan 2018 09:14:21 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:44141 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753212AbeAQOOI (ORCPT ); Wed, 17 Jan 2018 09:14:08 -0500 Received: by mail-wm0-f68.google.com with SMTP id t74so15606839wme.3; Wed, 17 Jan 2018 06:14:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EgOtJI7D75W0HXF94zLs4nd80Tzii/dIKwZ9BmwGpMs=; b=PoOgERfoZXJWD6rwg53PKIbYBrGChDJ7djKqcqA0MEvwOOcSRu4n/pyTVk9TdFJKYx ttjSu7pttEj9iajnGKkYATid6AAYcAttFJDrdNJAJ/iRZBwkT35EV0D5bzqJbJIgSHly Y9r2SawYSRs/coG6UYdTfGe+xfdN5W746wt44Mmhfj/4aEDkYEwQW19VuHZPWGbGv2nP J+Q+lD8Po71lLrNP83/qKz5CKUbbT3LVwpOpRaorYTYrqCQ+wA0o4aQDN/W7GSU1Vwc+ UY1kZe/ncrEZHR2rb0CVeEvQki91ZnQvxdHQrjr97gjaY3u931/RXLXOWL4Y5Bn2vt6T oR7A== X-Gm-Message-State: AKwxyteiC3bNtx+xD2geHXv8s94SbUq5j+QhuHQq72BhQPA8zazqd3Do 1EtAjn6X2V3VVO63e2ngyLnse63Rieg= X-Google-Smtp-Source: ACJfBouXxJS75l3tghRPCyJ5bGn0/5gqk7ZP/U75etLGOxeG/alCdZOlB9KuSeuAifoD3VWd+uoE+g== X-Received: by 10.80.134.44 with SMTP id o41mr3062489edo.243.1516198446126; Wed, 17 Jan 2018 06:14:06 -0800 (PST) Received: from tfsielt31850.tycofs.com ([77.107.218.170]) by smtp.gmail.com with ESMTPSA id b30sm3490416ede.53.2018.01.17.06.14.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 06:14:05 -0800 (PST) From: =?UTF-8?q?Andr=C3=A9=20Draszik?= To: linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Andr=C3=A9=20Draszik?= , "Theodore Y. Ts'o" , Jaegeuk Kim , Jonathan Corbet , linux-fscrypt@vger.kernel.org, Eric Biggers , linux-doc@vger.kernel.org Subject: [PATCH v2 2/2] fscrypt: update documentation for encrypted key support Date: Wed, 17 Jan 2018 14:13:19 +0000 Message-Id: <20180117141319.8060-2-git@andred.net> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180117141319.8060-1-git@andred.net> References: <20180111040022.GA943@zzz.localdomain> <20180117141319.8060-1-git@andred.net> MIME-Version: 1.0 Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: André Draszik Cc: "Theodore Y. Ts'o" Cc: Jaegeuk Kim Cc: Jonathan Corbet Cc: linux-fscrypt@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Eric Biggers Cc: linux-doc@vger.kernel.org --- Documentation/filesystems/fscrypt.rst | 56 +++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/Documentation/filesystems/fscrypt.rst b/Documentation/filesystems/fscrypt.rst index 776ddc655f79..852ac2900b66 100644 --- a/Documentation/filesystems/fscrypt.rst +++ b/Documentation/filesystems/fscrypt.rst @@ -368,11 +368,19 @@ Adding keys To provide a master key, userspace must add it to an appropriate keyring using the add_key() system call (see: ``Documentation/security/keys/core.rst``). The key type must be -"logon"; keys of this type are kept in kernel memory and cannot be -read back by userspace. The key description must be "fscrypt:" -followed by the 16-character lower case hex representation of the -``master_key_descriptor`` that was set in the encryption policy. The -key payload must conform to the following structure:: +either "logon" or "encrypted"; "logon" keys are kept in kernel +memory and cannot be read back by userspace while "encrypted" +keys can be rooted in a "trusted" key and thus are protected by +a TPM and cannot be read by userspace in unencrypted form. Note +that while an "encrypted" key can also be rooted in a "user" key, +any "encrypted" key rooted in a "user" key can effectively be +retrieved in the clear, hence only rooting the key in a "trusted" +key has any useful security properties! + +The key description must be "fscrypt:" followed by the 16-character +lower case hex representation of the ``master_key_descriptor`` that +was set in the encryption policy. For a "logon" key, key payload +must conform to the following structure:: #define FS_MAX_KEY_SIZE 64 @@ -386,6 +394,17 @@ key payload must conform to the following structure:: ``raw`` with ``size`` indicating its size in bytes. That is, the bytes ``raw[0..size-1]`` (inclusive) are the actual key. +When using an "encrypted" key, only the actual ``raw`` key from above +fscrypt_key structure is needed:: + + keyctl add encrypted "fscrypt:``master_key_descriptor``" "new default trusted:``master-key-name`` ``size``" ``ring`` + keyctl add encrypted "fscrypt:``master_key_descriptor``" "load ``hex_blob``" ``ring`` + +Where:: + + master-key-name:= name of the trusted key this fscrypt master key + shall be rooted in + The key description prefix "fscrypt:" may alternatively be replaced with a filesystem-specific prefix such as "ext4:". However, the filesystem-specific prefixes are deprecated and should not be used in @@ -412,6 +431,33 @@ evicted. In the future there probably should be a way to provide keys directly to the filesystem instead, which would make the intended semantics clearer. +Complete Examples +------------------ + +Set fscrypt policy on an (empty) encrypted directory, /encrypted:: + + $ fscryptctl set_policy 1234567890123456 /encrypted + +Create an encrypted key "1234567890123456" of length 64 bytes with format +'fscrypt' and root it in a previously loaded trusted "kmk":: + + $ keyctl add encrypted "fscrypt:1234567890123456" "new default trusted:kmk 64" @u + 839715473 + + $ keyctl print 839715473 + default trusted:kmk 64 e98a49dc11eb9312f46530879aac869300ee734035100f4ee + 5441279369a4c9d83d6e59b8158d0a3de01790c0bb99af82e9603cb6977c7d1229338cda + 80375aaf034678405a00c19806d6fb12490e39b1d7ca603c491b58a962345160e344ae51 + 83483e066692d05f5ab3d8b9ea39cab0e + + $ keyctl pipe 839715473 > fscrypt.blob + +The directory policy will remain across reboots, so after a reboot the key +generated earlier will simply have to be loaded into the kernel keyring +again:: + + $ keyctl add encrypted fscrypt:1234567890123456 "load $(cat fscrypt.blob)" @u + Access semantics ================