1. 11 7月, 2019 1 次提交
  2. 09 7月, 2019 8 次提交
    • R
      ubifs: Don't leak orphans on memory during commit · 8009ce95
      Richard Weinberger 提交于
      If an orphan has child orphans (xattrs), and due
      to a commit the parent orpahn cannot get free()'ed immediately,
      put also all child orphans on the erase list.
      Otherwise UBIFS will free() them only upon unmount and we
      waste memory.
      
      Fixes: 988bec41 ("ubifs: orphan: Handle xattrs like files")
      Signed-off-by: NRichard Weinberger <richard@nod.at>
      8009ce95
    • R
      ubifs: Check link count of inodes when killing orphans. · ee1438ce
      Richard Weinberger 提交于
      O_TMPFILE files can change their link count back to non-zero.
      This corner case needs to get addressed in the orphans subsystem
      too.
      
      Fixes: 474b9370 ("ubifs: Implement O_TMPFILE")
      Reported-by: NLars Persson <lists@bofh.nu>
      Signed-off-by: NRichard Weinberger <richard@nod.at>
      ee1438ce
    • M
      ubifs: Add support for zstd compression. · eeabb986
      Michele Dionisio 提交于
      zstd shows a good compression rate and is faster than lzo,
      also on slow ARM cores.
      
      Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
      Signed-off-by: NMichele Dionisio <michele.dionisio@gmail.com>
      [rw: rewrote commit message]
      Signed-off-by: NRichard Weinberger <richard@nod.at>
      eeabb986
    • S
      ubifs: support offline signed images · 817aa094
      Sascha Hauer 提交于
      HMACs can only be generated on the system the UBIFS image is running on.
      To support offline signed images we add a PKCS#7 signature to the UBIFS
      image which can be created by mkfs.ubifs.
      
      Both the master node and the superblock need to be authenticated, during
      normal runtime both are protected with HMACs. For offline signature
      support however only a single signature is desired. We add a signature
      covering the superblock node directly behind it. To protect the master
      node a hash of the master node is added to the superblock which is used
      when the master node doesn't contain a HMAC.
      
      Transition to a read/write filesystem is also supported. During
      transition first the master node is rewritten with a HMAC (implicitly,
      it is written anyway as the FS is marked dirty). Afterwards the
      superblock is rewritten with a HMAC. Once after the image has been
      mounted read/write it is HMAC only, the signature is no longer required
      or even present on the filesystem.
      
      In an offline signed image the master node is authenticated by the
      superblock. In a transition to r/w we have to make sure that the master
      node is rewritten before the superblock node. In this case the master
      node gets a HMAC and its authenticity no longer depends on the
      superblock node. There are some cases in which the current code first
      writes the superblock node though, so with this patch writing of the
      superblock node is delayed until the master node is written.
      Signed-off-by: NSascha Hauer <s.hauer@pengutronix.de>
      Signed-off-by: NRichard Weinberger <richard@nod.at>
      817aa094
    • L
      ubifs: remove unnecessary check in ubifs_log_start_commit · 8ba0a2ab
      Liu Song 提交于
      In ubifs_log_start_commit, the value of c->lhead_offs is zero or set
      to zero by code bellow.
      
      	/* Switch to the next log LEB */
      	if (c->lhead_offs) {
      		c->lhead_lnum = ubifs_next_log_lnum(c, c->lhead_lnum);
      		ubifs_assert(c->lhead_lnum != c->ltail_lnum);
      		c->lhead_offs = 0;
      	}
      
      The value of 'len' can not exceed 'max_len' which assigned value by
      code bellow.
      
      	max_len = UBIFS_CS_NODE_SZ + c->jhead_cnt * UBIFS_REF_NODE_SZ;
      
      The value of c->lhead_offs changed by code bellow and cannot exceed
      'max_len'.
      
      	c->lhead_offs += len;
      	if (c->lhead_offs == c->leb_size) {
      		c->lhead_lnum = ubifs_next_log_lnum(c, c->lhead_lnum);
      		c->lhead_offs = 0;
      	}
      
      Usually, the size of PEB is between 64KB and 256KB. So the value of
      c->lhead_offs is far less than c->leb_size. The check
      'if (c->lhead_offs == c->leb_size)' could never to be true.
      Signed-off-by: NLiu Song <liu.song11@zte.com.cn>
      Reviewed-by: NJiang Biao <jiang.biao2@zte.com.cn>
      Signed-off-by: NRichard Weinberger <richard@nod.at>
      8ba0a2ab
    • L
      ubifs: Fix typo of output in get_cs_sqnum · 7d8c811b
      Liu Song 提交于
      "Not a CS node" makes more sense than "Node a CS node".
      Signed-off-by: NLiu Song <liu.song11@zte.com.cn>
      Reviewed-by: NJiang Biao <jiang.biao2@zte.com.cn>
      Signed-off-by: NRichard Weinberger <richard@nod.at>
      7d8c811b
    • L
      ubifs: Simplify redundant code · d5cf9473
      Liu Song 提交于
      cbuf's size can be simply assigned.
      Signed-off-by: NLiu Song <liu.song11@zte.com.cn>
      Reviewed-by: NJiang Biao <jiang.biao2@zte.com.cn>
      Signed-off-by: NRichard Weinberger <richard@nod.at>
      d5cf9473
    • R
      ubifs: Correctly use tnc_next() in search_dh_cookie() · bacfa94b
      Richard Weinberger 提交于
      Commit c877154d fixed an uninitialized variable and optimized
      the function to not call tnc_next() in the first iteration of the
      loop. While this seemed perfectly legit and wise, it turned out to
      be illegal.
      If the lookup function does not find an exact match it will rewind
      the cursor by 1.
      The rewinded cursor will not match the name hash we are looking for
      and this results in a spurious -ENOENT.
      So we need to move to the next entry in case of an non-exact match,
      but not if the match was exact.
      
      While we are here, update the documentation to avoid further confusion.
      
      Cc: Hyunchul Lee <hyc.lee@gmail.com>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Fixes: c877154d ("ubifs: Fix uninitialized variable in search_dh_cookie()")
      Fixes: 781f675e ("ubifs: Fix unlink code wrt. double hash lookups")
      Signed-off-by: NRichard Weinberger <richard@nod.at>
      bacfa94b
  3. 04 7月, 2019 1 次提交
  4. 03 7月, 2019 1 次提交
  5. 01 7月, 2019 1 次提交
  6. 28 6月, 2019 1 次提交
    • D
      keys: Replace uid/gid/perm permissions checking with an ACL · 2e12256b
      David Howells 提交于
      Replace the uid/gid/perm permissions checking on a key with an ACL to allow
      the SETATTR and SEARCH permissions to be split.  This will also allow a
      greater range of subjects to represented.
      
      ============
      WHY DO THIS?
      ============
      
      The problem is that SETATTR and SEARCH cover a slew of actions, not all of
      which should be grouped together.
      
      For SETATTR, this includes actions that are about controlling access to a
      key:
      
       (1) Changing a key's ownership.
      
       (2) Changing a key's security information.
      
       (3) Setting a keyring's restriction.
      
      And actions that are about managing a key's lifetime:
      
       (4) Setting an expiry time.
      
       (5) Revoking a key.
      
      and (proposed) managing a key as part of a cache:
      
       (6) Invalidating a key.
      
      Managing a key's lifetime doesn't really have anything to do with
      controlling access to that key.
      
      Expiry time is awkward since it's more about the lifetime of the content
      and so, in some ways goes better with WRITE permission.  It can, however,
      be set unconditionally by a process with an appropriate authorisation token
      for instantiating a key, and can also be set by the key type driver when a
      key is instantiated, so lumping it with the access-controlling actions is
      probably okay.
      
      As for SEARCH permission, that currently covers:
      
       (1) Finding keys in a keyring tree during a search.
      
       (2) Permitting keyrings to be joined.
      
       (3) Invalidation.
      
      But these don't really belong together either, since these actions really
      need to be controlled separately.
      
      Finally, there are number of special cases to do with granting the
      administrator special rights to invalidate or clear keys that I would like
      to handle with the ACL rather than key flags and special checks.
      
      
      ===============
      WHAT IS CHANGED
      ===============
      
      The SETATTR permission is split to create two new permissions:
      
       (1) SET_SECURITY - which allows the key's owner, group and ACL to be
           changed and a restriction to be placed on a keyring.
      
       (2) REVOKE - which allows a key to be revoked.
      
      The SEARCH permission is split to create:
      
       (1) SEARCH - which allows a keyring to be search and a key to be found.
      
       (2) JOIN - which allows a keyring to be joined as a session keyring.
      
       (3) INVAL - which allows a key to be invalidated.
      
      The WRITE permission is also split to create:
      
       (1) WRITE - which allows a key's content to be altered and links to be
           added, removed and replaced in a keyring.
      
       (2) CLEAR - which allows a keyring to be cleared completely.  This is
           split out to make it possible to give just this to an administrator.
      
       (3) REVOKE - see above.
      
      
      Keys acquire ACLs which consist of a series of ACEs, and all that apply are
      unioned together.  An ACE specifies a subject, such as:
      
       (*) Possessor - permitted to anyone who 'possesses' a key
       (*) Owner - permitted to the key owner
       (*) Group - permitted to the key group
       (*) Everyone - permitted to everyone
      
      Note that 'Other' has been replaced with 'Everyone' on the assumption that
      you wouldn't grant a permit to 'Other' that you wouldn't also grant to
      everyone else.
      
      Further subjects may be made available by later patches.
      
      The ACE also specifies a permissions mask.  The set of permissions is now:
      
      	VIEW		Can view the key metadata
      	READ		Can read the key content
      	WRITE		Can update/modify the key content
      	SEARCH		Can find the key by searching/requesting
      	LINK		Can make a link to the key
      	SET_SECURITY	Can change owner, ACL, expiry
      	INVAL		Can invalidate
      	REVOKE		Can revoke
      	JOIN		Can join this keyring
      	CLEAR		Can clear this keyring
      
      
      The KEYCTL_SETPERM function is then deprecated.
      
      The KEYCTL_SET_TIMEOUT function then is permitted if SET_SECURITY is set,
      or if the caller has a valid instantiation auth token.
      
      The KEYCTL_INVALIDATE function then requires INVAL.
      
      The KEYCTL_REVOKE function then requires REVOKE.
      
      The KEYCTL_JOIN_SESSION_KEYRING function then requires JOIN to join an
      existing keyring.
      
      The JOIN permission is enabled by default for session keyrings and manually
      created keyrings only.
      
      
      ======================
      BACKWARD COMPATIBILITY
      ======================
      
      To maintain backward compatibility, KEYCTL_SETPERM will translate the
      permissions mask it is given into a new ACL for a key - unless
      KEYCTL_SET_ACL has been called on that key, in which case an error will be
      returned.
      
      It will convert possessor, owner, group and other permissions into separate
      ACEs, if each portion of the mask is non-zero.
      
      SETATTR permission turns on all of INVAL, REVOKE and SET_SECURITY.  WRITE
      permission turns on WRITE, REVOKE and, if a keyring, CLEAR.  JOIN is turned
      on if a keyring is being altered.
      
      The KEYCTL_DESCRIBE function translates the ACL back into a permissions
      mask to return depending on possessor, owner, group and everyone ACEs.
      
      It will make the following mappings:
      
       (1) INVAL, JOIN -> SEARCH
      
       (2) SET_SECURITY -> SETATTR
      
       (3) REVOKE -> WRITE if SETATTR isn't already set
      
       (4) CLEAR -> WRITE
      
      Note that the value subsequently returned by KEYCTL_DESCRIBE may not match
      the value set with KEYCTL_SETATTR.
      
      
      =======
      TESTING
      =======
      
      This passes the keyutils testsuite for all but a couple of tests:
      
       (1) tests/keyctl/dh_compute/badargs: The first wrong-key-type test now
           returns EOPNOTSUPP rather than ENOKEY as READ permission isn't removed
           if the type doesn't have ->read().  You still can't actually read the
           key.
      
       (2) tests/keyctl/permitting/valid: The view-other-permissions test doesn't
           work as Other has been replaced with Everyone in the ACL.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      2e12256b
  7. 05 6月, 2019 1 次提交
  8. 29 5月, 2019 2 次提交
    • E
      fscrypt: introduce fscrypt_decrypt_block_inplace() · 41adbcb7
      Eric Biggers 提交于
      Currently fscrypt_decrypt_page() does one of two logically distinct
      things depending on whether FS_CFLG_OWN_PAGES is set in the filesystem's
      fscrypt_operations: decrypt a pagecache page in-place, or decrypt a
      filesystem block in-place in any page.  Currently these happen to share
      the same implementation, but this conflates the notion of blocks and
      pages.  It also makes it so that all callers have to provide inode and
      lblk_num, when fscrypt could determine these itself for pagecache pages.
      
      Therefore, move the FS_CFLG_OWN_PAGES behavior into a new function
      fscrypt_decrypt_block_inplace().  This mirrors
      fscrypt_encrypt_block_inplace().
      
      This is in preparation for allowing encryption on ext4 filesystems with
      blocksize != PAGE_SIZE.
      Reviewed-by: NChandan Rajendra <chandan@linux.ibm.com>
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      41adbcb7
    • E
      fscrypt: introduce fscrypt_encrypt_block_inplace() · 03569f2f
      Eric Biggers 提交于
      fscrypt_encrypt_page() behaves very differently depending on whether the
      filesystem set FS_CFLG_OWN_PAGES in its fscrypt_operations.  This makes
      the function difficult to understand and document.  It also makes it so
      that all callers have to provide inode and lblk_num, when fscrypt could
      determine these itself for pagecache pages.
      
      Therefore, move the FS_CFLG_OWN_PAGES behavior into a new function
      fscrypt_encrypt_block_inplace().
      
      This is in preparation for allowing encryption on ext4 filesystems with
      blocksize != PAGE_SIZE.
      Reviewed-by: NChandan Rajendra <chandan@linux.ibm.com>
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      03569f2f
  9. 21 5月, 2019 1 次提交
  10. 16 5月, 2019 3 次提交
  11. 08 5月, 2019 12 次提交
  12. 02 5月, 2019 1 次提交
  13. 25 4月, 2019 1 次提交
    • E
      crypto: shash - remove shash_desc::flags · 877b5691
      Eric Biggers 提交于
      The flags field in 'struct shash_desc' never actually does anything.
      The only ostensibly supported flag is CRYPTO_TFM_REQ_MAY_SLEEP.
      However, no shash algorithm ever sleeps, making this flag a no-op.
      
      With this being the case, inevitably some users who can't sleep wrongly
      pass MAY_SLEEP.  These would all need to be fixed if any shash algorithm
      actually started sleeping.  For example, the shash_ahash_*() functions,
      which wrap a shash algorithm with the ahash API, pass through MAY_SLEEP
      from the ahash API to the shash API.  However, the shash functions are
      called under kmap_atomic(), so actually they're assumed to never sleep.
      
      Even if it turns out that some users do need preemption points while
      hashing large buffers, we could easily provide a helper function
      crypto_shash_update_large() which divides the data into smaller chunks
      and calls crypto_shash_update() and cond_resched() for each chunk.  It's
      not necessary to have a flag in 'struct shash_desc', nor is it necessary
      to make individual shash algorithms aware of this at all.
      
      Therefore, remove shash_desc::flags, and document that the
      crypto_shash_*() functions can be called from any context.
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      877b5691
  14. 18 4月, 2019 1 次提交
    • E
      fscrypt: cache decrypted symlink target in ->i_link · 2c58d548
      Eric Biggers 提交于
      Path lookups that traverse encrypted symlink(s) are very slow because
      each encrypted symlink needs to be decrypted each time it's followed.
      This also involves dropping out of rcu-walk mode.
      
      Make encrypted symlinks faster by caching the decrypted symlink target
      in ->i_link.  The first call to fscrypt_get_symlink() sets it.  Then,
      the existing VFS path lookup code uses the non-NULL ->i_link to take the
      fast path where ->get_link() isn't called, and lookups in rcu-walk mode
      remain in rcu-walk mode.
      
      Also set ->i_link immediately when a new encrypted symlink is created.
      
      To safely free the symlink target after an RCU grace period has elapsed,
      introduce a new function fscrypt_free_inode(), and make the relevant
      filesystems call it just before actually freeing the inode.
      
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      2c58d548
  15. 17 4月, 2019 1 次提交
    • E
      fscrypt: fix race where ->lookup() marks plaintext dentry as ciphertext · b01531db
      Eric Biggers 提交于
      ->lookup() in an encrypted directory begins as follows:
      
      1. fscrypt_prepare_lookup():
          a. Try to load the directory's encryption key.
          b. If the key is unavailable, mark the dentry as a ciphertext name
             via d_flags.
      2. fscrypt_setup_filename():
          a. Try to load the directory's encryption key.
          b. If the key is available, encrypt the name (treated as a plaintext
             name) to get the on-disk name.  Otherwise decode the name
             (treated as a ciphertext name) to get the on-disk name.
      
      But if the key is concurrently added, it may be found at (2a) but not at
      (1a).  In this case, the dentry will be wrongly marked as a ciphertext
      name even though it was actually treated as plaintext.
      
      This will cause the dentry to be wrongly invalidated on the next lookup,
      potentially causing problems.  For example, if the racy ->lookup() was
      part of sys_mount(), then the new mount will be detached when anything
      tries to access it.  This is despite the mountpoint having a plaintext
      path, which should remain valid now that the key was added.
      
      Of course, this is only possible if there's a userspace race.  Still,
      the additional kernel-side race is confusing and unexpected.
      
      Close the kernel-side race by changing fscrypt_prepare_lookup() to also
      set the on-disk filename (step 2b), consistent with the d_flags update.
      
      Fixes: 28b4c263 ("ext4 crypto: revalidate dentry after adding or removing the key")
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      b01531db
  16. 01 4月, 2019 1 次提交
  17. 24 2月, 2019 1 次提交
  18. 24 1月, 2019 1 次提交
  19. 29 12月, 2018 1 次提交