1. 06 1月, 2019 1 次提交
    • E
      fscrypt: add Adiantum support · 8094c3ce
      Eric Biggers 提交于
      Add support for the Adiantum encryption mode to fscrypt.  Adiantum is a
      tweakable, length-preserving encryption mode with security provably
      reducible to that of XChaCha12 and AES-256, subject to a security bound.
      It's also a true wide-block mode, unlike XTS.  See the paper
      "Adiantum: length-preserving encryption for entry-level processors"
      (https://eprint.iacr.org/2018/720.pdf) for more details.  Also see
      commit 059c2a4d ("crypto: adiantum - add Adiantum support").
      
      On sufficiently long messages, Adiantum's bottlenecks are XChaCha12 and
      the NH hash function.  These algorithms are fast even on processors
      without dedicated crypto instructions.  Adiantum makes it feasible to
      enable storage encryption on low-end mobile devices that lack AES
      instructions; currently such devices are unencrypted.  On ARM Cortex-A7,
      on 4096-byte messages Adiantum encryption is about 4 times faster than
      AES-256-XTS encryption; decryption is about 5 times faster.
      
      In fscrypt, Adiantum is suitable for encrypting both file contents and
      names.  With filenames, it fixes a known weakness: when two filenames in
      a directory share a common prefix of >= 16 bytes, with CTS-CBC their
      encrypted filenames share a common prefix too, leaking information.
      Adiantum does not have this problem.
      
      Since Adiantum also accepts long tweaks (IVs), it's also safe to use the
      master key directly for Adiantum encryption rather than deriving
      per-file keys, provided that the per-file nonce is included in the IVs
      and the master key isn't used for any other encryption mode.  This
      configuration saves memory and improves performance.  A new fscrypt
      policy flag is added to allow users to opt-in to this configuration.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      8094c3ce
  2. 04 9月, 2018 1 次提交
  3. 21 5月, 2018 9 次提交
    • E
      fscrypt: log the crypto algorithm implementations · e1cc40e5
      Eric Biggers 提交于
      Log the crypto algorithm driver name for each fscrypt encryption mode on
      its first use, also showing a friendly name for the mode.
      
      This will help people determine whether the expected implementations are
      being used.  In some cases we've seen people do benchmarks and reject
      using encryption for performance reasons, when in fact they used a much
      slower implementation of AES-XTS than was possible on the hardware.  It
      can make an enormous difference; e.g., AES-XTS on ARM is about 10x
      faster with the crypto extensions (AES instructions) than without.
      
      This also makes it more obvious which modes are being used, now that
      fscrypt supports multiple combinations of modes.
      
      Example messages (with default modes, on x86_64):
      
      [   35.492057] fscrypt: AES-256-CTS-CBC using implementation "cts(cbc-aes-aesni)"
      [   35.492171] fscrypt: AES-256-XTS using implementation "xts-aes-aesni"
      
      Note: algorithms can be dynamically added to the crypto API, which can
      result in different implementations being used at different times.  But
      this is rare; for most users, showing the first will be good enough.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      e1cc40e5
    • E
      fscrypt: add Speck128/256 support · 12d28f79
      Eric Biggers 提交于
      fscrypt currently only supports AES encryption.  However, many low-end
      mobile devices have older CPUs that don't have AES instructions, e.g.
      the ARMv8 Cryptography Extensions.  Currently, user data on such devices
      is not encrypted at rest because AES is too slow, even when the NEON
      bit-sliced implementation of AES is used.  Unfortunately, it is
      infeasible to encrypt these devices at all when AES is the only option.
      
      Therefore, this patch updates fscrypt to support the Speck block cipher,
      which was recently added to the crypto API.  The C implementation of
      Speck is not especially fast, but Speck can be implemented very
      efficiently with general-purpose vector instructions, e.g. ARM NEON.
      For example, on an ARMv7 processor, we measured the NEON-accelerated
      Speck128/256-XTS at 69 MB/s for both encryption and decryption, while
      AES-256-XTS with the NEON bit-sliced implementation was only 22 MB/s
      encryption and 19 MB/s decryption.
      
      There are multiple variants of Speck.  This patch only adds support for
      Speck128/256, which is the variant with a 128-bit block size and 256-bit
      key size -- the same as AES-256.  This is believed to be the most secure
      variant of Speck, and it's only about 6% slower than Speck128/128.
      Speck64/128 would be at least 20% faster because it has 20% rounds, and
      it can be even faster on CPUs that can't efficiently do the 64-bit
      operations needed for Speck128.  However, Speck64's 64-bit block size is
      not preferred security-wise.  ARM NEON also supports the needed 64-bit
      operations even on 32-bit CPUs, resulting in Speck128 being fast enough
      for our targeted use cases so far.
      
      The chosen modes of operation are XTS for contents and CTS-CBC for
      filenames.  These are the same modes of operation that fscrypt defaults
      to for AES.  Note that as with the other fscrypt modes, Speck will not
      be used unless userspace chooses to use it.  Nor are any of the existing
      modes (which are all AES-based) being removed, of course.
      
      We intentionally don't make CONFIG_FS_ENCRYPTION select
      CONFIG_CRYPTO_SPECK, so people will have to enable Speck support
      themselves if they need it.  This is because we shouldn't bloat the
      FS_ENCRYPTION dependencies with every new cipher, especially ones that
      aren't recommended for most users.  Moreover, CRYPTO_SPECK is just the
      generic implementation, which won't be fast enough for many users; in
      practice, they'll need to enable CRYPTO_SPECK_NEON to get acceptable
      performance.
      
      More details about our choice of Speck can be found in our patches that
      added Speck to the crypto API, and the follow-on discussion threads.
      We're planning a publication that explains the choice in more detail.
      But briefly, we can't use ChaCha20 as we previously proposed, since it
      would be insecure to use a stream cipher in this context, with potential
      IV reuse during writes on f2fs and/or on wear-leveling flash storage.
      
      We also evaluated many other lightweight and/or ARX-based block ciphers
      such as Chaskey-LTS, RC5, LEA, CHAM, Threefish, RC6, NOEKEON, SPARX, and
      XTEA.  However, all had disadvantages vs. Speck, such as insufficient
      performance with NEON, much less published cryptanalysis, or an
      insufficient security level.  Various design choices in Speck make it
      perform better with NEON than competing ciphers while still having a
      security margin similar to AES, and in the case of Speck128 also the
      same available security levels.  Unfortunately, Speck does have some
      political baggage attached -- it's an NSA designed cipher, and was
      rejected from an ISO standard (though for context, as far as I know none
      of the above-mentioned alternatives are ISO standards either).
      Nevertheless, we believe it is a good solution to the problem from a
      technical perspective.
      
      Certain algorithms constructed from ChaCha or the ChaCha permutation,
      such as MEM (Masked Even-Mansour) or HPolyC, may also meet our
      performance requirements.  However, these are new constructions that
      need more time to receive the cryptographic review and acceptance needed
      to be confident in their security.  HPolyC hasn't been published yet,
      and we are concerned that MEM makes stronger assumptions about the
      underlying permutation than the ChaCha stream cipher does.  In contrast,
      the XTS mode of operation is relatively well accepted, and Speck has
      over 70 cryptanalysis papers.  Of course, these ChaCha-based algorithms
      can still be added later if they become ready.
      
      The best known attack on Speck128/256 is a differential cryptanalysis
      attack on 25 of 34 rounds with 2^253 time complexity and 2^125 chosen
      plaintexts, i.e. only marginally faster than brute force.  There is no
      known attack on the full 34 rounds.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      12d28f79
    • E
      fscrypt: only derive the needed portion of the key · 646b7d4f
      Eric Biggers 提交于
      Currently the key derivation function in fscrypt uses the master key
      length as the amount of output key material to derive.  This works, but
      it means we can waste time deriving more key material than is actually
      used, e.g. most commonly, deriving 64 bytes for directories which only
      take a 32-byte AES-256-CTS-CBC key.  It also forces us to validate that
      the master key length is a multiple of AES_BLOCK_SIZE, which wouldn't
      otherwise be necessary.
      
      Fix it to only derive the needed length key.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      646b7d4f
    • E
      fscrypt: separate key lookup from key derivation · 590f497d
      Eric Biggers 提交于
      Refactor the confusingly-named function 'validate_user_key()' into a new
      function 'find_and_derive_key()' which first finds the keyring key, then
      does the key derivation.  Among other benefits this avoids the strange
      behavior we had previously where if key derivation failed for some
      reason, then we would fall back to the alternate key prefix.  Now, we'll
      only fall back to the alternate key prefix if a valid key isn't found.
      
      This patch also improves the warning messages that are logged when the
      keyring key's payload is invalid.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      590f497d
    • E
      fscrypt: use a common logging function · 544d08fd
      Eric Biggers 提交于
      Use a common function for fscrypt warning and error messages so that all
      the messages are consistently ratelimited, include the "fscrypt:"
      prefix, and include the filesystem name if applicable.
      
      Also fix up a few of the log messages to be more descriptive.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      544d08fd
    • E
      fscrypt: remove internal key size constants · 11b8818e
      Eric Biggers 提交于
      With one exception, the internal key size constants such as
      FS_AES_256_XTS_KEY_SIZE are only used for the 'available_modes' array,
      where they really only serve to obfuscate what the values are.  Also
      some of the constants are unused, and the key sizes tend to be in the
      names of the algorithms anyway.  In the past these values were also
      misused, e.g. we used to have FS_AES_256_XTS_KEY_SIZE in places that
      technically should have been FS_MAX_KEY_SIZE.
      
      The exception is that FS_AES_128_ECB_KEY_SIZE is used for key
      derivation.  But it's more appropriate to use
      FS_KEY_DERIVATION_NONCE_SIZE for that instead.
      
      Thus, just put the sizes directly in the 'available_modes' array.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      11b8818e
    • E
      fscrypt: remove unnecessary check for non-logon key type · 1086c80c
      Eric Biggers 提交于
      We're passing 'key_type_logon' to request_key(), so the found key is
      guaranteed to be of type "logon".  Thus, there is no reason to check
      later that the key is really a "logon" key.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      1086c80c
    • E
      fscrypt: don't clear flags on crypto transform · 101c97a3
      Eric Biggers 提交于
      fscrypt is clearing the flags on the crypto_skcipher it allocates for
      each inode.  But, this is unnecessary and may cause problems in the
      future because it will even clear flags that are meant to be internal to
      the crypto API, e.g. CRYPTO_TFM_NEED_KEY.
      
      Remove the unnecessary flag clearing.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      101c97a3
    • E
      fscrypt: remove unnecessary NULL check when allocating skcipher · 9919479b
      Eric Biggers 提交于
      crypto_alloc_skcipher() returns an ERR_PTR() on failure, not NULL.
      Remove the unnecessary check for NULL.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      9919479b
  4. 12 1月, 2018 2 次提交
  5. 03 11月, 2017 1 次提交
  6. 02 11月, 2017 1 次提交
    • G
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman 提交于
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard license headers were used, and references to license
      had to be inferred by heuristics based on keywords.
      
      The analysis to determine which SPDX License Identifier to be applied to
      a file was done in a spreadsheet of side by side results from of the
      output of two independent scanners (ScanCode & Windriver) producing SPDX
      tag:value files created by Philippe Ombredanne.  Philippe prepared the
      base worksheet, and did an initial spot review of a few 1000 files.
      
      The 4.13 kernel was the starting point of the analysis with 60,537 files
      assessed.  Kate Stewart did a file by file comparison of the scanner
      results in the spreadsheet to determine which SPDX license identifier(s)
      to be applied to the file. She confirmed any determination that was not
      immediately clear with lawyers working with the Linux Foundation.
      
      Criteria used to select files for SPDX license identifier tagging was:
       - Files considered eligible had to be source code files.
       - Make and config files were included as candidates if they contained >5
         lines of source
       - File already had some variant of a license header in it (even if <5
         lines).
      
      All documentation files were explicitly excluded.
      
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
      
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
      
         For non */uapi/* files that summary was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0                                              11139
      
         and resulted in the first patch in this series.
      
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0 WITH Linux-syscall-note                        930
      
         and resulted in the second patch in this series.
      
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|------
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
      
         and that resulted in the third patch in this series.
      
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
      
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
      
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
      
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
      
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      Reviewed-by: NKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: NPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2441318
  7. 25 10月, 2017 1 次提交
    • M
      locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns... · 6aa7de05
      Mark Rutland 提交于
      locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()
      
      Please do not apply this to mainline directly, instead please re-run the
      coccinelle script shown below and apply its output.
      
      For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
      preference to ACCESS_ONCE(), and new code is expected to use one of the
      former. So far, there's been no reason to change most existing uses of
      ACCESS_ONCE(), as these aren't harmful, and changing them results in
      churn.
      
      However, for some features, the read/write distinction is critical to
      correct operation. To distinguish these cases, separate read/write
      accessors must be used. This patch migrates (most) remaining
      ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
      coccinelle script:
      
      ----
      // Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
      // WRITE_ONCE()
      
      // $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch
      
      virtual patch
      
      @ depends on patch @
      expression E1, E2;
      @@
      
      - ACCESS_ONCE(E1) = E2
      + WRITE_ONCE(E1, E2)
      
      @ depends on patch @
      expression E;
      @@
      
      - ACCESS_ONCE(E)
      + READ_ONCE(E)
      ----
      Signed-off-by: NMark Rutland <mark.rutland@arm.com>
      Signed-off-by: NPaul E. McKenney <paulmck@linux.vnet.ibm.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: davem@davemloft.net
      Cc: linux-arch@vger.kernel.org
      Cc: mpe@ellerman.id.au
      Cc: shuah@kernel.org
      Cc: snitzer@redhat.com
      Cc: thor.thayer@linux.intel.com
      Cc: tj@kernel.org
      Cc: viro@zeniv.linux.org.uk
      Cc: will.deacon@arm.com
      Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      6aa7de05
  8. 19 10月, 2017 1 次提交
  9. 13 10月, 2017 1 次提交
  10. 24 6月, 2017 1 次提交
    • D
      fscrypt: add support for AES-128-CBC · b7e7cf7a
      Daniel Walter 提交于
      fscrypt provides facilities to use different encryption algorithms which
      are selectable by userspace when setting the encryption policy. Currently,
      only AES-256-XTS for file contents and AES-256-CBC-CTS for file names are
      implemented. This is a clear case of kernel offers the mechanism and
      userspace selects a policy. Similar to what dm-crypt and ecryptfs have.
      
      This patch adds support for using AES-128-CBC for file contents and
      AES-128-CBC-CTS for file name encryption. To mitigate watermarking
      attacks, IVs are generated using the ESSIV algorithm. While AES-CBC is
      actually slightly less secure than AES-XTS from a security point of view,
      there is more widespread hardware support. Using AES-CBC gives us the
      acceptable performance while still providing a moderate level of security
      for persistent storage.
      
      Especially low-powered embedded devices with crypto accelerators such as
      CAAM or CESA often only support AES-CBC. Since using AES-CBC over AES-XTS
      is basically thought of a last resort, we use AES-128-CBC over AES-256-CBC
      since it has less encryption rounds and yields noticeable better
      performance starting from a file size of just a few kB.
      Signed-off-by: NDaniel Walter <dwalter@sigma-star.at>
      [david@sigma-star.at: addressed review comments]
      Signed-off-by: NDavid Gstir <david@sigma-star.at>
      Reviewed-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      b7e7cf7a
  11. 30 4月, 2017 1 次提交
  12. 16 3月, 2017 1 次提交
    • E
      fscrypt: remove broken support for detecting keyring key revocation · 1b53cf98
      Eric Biggers 提交于
      Filesystem encryption ostensibly supported revoking a keyring key that
      had been used to "unlock" encrypted files, causing those files to become
      "locked" again.  This was, however, buggy for several reasons, the most
      severe of which was that when key revocation happened to be detected for
      an inode, its fscrypt_info was immediately freed, even while other
      threads could be using it for encryption or decryption concurrently.
      This could be exploited to crash the kernel or worse.
      
      This patch fixes the use-after-free by removing the code which detects
      the keyring key having been revoked, invalidated, or expired.  Instead,
      an encrypted inode that is "unlocked" now simply remains unlocked until
      it is evicted from memory.  Note that this is no worse than the case for
      block device-level encryption, e.g. dm-crypt, and it still remains
      possible for a privileged user to evict unused pages, inodes, and
      dentries by running 'sync; echo 3 > /proc/sys/vm/drop_caches', or by
      simply unmounting the filesystem.  In fact, one of those actions was
      already needed anyway for key revocation to work even somewhat sanely.
      This change is not expected to break any applications.
      
      In the future I'd like to implement a real API for fscrypt key
      revocation that interacts sanely with ongoing filesystem operations ---
      waiting for existing operations to complete and blocking new operations,
      and invalidating and sanitizing key material and plaintext from the VFS
      caches.  But this is a hard problem, and for now this bug must be fixed.
      
      This bug affected almost all versions of ext4, f2fs, and ubifs
      encryption, and it was potentially reachable in any kernel configured
      with encryption support (CONFIG_EXT4_ENCRYPTION=y,
      CONFIG_EXT4_FS_ENCRYPTION=y, CONFIG_F2FS_FS_ENCRYPTION=y, or
      CONFIG_UBIFS_FS_ENCRYPTION=y).  Note that older kernels did not use the
      shared fs/crypto/ code, but due to the potential security implications
      of this bug, it may still be worthwhile to backport this fix to them.
      
      Fixes: b7236e21 ("ext4 crypto: reorganize how we store keys in the inode")
      Cc: stable@vger.kernel.org # v4.2+
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      Acked-by: NMichael Halcrow <mhalcrow@google.com>
      1b53cf98
  13. 02 3月, 2017 1 次提交
    • D
      KEYS: Differentiate uses of rcu_dereference_key() and user_key_payload() · 0837e49a
      David Howells 提交于
      rcu_dereference_key() and user_key_payload() are currently being used in
      two different, incompatible ways:
      
       (1) As a wrapper to rcu_dereference() - when only the RCU read lock used
           to protect the key.
      
       (2) As a wrapper to rcu_dereference_protected() - when the key semaphor is
           used to protect the key and the may be being modified.
      
      Fix this by splitting both of the key wrappers to produce:
      
       (1) RCU accessors for keys when caller has the key semaphore locked:
      
      	dereference_key_locked()
      	user_key_payload_locked()
      
       (2) RCU accessors for keys when caller holds the RCU read lock:
      
      	dereference_key_rcu()
      	user_key_payload_rcu()
      
      This should fix following warning in the NFS idmapper
      
        ===============================
        [ INFO: suspicious RCU usage. ]
        4.10.0 #1 Tainted: G        W
        -------------------------------
        ./include/keys/user-type.h:53 suspicious rcu_dereference_protected() usage!
        other info that might help us debug this:
        rcu_scheduler_active = 2, debug_locks = 0
        1 lock held by mount.nfs/5987:
          #0:  (rcu_read_lock){......}, at: [<d000000002527abc>] nfs_idmap_get_key+0x15c/0x420 [nfsv4]
        stack backtrace:
        CPU: 1 PID: 5987 Comm: mount.nfs Tainted: G        W       4.10.0 #1
        Call Trace:
          dump_stack+0xe8/0x154 (unreliable)
          lockdep_rcu_suspicious+0x140/0x190
          nfs_idmap_get_key+0x380/0x420 [nfsv4]
          nfs_map_name_to_uid+0x2a0/0x3b0 [nfsv4]
          decode_getfattr_attrs+0xfac/0x16b0 [nfsv4]
          decode_getfattr_generic.constprop.106+0xbc/0x150 [nfsv4]
          nfs4_xdr_dec_lookup_root+0xac/0xb0 [nfsv4]
          rpcauth_unwrap_resp+0xe8/0x140 [sunrpc]
          call_decode+0x29c/0x910 [sunrpc]
          __rpc_execute+0x140/0x8f0 [sunrpc]
          rpc_run_task+0x170/0x200 [sunrpc]
          nfs4_call_sync_sequence+0x68/0xa0 [nfsv4]
          _nfs4_lookup_root.isra.44+0xd0/0xf0 [nfsv4]
          nfs4_lookup_root+0xe0/0x350 [nfsv4]
          nfs4_lookup_root_sec+0x70/0xa0 [nfsv4]
          nfs4_find_root_sec+0xc4/0x100 [nfsv4]
          nfs4_proc_get_rootfh+0x5c/0xf0 [nfsv4]
          nfs4_get_rootfh+0x6c/0x190 [nfsv4]
          nfs4_server_common_setup+0xc4/0x260 [nfsv4]
          nfs4_create_server+0x278/0x3c0 [nfsv4]
          nfs4_remote_mount+0x50/0xb0 [nfsv4]
          mount_fs+0x74/0x210
          vfs_kern_mount+0x78/0x220
          nfs_do_root_mount+0xb0/0x140 [nfsv4]
          nfs4_try_mount+0x60/0x100 [nfsv4]
          nfs_fs_mount+0x5ec/0xda0 [nfs]
          mount_fs+0x74/0x210
          vfs_kern_mount+0x78/0x220
          do_mount+0x254/0xf70
          SyS_mount+0x94/0x100
          system_call+0x38/0xe0
      Reported-by: NJan Stancek <jstancek@redhat.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Tested-by: NJan Stancek <jstancek@redhat.com>
      Signed-off-by: NJames Morris <james.l.morris@oracle.com>
      0837e49a
  14. 07 2月, 2017 1 次提交
  15. 08 1月, 2017 1 次提交
  16. 03 1月, 2017 1 次提交
    • T
      fscrypt: make test_dummy_encryption require a keyring key · 5bbdcbbb
      Theodore Ts'o 提交于
      Currently, the test_dummy_encryption ext4 mount option, which exists
      only to test encrypted I/O paths with xfstests, overrides all
      per-inode encryption keys with a fixed key.
      
      This change minimizes test_dummy_encryption-specific code path changes
      by supplying a fake context for directories which are not encrypted
      for use when creating new directories, files, or symlinks.  This
      allows us to properly exercise the keyring lookup, derivation, and
      context inheritance code paths.
      
      Before mounting a file system using test_dummy_encryption, userspace
      must execute the following shell commands:
      
          mode='\x00\x00\x00\x00'
          raw="$(printf ""\\\\x%02x"" $(seq 0 63))"
          if lscpu | grep "Byte Order" | grep -q Little ; then
              size='\x40\x00\x00\x00'
          else
              size='\x00\x00\x00\x40'
          fi
          key="${mode}${raw}${size}"
          keyctl new_session
          echo -n -e "${key}" | keyctl padd logon fscrypt:4242424242424242 @s
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      5bbdcbbb
  17. 28 12月, 2016 1 次提交
    • T
      fscrypt: fix the test_dummy_encryption mount option · fe4f6c80
      Theodore Ts'o 提交于
      Commit f1c131b4: "crypto: xts - Convert to skcipher" now fails
      the setkey operation if the AES key is the same as the tweak key.
      Previously this check was only done if FIPS mode is enabled.  Now this
      check is also done if weak key checking was requested.  This is
      reasonable, but since we were using the dummy key which was a constant
      series of 0x42 bytes, it now caused dummy encrpyption test mode to
      fail.
      
      Fix this by using 0x42... and 0x24... for the two keys, so they are
      different.
      
      Fixes: f1c131b4
      Cc: stable@vger.kernel.org
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      fe4f6c80
  18. 12 12月, 2016 2 次提交
  19. 20 11月, 2016 1 次提交
    • E
      fscrypto: don't use on-stack buffer for key derivation · 0f0909e2
      Eric Biggers 提交于
      With the new (in 4.9) option to use a virtually-mapped stack
      (CONFIG_VMAP_STACK), stack buffers cannot be used as input/output for
      the scatterlist crypto API because they may not be directly mappable to
      struct page.  get_crypt_info() was using a stack buffer to hold the
      output from the encryption operation used to derive the per-file key.
      Fix it by using a heap buffer.
      
      This bug could most easily be observed in a CONFIG_DEBUG_SG kernel
      because this allowed the BUG in sg_set_buf() to be triggered.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      0f0909e2
  20. 14 11月, 2016 1 次提交
    • E
      fscrypto: don't use on-stack buffer for key derivation · a6e08912
      Eric Biggers 提交于
      With the new (in 4.9) option to use a virtually-mapped stack
      (CONFIG_VMAP_STACK), stack buffers cannot be used as input/output for
      the scatterlist crypto API because they may not be directly mappable to
      struct page.  get_crypt_info() was using a stack buffer to hold the
      output from the encryption operation used to derive the per-file key.
      Fix it by using a heap buffer.
      
      This bug could most easily be observed in a CONFIG_DEBUG_SG kernel
      because this allowed the BUG in sg_set_buf() to be triggered.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      a6e08912
  21. 16 9月, 2016 2 次提交
  22. 08 5月, 2016 1 次提交
    • J
      fscrypto/f2fs: allow fs-specific key prefix for fs encryption · b5a7aef1
      Jaegeuk Kim 提交于
      This patch allows fscrypto to handle a second key prefix given by filesystem.
      The main reason is to provide backward compatibility, since previously f2fs
      used "f2fs:" as a crypto prefix instead of "fscrypt:".
      Later, ext4 should also provide key_prefix() to give "ext4:".
      
      One concern decribed by Ted would be kinda double check overhead of prefixes.
      In x86, for example, validate_user_key consumes 8 ms after boot-up, which turns
      out derive_key_aes() consumed most of the time to load specific crypto module.
      After such the cold miss, it shows almost zero latencies, which treats as a
      negligible overhead.
      Note that request_key() detects wrong prefix in prior to derive_key_aes() even.
      
      Cc: Ted Tso <tytso@mit.edu>
      Cc: stable@vger.kernel.org # v4.6
      Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
      b5a7aef1
  23. 18 3月, 2016 1 次提交
    • J
      fs crypto: move per-file encryption from f2fs tree to fs/crypto · 0b81d077
      Jaegeuk Kim 提交于
      This patch adds the renamed functions moved from the f2fs crypto files.
      
      1. definitions for per-file encryption used by ext4 and f2fs.
      
      2. crypto.c for encrypt/decrypt functions
       a. IO preparation:
        - fscrypt_get_ctx / fscrypt_release_ctx
       b. before IOs:
        - fscrypt_encrypt_page
        - fscrypt_decrypt_page
        - fscrypt_zeroout_range
       c. after IOs:
        - fscrypt_decrypt_bio_pages
        - fscrypt_pullback_bio_page
        - fscrypt_restore_control_page
      
      3. policy.c supporting context management.
       a. For ioctls:
        - fscrypt_process_policy
        - fscrypt_get_policy
       b. For context permission
        - fscrypt_has_permitted_context
        - fscrypt_inherit_context
      
      4. keyinfo.c to handle permissions
        - fscrypt_get_encryption_info
        - fscrypt_free_encryption_info
      
      5. fname.c to support filename encryption
       a. general wrapper functions
        - fscrypt_fname_disk_to_usr
        - fscrypt_fname_usr_to_disk
        - fscrypt_setup_filename
        - fscrypt_free_filename
      
       b. specific filename handling functions
        - fscrypt_fname_alloc_buffer
        - fscrypt_fname_free_buffer
      
      6. Makefile and Kconfig
      
      Cc: Al Viro <viro@ftp.linux.org.uk>
      Signed-off-by: NMichael Halcrow <mhalcrow@google.com>
      Signed-off-by: NIldar Muslukhov <ildarm@google.com>
      Signed-off-by: NUday Savagaonkar <savagaon@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
      0b81d077
  24. 23 2月, 2016 3 次提交
  25. 27 1月, 2016 1 次提交
  26. 21 10月, 2015 1 次提交
    • D
      KEYS: Merge the type-specific data with the payload data · 146aa8b1
      David Howells 提交于
      Merge the type-specific data with the payload data into one four-word chunk
      as it seems pointless to keep them separate.
      
      Use user_key_payload() for accessing the payloads of overloaded
      user-defined keys.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      cc: linux-cifs@vger.kernel.org
      cc: ecryptfs@vger.kernel.org
      cc: linux-ext4@vger.kernel.org
      cc: linux-f2fs-devel@lists.sourceforge.net
      cc: linux-nfs@vger.kernel.org
      cc: ceph-devel@vger.kernel.org
      cc: linux-ima-devel@lists.sourceforge.net
      146aa8b1
  27. 05 8月, 2015 1 次提交