Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp9528021ybl; Fri, 17 Jan 2020 13:43:07 -0800 (PST) X-Google-Smtp-Source: APXvYqyTLclStBtIKagi3inZjVlPDR1DrhTiadFyKQAX9Tnygi9tJ8nVu1F4zvQppDU99WNi/oHy X-Received: by 2002:aca:4ad5:: with SMTP id x204mr4916518oia.162.1579297387447; Fri, 17 Jan 2020 13:43:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579297387; cv=none; d=google.com; s=arc-20160816; b=ZoaJpqxRA1XvRbsnOXDLCJ+PvjQwJFrIW1EtsONzr3wHqPXlYoO/zur6oSLU5Wsz7C nCI0r4Ki1dWmmfdyZsBx06gPv8j9xtIx98j60VBmsCDtEDxRYPE8b900g2wQ5c3ObSIi 3ppQbjNgmxFQ3/eZC4+XPIaa6HOIWwbKgNz+zk3ZzBrbxahoSQX5t4Y5DtegQVBYXGiR TgobywhM/WTb2itoPqsbpEp+L550breo7Oljl4wfQzkiOTIcrncDiokUyghgBR6Zjjk6 mqYrNkHturZY3jMSY2OP3YQ/2rbWcRebs8HRVZVOkLmO1P6y0JLHPUCHGWQ8CTLnWlZe eYhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=yBEf4c2Y/V+ZNwnYQzLFCcZKpZySQQ5dJ9X0QGzY9eo=; b=uXYTuluLx2TsJCaoXiO+XtarpcZ7ZaBKTQNIT+hvmGQhnldbn1uOwYdr3EQelmDEoo 08jqz73rQKXNNWl31ZeRALBuBJTtB4uCzCQGhf3zhn4Z07QnyYo0t76fXxB9ajfPckf7 gYfiadHTWHlkeGYb6vQuCEY+w9BGTA4xUM4nNv6akealtETIr+pJG7ikhVtAmSiawykv BBkkSh2icpx2mRfSgUDchgUPgADr/2vx0o1saWqMchNGIKlVu4vyIz+FuYbWIJLAJhAc cF0oATjTTLsW2MepgiUovx/QyF6pMnXNyjCrulTze6XoQeoWTaSW5cVqC3N+1x4hjTCC a51Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hrp+gp+g; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-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. [209.132.180.67]) by mx.google.com with ESMTP id d2si14823273oth.267.2020.01.17.13.42.56; Fri, 17 Jan 2020 13:43:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hrp+gp+g; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-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 S1728778AbgAQVmz (ORCPT + 99 others); Fri, 17 Jan 2020 16:42:55 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:50974 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726752AbgAQVmz (ORCPT ); Fri, 17 Jan 2020 16:42:55 -0500 Received: by mail-pl1-f202.google.com with SMTP id g5so8061018plq.17 for ; Fri, 17 Jan 2020 13:42:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=yBEf4c2Y/V+ZNwnYQzLFCcZKpZySQQ5dJ9X0QGzY9eo=; b=hrp+gp+g8aB/jpumGkpuc5F5wkzC/eegSUgKsuaP5vuBUKLF33qoqqM2MafIuVh9s1 jI2A1GYFMvU+zXn/tCLnmGXTqm3p0Gd4ZJGvWkGqgwBJx9K3w5rosKRTKFkLyeVpf7r7 WFGq/cvvGa0UIt89Z8qEnh4tUigSQ7k5T7oowlnUjWNYSj1q2cLitkSLMyMd0jkKCkAD anxNB8ZROhRvpyrX/Yj82zl81n9GScBR9YTXGVMqHu3OoPibEEExYkK8+hQXWp7bAWgy 5hmPB7B0i/vXCHN1gPjV6lJhuK5oImOVpW8qPq4w+BW8SnU9RkZI5NRwJt35MaEoucrI kOSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=yBEf4c2Y/V+ZNwnYQzLFCcZKpZySQQ5dJ9X0QGzY9eo=; b=iQAPHkNeWTiW8DSK5jt0Yks6L0ciCi3LYLtasGojg+eEN/6oqH5+Cozlfyu2IqQada Hc3/gb65CzhFoXMOc7BnmT70Fjg0rIdRqaEdCIKqSEjH4+fSQ6Ty/ify6IE71uNzNi1A 8dnh2ciYoFEGEi09RowHcY/Ra3G2r9d9hqzw2DzEXVNd24/fmzwRuH1BY3XzVH7TfC/w l3T8wCflGMjilqVegXUzxpkc+DFOSQt6++khKrqrbdjBuF1Fb09cVkp5eS2fE3ziRl7n cYDV8p9k+SeOXH1j6fcxiX/mujWiTPJ5V/ezYVS6VlWFxryq616WpY2tSf25OCKON6Ms w/nQ== X-Gm-Message-State: APjAAAU6S7hhIXWG7YTRvDZ0bs1DmZWWy+3KfTG7IBB7y1MExh8ntCjN UE37xEPz4AogwxzqSeQXyqvyL1fdn+M= X-Received: by 2002:a63:ff20:: with SMTP id k32mr45963088pgi.448.1579297374588; Fri, 17 Jan 2020 13:42:54 -0800 (PST) Date: Fri, 17 Jan 2020 13:42:37 -0800 Message-Id: <20200117214246.235591-1-drosen@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v3 0/9] Support for Casefolding and Encryption From: Daniel Rosenberg To: "Theodore Ts'o" , linux-ext4@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, Eric Biggers , linux-fscrypt@vger.kernel.org, Alexander Viro Cc: Andreas Dilger , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi , kernel-team@android.com, Daniel Rosenberg Content-Type: text/plain; charset="UTF-8" Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org These patches are all on top of fscrypt's developement branch Ext4 and F2FS currently both support casefolding and encryption, but not at the same time. These patches aim to rectify that. Since directory names are stored case preserved, we cannot just take the hash of the ciphertext. Instead we use the siphash of the casefolded name. With this we no longer have a direct path from an encrypted name to the hash without the key. To deal with this, fscrypt now always includes the hash in the name it presents when the key is not present. There is a pre-existing bug where you can change parts of the hash and still match the name so long as the disruption to the hash does not happen to affect lookup on that filesystem. I'm not sure how to fix that without making ext4 lookups slower in the more common case. I moved the identical dcache operations for ext4 and f2fs into the VFS, as any filesystem that uses casefolding will need the same code. This will also allow further optimizations to that path, although my current changes don't take advantage of that yet. For Ext4, this also means that we need to store the hash on disk. We only do so for encrypted and casefolded directories to avoid on disk format changes. Previously encryption and casefolding could not live on the same filesystem, and we're relaxing that requirement. F2fs is a bit more straightforward since it already stores hashes on disk. I've updated the related tools with just enough to enable the feature. I still need to adjust ext4's fsck's, although without access to the keys, neither fsck will be able to verify the hashes of casefolded and encrypted names. v3 changes: fscrypt patch only creates hash key if it will be needed. Rebased on top of fscrypt branch, reconstified match functions in ext4/f2fs v2 changes: fscrypt moved to separate thread to rebase on fscrypt dev branch addressed feedback, plus some minor fixes Daniel Rosenberg (9): fscrypt: Add siphash and hash key for policy v2 fscrypt: Don't allow v1 policies with casefolding fscrypt: Change format of no-key token fscrypt: Only create hash key when needed vfs: Fold casefolding into vfs f2fs: Handle casefolding with Encryption ext4: Use struct super_blocks' casefold data ext4: Hande casefolding with encryption ext4: Optimize match for casefolded encrypted dirs Documentation/filesystems/ext4/directory.rst | 27 ++ fs/crypto/Kconfig | 1 + fs/crypto/fname.c | 232 ++++++++++--- fs/crypto/fscrypt_private.h | 9 + fs/crypto/keysetup.c | 35 +- fs/crypto/policy.c | 53 +++ fs/dcache.c | 28 ++ fs/ext4/dir.c | 75 +---- fs/ext4/ext4.h | 85 +++-- fs/ext4/hash.c | 26 +- fs/ext4/ialloc.c | 5 +- fs/ext4/inline.c | 41 +-- fs/ext4/namei.c | 324 ++++++++++++------- fs/ext4/super.c | 21 +- fs/f2fs/dir.c | 112 +++---- fs/f2fs/f2fs.h | 12 +- fs/f2fs/hash.c | 25 +- fs/f2fs/inline.c | 9 +- fs/f2fs/super.c | 17 +- fs/f2fs/sysfs.c | 8 +- fs/inode.c | 3 +- fs/namei.c | 41 ++- include/linux/fs.h | 10 + include/linux/fscrypt.h | 95 ++---- include/linux/unicode.h | 14 + 25 files changed, 835 insertions(+), 473 deletions(-) -- 2.25.0.341.g760bfbb309-goog