Skip to content
Snippets Groups Projects
  1. Aug 09, 2017
  2. Jul 07, 2017
  3. Feb 22, 2017
    • Daniel Rosenberg's avatar
      ANDROID: sdcardfs: Don't bother deleting freelist · 880c68e4
      Daniel Rosenberg authored
      
      There is no point deleting entries from dlist, as
      that is a temporary list on the stack from which
      contains only entries that are being deleted.
      
      Not all code paths set up dlist, so those that
      don't were performing invalid accesses in
      hash_del_rcu. As an additional means to prevent
      any other issue, we null out the list entries when
      we allocate from the cache.
      
      Signed-off-by: default avatarDaniel Rosenberg <drosen@google.com>
      Bug: 35666680
      Change-Id: Ibb1e28c08c3a600c29418d39ba1c0f3db3bf31e5
      880c68e4
  4. Feb 17, 2017
  5. Feb 15, 2017
  6. Feb 14, 2017
    • Michael Halcrow's avatar
      ANDROID: ext4 crypto: Disables zeroing on truncation when there's no key · 8b75db98
      Michael Halcrow authored
      
      When performing orphan cleanup on mount, ext4 may truncate pages.
      Truncation as currently implemented may require the encryption key for
      partial zeroing, and the key isn't necessarily available on mount.
      Since the userspace tools don't perform the partial zeroing operation
      anyway, let's just skip doing that in the kernel.
      
      This patch fixes a BUG_ON() oops.
      
      Bug: 35209576
      Change-Id: I2527a3f8d2c57d2de5df03fda69ee397f76095d7
      Signed-off-by: default avatarMichael Halcrow <mhalcrow@google.com>
      8b75db98
  7. Feb 10, 2017
    • Eric Biggers's avatar
      ANDROID: ext4: add a non-reversible key derivation method · a425a70b
      Eric Biggers authored
      
      Add a new per-file key derivation method to ext4 encryption defined as:
      
          derived_key[0:127]   = AES-256-ENCRYPT(master_key[0:255], nonce)
          derived_key[128:255] = AES-256-ENCRYPT(master_key[0:255], nonce ^ 0x01)
          derived_key[256:383] = AES-256-ENCRYPT(master_key[256:511], nonce)
          derived_key[384:511] = AES-256-ENCRYPT(master_key[256:511], nonce ^ 0x01)
      
      ... where the derived key and master key are both 512 bits, the nonce is
      128 bits, AES-256-ENCRYPT takes the arguments (key, plaintext), and
      'nonce ^ 0x01' denotes flipping the low order bit of the last byte.
      
      The existing key derivation method is
      'derived_key = AES-128-ECB-ENCRYPT(key=nonce, plaintext=master_key)'.
      We want to make this change because currently, given a derived key you
      can easily compute the master key by computing
      'AES-128-ECB-DECRYPT(key=nonce, ciphertext=derived_key)'.
      
      This was formerly OK because the previous threat model assumed that the
      master key and derived keys are equally hard to obtain by an attacker.
      However, we are looking to move the master key into secure hardware in
      some cases, so we want to make sure that an attacker with access to a
      derived key cannot compute the master key.
      
      We are doing this instead of increasing the nonce to 512 bits because
      it's important that the per-file xattr fit in the inode itself.  By
      default, inodes are 256 bytes, and on Android we're already pretty close
      to that limit. If we increase the nonce size, we end up allocating a new
      filesystem block for each and every encrypted file, which has a
      substantial performance and disk utilization impact.
      
      Another option considered was to use the HMAC-SHA512 of the nonce, keyed
      by the master key.  However this would be a little less performant,
      would be less extensible to other key sizes and MAC algorithms, and
      would pull in a dependency (security-wise and code-wise) on SHA-512.
      
      Due to the use of "aes" rather than "ecb(aes)" in the implementation,
      the new key derivation method is actually about twice as fast as the old
      one, though the old one could be optimized similarly as well.
      
      This patch makes the new key derivation method be used whenever HEH is
      used to encrypt filenames.  Although these two features are logically
      independent, it was decided to bundle them together for now.  Note that
      neither feature is upstream yet, and it cannot be guaranteed that the
      on-disk format won't change if/when these features are upstreamed.  For
      this reason, and as noted in the previous patch, the features are both
      behind a special mode number for now.
      
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: Iee4113f57e59dc8c0b7dc5238d7003c83defb986
      a425a70b
    • Eric Biggers's avatar
      ANDROID: ext4: allow encrypting filenames using HEH algorithm · 3e0dd6ec
      Eric Biggers authored
      
      Update ext4 encryption to allow filenames to be encrypted using the
      Hash-Encrypt-Hash (HEH) block cipher mode of operation, which is
      believed to be more secure than CBC, particularly within the constant
      initialization vector (IV) constraint of filename encryption.  Notably,
      HEH avoids the "common prefix" problem of CBC.  Both algorithms use
      AES-256 as the underlying block cipher and take a 256-bit key.
      
      We assign mode number 126 to HEH, just below 127
      (EXT4_ENCRYPTION_MODE_PRIVATE) which in some kernels is reserved for
      inline encryption on MSM chipsets.  Note that these modes are not yet
      upstream, which is why these numbers are being used; it's preferable to
      avoid collisions with modes that may be added upstream.  Also, although
      HEH is not hardware-specific, we aren't currently reserving mode number
      5 for HEH upstream, since for now we are tying HEH to the new key
      derivation method which might become an independent flag upstream, and
      there's also a chance that details of HEH will change after it gets
      wider review.
      
      Bug: 32975945
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: I81418709d47da0e0ac607ae3f91088063c2d5dd4
      3e0dd6ec
    • Eric Biggers's avatar
      ANDROID: arm64/crypto: add ARMv8-CE optimized poly_hash algorithm · 0223de3a
      Eric Biggers authored
      poly_hash is part of the HEH (Hash-Encrypt-Hash) encryption mode,
      proposed in Internet Draft
      https://tools.ietf.org/html/draft-cope-heh-01
      
      .  poly_hash is very
      similar to GHASH; besides the swapping of the last two coefficients
      which we opted to handle in the HEH template, poly_hash just uses a
      different finite field representation.  As with GHASH, poly_hash becomes
      much faster and more secure against timing attacks when implemented
      using carryless multiplication instructions instead of tables.  This
      patch adds an ARMv8-CE optimized version of poly_hash, based roughly on
      the existing ARMv8-CE optimized version of GHASH.
      
      Benchmark results are shown below, but note that the resistance to
      timing attacks may be even more important than the performance gain.
      
      poly_hash only:
      
          poly_hash-generic:
              1,000,000 setkey() takes 1185 ms
              hashing is 328 MB/s
      
          poly_hash-ce:
              1,000,000 setkey() takes 8 ms
              hashing is 1756 MB/s
      
      heh(aes) with 4096-byte inputs (this is the ideal case, as the
      improvement is less significant with smaller inputs):
      
          encryption with "heh_base(cmac(aes-ce),poly_hash-generic,ecb-aes-ce)": 118 MB/s
          decryption with "heh_base(cmac(aes-ce),poly_hash-generic,ecb-aes-ce)": 120 MB/s
      
          encryption with "heh_base(cmac(aes-ce),poly_hash-ce,ecb-aes-ce)": 291 MB/s
          decryption with "heh_base(cmac(aes-ce),poly_hash-ce,ecb-aes-ce)": 293 MB/s
      
      Bug: 32508661
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: I621ec0e1115df7e6f5cbd7e864a4a9d8d2e94cf2
      0223de3a
    • Eric Biggers's avatar
      ANDROID: crypto: heh - factor out poly_hash algorithm · 58b9edb0
      Eric Biggers authored
      
      Factor most of poly_hash() out into its own keyed hash algorithm so that
      optimized architecture-specific implementations of it will be possible.
      
      For now we call poly_hash through the shash API, since HEH already had
      an example of using shash for another algorithm (CMAC), and we will not
      be adding any poly_hash implementations that require ahash yet.  We can
      however switch to ahash later if it becomes useful.
      
      Bug: 32508661
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: I8de54ddcecd1d7fa6e9842a09506a08129bae0b6
      58b9edb0
    • Alex Cope's avatar
      ANDROID: crypto: heh - Add Hash-Encrypt-Hash (HEH) algorithm · 698ffc03
      Alex Cope authored
      Hash-Encrypt-Hash (HEH) is a proposed block cipher mode of operation
      which extends the strong pseudo-random permutation property of block
      ciphers (e.g. AES) to arbitrary length input strings.  This provides a
      stronger notion of security than existing block cipher modes of
      operation (e.g. CBC, CTR, XTS), though it is usually less performant.
      It uses two keyed invertible hash functions with a layer of ECB
      encryption applied in-between.  The algorithm is currently specified by
      the following Internet Draft:
      
      	https://tools.ietf.org/html/draft-cope-heh-01
      
      
      
      This patch adds HEH as a symmetric cipher only.  Support for HEH as an
      AEAD is not yet implemented.
      
      HEH will use an existing accelerated ecb(block_cipher) implementation
      for the encrypt step if available.  Accelerated versions of the hash
      step are planned but will be left for later patches.
      
      This patch backports HEH to the 4.4 Android kernel, initially for use by
      ext4 filenames encryption.  Note that HEH is not yet upstream; however,
      patches have been made available on linux-crypto, and as noted there is
      also a draft specification available.  This backport required updating
      the code to conform to the legacy ablkcipher API rather than the
      skcipher API, which wasn't complete in 4.4.
      
      Signed-off-by: default avatarAlex Cope <alexcope@google.com>
      Bug: 32975945
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: I945bcc9c0115916824d701bae91b86e3f059a1a9
      698ffc03
    • Alex Cope's avatar
      ANDROID: crypto: gf128mul - Add ble multiplication functions · ce2ace45
      Alex Cope authored
      
      Adding ble multiplication to GF128mul, and fixing up comments.
      
      The ble multiplication functions multiply GF(2^128) elements in the
      ble format. This format is preferable because the bits within each
      byte map to polynomial coefficients in the natural order (lowest order
      bit = coefficient of lowest degree polynomial term), and the bytes are
      stored in little endian order which matches the endianness of most
      modern CPUs.
      
      These new functions will be used by the HEH algorithm.
      
      Signed-off-by: default avatarAlex Cope <alexcope@google.com>
      Bug: 32975945
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: I39a58e8ee83e6f9b2e6bd51738f816dbfa2f3a47
      ce2ace45
    • Eric Biggers's avatar
      ANDROID: crypto: gf128mul - Refactor gf128 overflow macros and tables · 3eaf06b7
      Eric Biggers authored
      
      Rename and clean up the GF(2^128) overflow macros and tables.  Their
      usage is more general than the name suggested, e.g. what was previously
      known as the "bbe" table can actually be used for both "bbe" and "ble"
      multiplication.
      
      Bug: 32975945
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: Ie6c47b4075ca40031eb1767e9b468cfd7bf1b2e4
      3eaf06b7
    • Alex Cope's avatar
      UPSTREAM: crypto: gf128mul - Zero memory when freeing multiplication table · 8ea7531e
      Alex Cope authored
      
      GF(2^128) multiplication tables are typically used for secret
      information, so it's a good idea to zero them on free.
      
      Signed-off-by: default avatarAlex Cope <alexcope@google.com>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      (cherry-picked from 75aa0a7c)
      Bug: 32975945
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: I37b1ae9544158007f9ee2caf070120f4a42153ab
      8ea7531e
    • Eric Biggers's avatar
      ANDROID: crypto: shash - Add crypto_grab_shash() and crypto_spawn_shash_alg() · c8bb10b1
      Eric Biggers authored
      
      Analogous to crypto_grab_skcipher() and crypto_spawn_skcipher_alg(),
      these are useful for algorithms that need to use a shash sub-algorithm,
      possibly in addition to other sub-algorithms.
      
      Bug: 32975945
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: I44e5a519d73f5f839e3b6ecbf8c66e36ec569557
      c8bb10b1
    • Eric Biggers's avatar
      ANDROID: crypto: allow blkcipher walks over ablkcipher data · 93867d9b
      Eric Biggers authored
      
      Add a function blkcipher_ablkcipher_walk_virt() which allows ablkcipher
      algorithms to use the blkcipher_walk API to walk over their data.  This
      will be used by the HEH algorithm, which to support asynchronous ECB
      algorithms will be an ablkcipher, but it also needs to make other passes
      over the data.
      
      Bug: 32975945
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: I05f9a0e5473ba6115fcc72d5122d6b0b18b2078b
      93867d9b
    • Jeremy Linton's avatar
      UPSTREAM: arm/arm64: crypto: assure that ECB modes don't require an IV · 15227d3c
      Jeremy Linton authored
      
      ECB modes don't use an initialization vector. The kernel
      /proc/crypto interface doesn't reflect this properly.
      
      Acked-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
      Signed-off-by: default avatarJeremy Linton <jeremy.linton@arm.com>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      (cherry picked from bee038a4)
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Change-Id: Ief9558d2b41be58a2d845d2033a141b5ef7b585f
      15227d3c
    • Mohan Srinivasan's avatar
      ANDROID: Refactor fs readpage/write tracepoints. · d854b688
      Mohan Srinivasan authored
      
      Refactor the fs readpage/write tracepoints to move the
      inode->path lookup outside the tracepoint code, and pass a pointer
      to the path into the tracepoint code instead. This is necessary
      because the tracepoint code runs non-preemptible. Thanks to
      Trilok Soni for catching this in 4.4.
      
      Change-Id: I7486c5947918d155a30c61d6b9cd5027cf8fbe15
      Signed-off-by: default avatarMohan Srinivasan <srmohan@google.com>
      d854b688
    • Daniel Rosenberg's avatar
      ANDROID: export security_path_chown · 11fac3ae
      Daniel Rosenberg authored
      
      BUG: 35142419
      Change-Id: I05a9430a3c1bc624e019055175ad377290b4e774
      Signed-off-by: default avatarDaniel Rosenberg <drosen@google.com>
      11fac3ae
  8. Feb 09, 2017
    • Adrien Schildknecht's avatar
      Squashfs: optimize reading uncompressed data · d9aa8ddc
      Adrien Schildknecht authored
      
      When dealing with uncompressed data, there is no need to read a whole
      block (default 128K) to get the desired page: the pages are
      independent from each others.
      
      This patch change the readpages logic so that reading uncompressed
      data only read the number of pages advised by the readahead algorithm.
      
      Moreover, if the page actor contains holes (i.e. pages that are already
      up-to-date), squashfs skips the buffer_head associated to those pages.
      
      This patch greatly improve the performance of random reads for
      uncompressed files because squashfs only read what is needed. It also
      reduces the number of unnecessary reads.
      
      Signed-off-by: default avatarAdrien Schildknecht <adriens@google.com>
      Change-Id: I1850150fbf4b45c9dd138d88409fea1ab44054c0
      d9aa8ddc
    • Adrien Schildknecht's avatar
      Squashfs: implement .readpages() · 5e9c466d
      Adrien Schildknecht authored
      
      Squashfs does not implement .readpages(), so the kernel just repeatedly
      calls .readpage().
      
      The readpages function tries to pack as much pages as possible in the
      same page actor so that only 1 read request is issued.
      
      Now that the read requests are asynchronous, the kernel can truly
      prefetch pages using its readahead algorithm.
      
      Signed-off-by: default avatarAdrien Schildknecht <adriens@google.com>
      Change-Id: Ice70e029dc24526f61e4e5a1a902588be2212498
      5e9c466d
    • Adrien Schildknecht's avatar
      Squashfs: replace buffer_head with BIO · c9994560
      Adrien Schildknecht authored
      
      The 'll_rw_block' has been deprecated and BIO is now the basic container
      for block I/O within the kernel.
      
      Switching to BIO offers 2 advantages:
        1/ It removes synchronous wait for the up-to-date buffers: SquashFS
           now deals with decompressions/copies asynchronously.
           Implementing an asynchronous mechanism to read data is needed to
           efficiently implement .readpages().
        2/ Prior to this patch, merging the read requests entirely depends on
           the IO scheduler. SquashFS has more information than the IO
           scheduler about what could be merged. Moreover, merging the reads
           at the FS level means that we rely less on the IO scheduler.
      
      Signed-off-by: default avatarAdrien Schildknecht <adriens@google.com>
      Change-Id: I775d2e11f017476e1899518ab52d9d0a8a0bce28
      c9994560
    • Adrien Schildknecht's avatar
      Squashfs: refactor page_actor · 417aca47
      Adrien Schildknecht authored
      
      This patch essentially does 3 things:
        1/ Always use an array of page to store the data instead of a mix of
           buffers and pages.
        2/ It is now possible to have 'holes' in a page actor, i.e. NULL
           pages in the array.
           When reading a block (default 128K), squashfs tries to grab all
           the pages covering this block. If a single page is up-to-date or
           locked, it falls back to using an intermediate buffer to do the
           read and then copy the pages in the actor. Allowing holes in the
           page actor remove the need for this intermediate buffer.
        3/ Refactor the wrappers to share code that deals with page actors.
      
      Signed-off-by: default avatarAdrien Schildknecht <adriens@google.com>
      Change-Id: I98128bed5d518cf31b67e788a85b275e9a323bec
      417aca47
    • Adrien Schildknecht's avatar
      Squashfs: remove the FILE_CACHE option · 50dcddba
      Adrien Schildknecht authored
      
      FILE_DIRECT is working fine and offers faster results and lower memory
      footprint.
      
      Removing FILE_CACHE makes our life easier because we don't have to
      maintain 2 differents function that does the same thing.
      
      Signed-off-by: default avatarAdrien Schildknecht <adriens@google.com>
      Change-Id: I6689ba74d0042c222a806f9edc539995e8e04c6b
      50dcddba
  9. Feb 07, 2017
  10. Feb 04, 2017
  11. Feb 03, 2017
    • Pratyush Anand's avatar
      UPSTREAM: arm64: Allow hw watchpoint of length 3,5,6 and 7 · edc166a8
      Pratyush Anand authored
      
      (cherry picked from commit 0ddb8e0b)
      
      Since, arm64 can support all offset within a double word limit. Therefore,
      now support other lengths within that range as well.
      
      Signed-off-by: default avatarPratyush Anand <panand@redhat.com>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarPavel Labath <labath@google.com>
      Change-Id: Ibcb263a3903572336ccbf96e0180d3990326545a
      Bug: 30919905
      edc166a8
    • Pavel Labath's avatar
      BACKPORT: arm64: hw_breakpoint: Handle inexact watchpoint addresses · b48318f3
      Pavel Labath authored
      
      (cherry picked from commit fdfeff0f)
      
      Arm64 hardware does not always report a watchpoint hit address that
      matches one of the watchpoints set. It can also report an address
      "near" the watchpoint if a single instruction access both watched and
      unwatched addresses. There is no straight-forward way, short of
      disassembling the offending instruction, to map that address back to
      the watchpoint.
      
      Previously, when the hardware reported a watchpoint hit on an address
      that did not match our watchpoint (this happens in case of instructions
      which access large chunks of memory such as "stp") the process would
      enter a loop where we would be continually resuming it (because we did
      not recognise that watchpoint hit) and it would keep hitting the
      watchpoint again and again. The tracing process would never get
      notified of the watchpoint hit.
      
      This commit fixes the problem by looking at the watchpoints near the
      address reported by the hardware. If the address does not exactly match
      one of the watchpoints we have set, it attributes the hit to the
      nearest watchpoint we have.  This heuristic is a bit dodgy, but I don't
      think we can do much more, given the hardware limitations.
      
      Signed-off-by: default avatarPavel Labath <labath@google.com>
      [panand: reworked to rebase on his patches]
      Signed-off-by: default avatarPratyush Anand <panand@redhat.com>
      [will: use __ffs instead of ffs - 1]
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarPavel Labath <labath@google.com>
      [pavel: trivial fixup in hw_breakpoint.c:watchpoint_handler]
      Change-Id: I714dfaa3947d89d89a9e9a1ea84914d44ba0faa3
      Bug: 30919905
      b48318f3
    • Pratyush Anand's avatar
      UPSTREAM: arm64: Allow hw watchpoint at varied offset from base address · 7409857a
      Pratyush Anand authored
      
      ARM64 hardware supports watchpoint at any double word aligned address.
      However, it can select any consecutive bytes from offset 0 to 7 from that
      base address. For example, if base address is programmed as 0x420030 and
      byte select is 0x1C, then access of 0x420032,0x420033 and 0x420034 will
      generate a watchpoint exception.
      
      Currently, we do not have such modularity. We can only program byte,
      halfword, word and double word access exception from any base address.
      
      This patch adds support to overcome above limitations.
      
      Signed-off-by: default avatarPratyush Anand <panand@redhat.com>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarPavel Labath <labath@google.com>
      Change-Id: I28b1ca63f63182c10c3d6b6b3bacf6c56887ddbe
      Bug: 30919905
      7409857a
    • Pratyush Anand's avatar
      BACKPORT: hw_breakpoint: Allow watchpoint of length 3,5,6 and 7 · 91495bc6
      Pratyush Anand authored
      
      (cherry picked from commit 651be3cb)
      
      We only support breakpoint/watchpoint of length 1, 2, 4 and 8. If we can
      support other length as well, then user may watch more data with less
      number of watchpoints (provided hardware supports it). For example: if we
      have to watch only 4th, 5th and 6th byte from a 64 bit aligned address, we
      will have to use two slots to implement it currently. One slot will watch a
      half word at offset 4 and other a byte at offset 6. If we can have a
      watchpoint of length 3 then we can watch it with single slot as well.
      
      ARM64 hardware does support such functionality, therefore adding these new
      definitions in generic layer.
      
      Signed-off-by: default avatarPratyush Anand <panand@redhat.com>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarPavel Labath <labath@google.com>
      [pavel: tools/include/uapi/linux/hw_breakpoint.h is not present in this branch]
      Change-Id: Ie17ed89ca526e4fddf591bb4e556fdfb55fc2eac
      Bug: 30919905
      91495bc6
  12. Feb 02, 2017
  13. Feb 01, 2017
    • Amit Pundir's avatar
      ANDROID: binder: fix format specifier for type binder_size_t · df3087d4
      Amit Pundir authored
      
      Fix following warning on 32bit ARCH build:
      
        CC      drivers/android/binder.o
      drivers/android/binder.c: In function ‘binder_transaction’:
      ./include/linux/kern_levels.h:4:18: warning: format ‘%lld’ expects argument of type ‘long long int’,
      but argument 4 has type ‘binder_size_t {aka unsigned int}’ [-Wformat=]
      drivers/android/binder.c:2047:3: note: in expansion of macro ‘binder_user_error’
         binder_user_error("%d:%d got transaction with unaligned buffers size, %lld\n",
         ^
      
      Change-Id: I943d0d4d54f7f2a019900cc18e55bed661bec5a5
      Fixes: Change-Id: I02417f28cff14688f2e1d6fcb959438fd96566cc
             (android: binder: support for scatter-gather.")
      Signed-off-by: default avatarAmit Pundir <amit.pundir@linaro.org>
      df3087d4
Loading