Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3098798pxk; Mon, 5 Oct 2020 00:37:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXyLznwNMdsYVeNklkN4atn5V03ApPjp6eYzB0skyMzaBwXSoX/9HWy4P9F+r4qPLzq04+ X-Received: by 2002:a17:906:934f:: with SMTP id p15mr14673024ejw.497.1601883457418; Mon, 05 Oct 2020 00:37:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601883453; cv=none; d=google.com; s=arc-20160816; b=Z/DD3M4HSf6+FRg1eH9qL2h1AOrEGr8b6l0FEQT/Hz+86JxXSkAtFMsNB4f1SOeeC7 WuozFA9+i1ip1c02uZSMFPACShM0QHZvaJFe418EGjYZoG7PfGKnK3yhwXvQ8iWc3JEk 1rFJPCNoVgjOaRWY+5Vu6YL2oo/neadabx6Y7pv2hHvXTV1ZNXX6pPTopsbp09/kWIrG nyxaaHNpHyWzUlwCLUFlTot9cKBY/uIB3VmnfcNWNwbihpvTryUkmgWDtBNSTScJRu0I xLI20UazBHZI8M+iR8CPklHDQgOXT9cH0fjbYop/vDLuDtfGGu/B6sU6OPHGSxsmT9Z+ gN7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :sender:dkim-signature; bh=bLEC7Itfwt/vTBCBtwVmtMMOr1PQX84du7+WuinK0VQ=; b=ex6lqJsydtRGDj3hAH7bnHjqbgxGkABJswtY2ddVd6mIwtq6VeDlWGfNuF/UcE1Jz9 XbVZqHmXeWB/rZ2gQjb0Tes1FkEedcMmkuqA2/D7deOsI3kOWb2Qc7Pr62iob9gWDW1u 3pYtPeuLjWrcfiPm3dW7ETYfmoXYsm5ZHNQQfZG+EQQKJvN0aggh46hSMmGxL2I3PONZ l3WuoxPn/hU99fsj7xqrZA5A1iFXql771FyLTpdnw4UInCGJ20acghQebTcP9hG48B/i ASwnKsrUmxTVbqDEGtA98VZ39bnRo0WZ8r4VjrcrO0JqMn2bDK7jnUDkU/GRz4E3gk3q YIOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HV6ym01K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si3003705edx.281.2020.10.05.00.37.11; Mon, 05 Oct 2020 00:37:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HV6ym01K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725914AbgJEHgP (ORCPT + 99 others); Mon, 5 Oct 2020 03:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725905AbgJEHgO (ORCPT ); Mon, 5 Oct 2020 03:36:14 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7434DC0613A6 for ; Mon, 5 Oct 2020 00:36:14 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id co16so1667813pjb.1 for ; Mon, 05 Oct 2020 00:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=bLEC7Itfwt/vTBCBtwVmtMMOr1PQX84du7+WuinK0VQ=; b=HV6ym01K6y8BOz1GIxrCnw53fIUAS3awJUA7m9Z3ZlkOp5tuQKJ11SG2ntvCAnJUrm A/LRe4di/5HTVp1kuFcw6lod0tqBwi9AKovXncUB7nRs13Iyv+O7hU9XYUXW5nAEd588 wC0O5FjvB0VbzoCZ/1zL3M+BKnbxKHEEcG6UIyQYU/OR66xiczJXtUw+ey2lvFeiHMjG OoEqBgy6iTVVju+xW9bb7gbqWn2KOxs0Ju7tkzwornb7aQXpHavJw5nB9Fi1FQfCX7IQ 6bLtHS+ZfjPZUimtDeddRxX+PerODtxNYWvz5iPRZiez2yUVGTf31iy/ReL/jqQievKx ++cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=bLEC7Itfwt/vTBCBtwVmtMMOr1PQX84du7+WuinK0VQ=; b=uetjKqM4nJzXObXcuEWmjT40MJUbur+NNgLzj7T4DjBuEDhi0FsXab0vB0yJObuslt mtkiLCurH9Pbo0lhlYyJvRj3fbDejANcPVRe4v9wpjlDbm8N5gRosJ/5jxF76LGYgB76 3ndTCdlfA9rmzvYzXTTzhqGMAMVf7QzcJgn+1BWtB3IhUTKw/8kthBJkvKgux+6/zpXG 0vbtGjMJ3MJ4Izs8y/nCcOzmxVG/7l1DB1ZHZvs93Ru0YQBr/INKHQFAZilcgwL6SKQj EWb/A75Fr+TyUJHE7WCY4bai2DVUJcCUqz37eM+lCkJfKmlvNREWVpryLUkRr3NBa0dX 4yPA== X-Gm-Message-State: AOAM532vc1qxIhTLuC3fl4ZeD31Ji6ehRS1fD5VtQosQ0aG3R0WM+4qG h3nZVX2ycFTq60oWSVdc9MbxPfy4yi4= Sender: "satyat via sendgmr" X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a17:90b:608:: with SMTP id gb8mr2322362pjb.6.1601883373853; Mon, 05 Oct 2020 00:36:13 -0700 (PDT) Date: Mon, 5 Oct 2020 07:36:03 +0000 Message-Id: <20201005073606.1949772-1-satyat@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.806.g8561365e88-goog Subject: [PATCH 0/3] add support for metadata encryption to F2FS From: Satya Tangirala To: "Theodore Y . Ts'o" , Jaegeuk Kim , Eric Biggers , Chao Yu Cc: linux-kernel@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Satya Tangirala Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch series adds support for metadata encryption to F2FS using blk-crypto. Patch 1 replaces fscrypt_get_devices (which took an array of request_queues and filled it up) with fscrypt_get_device, which takes a index of the desired device and returns the device at that index (so the index passed to fscrypt_get_device must be between 0 and (fscrypt_get_num_devices() - 1) inclusive). This allows callers to avoid having to allocate an array to pass to fscrypt_get_devices() when they only need to iterate through each element in the array (and have no use for the array itself). Patch 2 introduces some functions to fscrypt that help filesystems perform metadata encryption. Any filesystem that wants to use metadata encryption can call fscrypt_setup_metadata_encryption() with the super_block of the filesystem, the encryption algorithm and the descriptor of the encryption key. The descriptor is looked up in the logon keyring of the current session with "fscrypt:" as the prefix of the descriptor. The patch also introduces fscrypt_metadata_crypt_bio() which an FS should call on a bio that the FS wants metadata crypted. The function will add an encryption context with the metadata encryption key set up by the call to the above mentioned fscrypt_setup_metadata_encryption(). The patch also introduces fscrypt_metadata_crypt_prepare_all_devices(). Filesystems that use multiple devices should call this function once all the underlying devices have been determined. An FS might only be able to determine all the underlying devices after some initial processing that might already require metadata en/decryption, which is why this function is separate from fscrypt_setup_metadata_encryption(). Patch 3 wires up F2FS with the functions introduced in Patch 2. F2FS will encrypt every block (that's not being encrypted by some other encryption key, e.g. a per-file key) with the metadata encryption key except the superblock (and the redundant copy of the superblock). The DUN of a block is the offset of the block from the start of the F2FS filesystem. Please refer to the commit message for why the superblock was excluded from en/decryption, and other limitations. The superblock and its copy are stored in plaintext on disk. The encryption algorithm used for metadata encryption is stored within the superblock itself. Changes to the userspace tools (that are required to test out metadata encryption with F2FS) are also being sent out - I'll post a link as a reply to this mail once it's out. Satya Tangirala (3): fscrypt, f2fs: replace fscrypt_get_devices with fscrypt_get_device fscrypt: Add metadata encryption support f2fs: Add metadata encryption support Documentation/filesystems/f2fs.rst | 12 ++ fs/crypto/Kconfig | 6 + fs/crypto/Makefile | 1 + fs/crypto/fscrypt_private.h | 19 +++ fs/crypto/inline_crypt.c | 37 +---- fs/crypto/metadata_crypt.c | 220 +++++++++++++++++++++++++++++ fs/f2fs/data.c | 24 ++-- fs/f2fs/f2fs.h | 2 + fs/f2fs/super.c | 83 +++++++++-- include/linux/f2fs_fs.h | 3 +- include/linux/fs.h | 3 + include/linux/fscrypt.h | 51 ++++++- 12 files changed, 410 insertions(+), 51 deletions(-) create mode 100644 fs/crypto/metadata_crypt.c -- 2.28.0.806.g8561365e88-goog