Skip to content
Snippets Groups Projects
  1. Jul 19, 2019
  2. Jul 15, 2019
  3. Jul 12, 2019
    • Alexander Potapenko's avatar
      mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options · 6471384a
      Alexander Potapenko authored
      Patch series "add init_on_alloc/init_on_free boot options", v10.
      
      Provide init_on_alloc and init_on_free boot options.
      
      These are aimed at preventing possible information leaks and making the
      control-flow bugs that depend on uninitialized values more deterministic.
      
      Enabling either of the options guarantees that the memory returned by the
      page allocator and SL[AU]B is initialized with zeroes.  SLOB allocator
      isn't supported at the moment, as its emulation of kmem caches complicates
      handling of SLAB_TYPESAFE_BY_RCU caches correctly.
      
      Enabling init_on_free also guarantees that pages and heap objects are
      initialized right after they're freed, so it won't be possible to access
      stale data by using a dangling pointer.
      
      As suggested by Michal Hocko, right now we don't let the heap users to
      disable initialization for certain allocations.  There's not enough
      evidence that doing so can speed up real-life cases, and introducing ways
      to opt-out may result in things going out of control.
      
      This patch (of 2):
      
      The new options are needed to prevent possible information leaks and make
      control-flow bugs that depend on uninitialized values more deterministic.
      
      This is expected to be on-by-default on Android and Chrome OS.  And it
      gives the opportunity for anyone else to use it under distros too via the
      boot args.  (The init_on_free feature is regularly requested by folks
      where memory forensics is included in their threat models.)
      
      init_on_alloc=1 makes the kernel initialize newly allocated pages and heap
      objects with zeroes.  Initialization is done at allocation time at the
      places where checks for __GFP_ZERO are performed.
      
      init_on_free=1 makes the kernel initialize freed pages and heap objects
      with zeroes upon their deletion.  This helps to ensure sensitive data
      doesn't leak via use-after-free accesses.
      
      Both init_on_alloc=1 and init_on_free=1 guarantee that the allocator
      returns zeroed memory.  The two exceptions are slab caches with
      constructors and SLAB_TYPESAFE_BY_RCU flag.  Those are never
      zero-initialized to preserve their semantics.
      
      Both init_on_alloc and init_on_free default to zero, but those defaults
      can be overridden with CONFIG_INIT_ON_ALLOC_DEFAULT_ON and
      CONFIG_INIT_ON_FREE_DEFAULT_ON.
      
      If either SLUB poisoning or page poisoning is enabled, those options take
      precedence over init_on_alloc and init_on_free: initialization is only
      applied to unpoisoned allocations.
      
      Slowdown for the new features compared to init_on_free=0, init_on_alloc=0:
      
      hackbench, init_on_free=1:  +7.62% sys time (st.err 0.74%)
      hackbench, init_on_alloc=1: +7.75% sys time (st.err 2.14%)
      
      Linux build with -j12, init_on_free=1:  +8.38% wall time (st.err 0.39%)
      Linux build with -j12, init_on_free=1:  +24.42% sys time (st.err 0.52%)
      Linux build with -j12, init_on_alloc=1: -0.13% wall time (st.err 0.42%)
      Linux build with -j12, init_on_alloc=1: +0.57% sys time (st.err 0.40%)
      
      The slowdown for init_on_free=0, init_on_alloc=0 compared to the baseline
      is within the standard error.
      
      The new features are also going to pave the way for hardware memory
      tagging (e.g.  arm64's MTE), which will require both on_alloc and on_free
      hooks to set the tags for heap objects.  With MTE, tagging will have the
      same cost as memory initialization.
      
      Although init_on_free is rather costly, there are paranoid use-cases where
      in-memory data lifetime is desired to be minimized.  There are various
      arguments for/against the realism of the associated threat models, but
      given that we'll need the infrastructure for MTE anyway, and there are
      people who want wipe-on-free behavior no matter what the performance cost,
      it seems reasonable to include it in this series.
      
      [glider@google.com: v8]
        Link: http://lkml.kernel.org/r/20190626121943.131390-2-glider@google.com
      [glider@google.com: v9]
        Link: http://lkml.kernel.org/r/20190627130316.254309-2-glider@google.com
      [glider@google.com: v10]
        Link: http://lkml.kernel.org/r/20190628093131.199499-2-glider@google.com
      Link: http://lkml.kernel.org/r/20190617151050.92663-2-glider@google.com
      
      
      Signed-off-by: default avatarAlexander Potapenko <glider@google.com>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Acked-by: Michal Hocko <mhocko@suse.cz>		[page and dmapool parts
      Acked-by: default avatarJames Morris <jamorris@linux.microsoft.com&gt;]>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Kostya Serebryany <kcc@google.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Sandeep Patil <sspatil@android.com>
      Cc: Laura Abbott <labbott@redhat.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Jann Horn <jannh@google.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Marco Elver <elver@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      6471384a
  4. Jul 11, 2019
  5. Jul 07, 2019
  6. Jul 05, 2019
  7. Jul 03, 2019
    • David Howells's avatar
      keys: Provide KEYCTL_GRANT_PERMISSION · 7a1ade84
      David Howells authored
      
      Provide a keyctl() operation to grant/remove permissions.  The grant
      operation, wrapped by libkeyutils, looks like:
      
      	int ret = keyctl_grant_permission(key_serial_t key,
      					  enum key_ace_subject_type type,
      					  unsigned int subject,
      					  unsigned int perm);
      
      Where key is the key to be modified, type and subject represent the subject
      to which permission is to be granted (or removed) and perm is the set of
      permissions to be granted.  0 is returned on success.  SET_SECURITY
      permission is required for this.
      
      The subject type currently must be KEY_ACE_SUBJ_STANDARD for the moment
      (other subject types will come along later).
      
      For subject type KEY_ACE_SUBJ_STANDARD, the following subject values are
      available:
      
      	KEY_ACE_POSSESSOR	The possessor of the key
      	KEY_ACE_OWNER		The owner of the key
      	KEY_ACE_GROUP		The key's group
      	KEY_ACE_EVERYONE	Everyone
      
      perm lists the permissions to be granted:
      
      	KEY_ACE_VIEW		Can view the key metadata
      	KEY_ACE_READ		Can read the key content
      	KEY_ACE_WRITE		Can update/modify the key content
      	KEY_ACE_SEARCH		Can find the key by searching/requesting
      	KEY_ACE_LINK		Can make a link to the key
      	KEY_ACE_SET_SECURITY	Can set security
      	KEY_ACE_INVAL		Can invalidate
      	KEY_ACE_REVOKE		Can revoke
      	KEY_ACE_JOIN		Can join this keyring
      	KEY_ACE_CLEAR		Can clear this keyring
      
      If an ACE already exists for the subject, then the permissions mask will be
      overwritten; if perm is 0, it will be deleted.
      
      Currently, the internal ACL is limited to a maximum of 16 entries.
      
      For example:
      
      	int ret = keyctl_grant_permission(key,
      					  KEY_ACE_SUBJ_STANDARD,
      					  KEY_ACE_OWNER,
      					  KEY_ACE_VIEW | KEY_ACE_READ);
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      7a1ade84
  8. Jul 01, 2019
  9. Jun 30, 2019
    • Thiago Jung Bauermann's avatar
      integrity: Introduce struct evm_xattr · 650b29db
      Thiago Jung Bauermann authored
      
      Even though struct evm_ima_xattr_data includes a fixed-size array to hold a
      SHA1 digest, most of the code ignores the array and uses the struct to mean
      "type indicator followed by data of unspecified size" and tracks the real
      size of what the struct represents in a separate length variable.
      
      The only exception to that is the EVM code, which correctly uses the
      definition of struct evm_ima_xattr_data.
      
      So make this explicit in the code by removing the length specification from
      the array in struct evm_ima_xattr_data. Also, change the name of the
      element from digest to data since in most places the array doesn't hold a
      digest.
      
      A separate struct evm_xattr is introduced, with the original definition of
      evm_ima_xattr_data to be used in the places that actually expect that
      definition, specifically the EVM HMAC code.
      
      Signed-off-by: default avatarThiago Jung Bauermann <bauerman@linux.ibm.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      650b29db
    • Thiago Jung Bauermann's avatar
      ima: Update MAX_TEMPLATE_NAME_LEN to fit largest reasonable definition · 337619eb
      Thiago Jung Bauermann authored
      
      MAX_TEMPLATE_NAME_LEN is used when restoring measurements carried over from
      a kexec. It should be set to the length of a template containing all fields
      except for 'd' and 'n', which don't need to be accounted for since they
      shouldn't be defined in the same template description as 'd-ng' and 'n-ng'.
      
      That length is greater than the current 15, so update using a sizeof() to
      show where the number comes from and also can be visually shown to be
      correct. The sizeof() is calculated at compile time.
      
      Signed-off-by: default avatarThiago Jung Bauermann <bauerman@linux.ibm.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      337619eb
    • Prakhar Srivastava's avatar
      IMA: Define a new template field buf · 86b4da8c
      Prakhar Srivastava authored
      
      A buffer(kexec boot command line arguments) measured into IMA
      measuremnt list cannot be appraised, without already being
      aware of the buffer contents. Since hashes are non-reversible,
      raw buffer is needed for validation or regenerating hash for
      appraisal/attestation.
      
      Add support to store/read the buffer contents in HEX.
      The kexec cmdline hash is stored in the "d-ng" field of the
      template data.  It can be verified using
      sudo cat /sys/kernel/security/integrity/ima/ascii_runtime_measurements |
        grep  kexec-cmdline | cut -d' ' -f 6 | xxd -r -p | sha256sum
      
      - Add two new fields to ima_event_data to hold the buf and
      buf_len
      - Add a new template field 'buf' to be used to store/read
      the buffer data.
      - Updated process_buffer_meaurement to add the buffer to
      ima_event_data. process_buffer_measurement added in
      "Define a new IMA hook to measure the boot command line
       arguments"
      - Add a new template policy name ima-buf to represent
      'd-ng|n-ng|buf'
      
      Signed-off-by: default avatarPrakhar Srivastava <prsriva02@gmail.com>
      Reviewed-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: default avatarJames Morris <jamorris@linux.microsoft.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      86b4da8c
  10. Jun 27, 2019
    • David Howells's avatar
      keys: Replace uid/gid/perm permissions checking with an ACL · 2e12256b
      David Howells authored
      
      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: default avatarDavid Howells <dhowells@redhat.com>
      2e12256b
    • David Howells's avatar
      keys: Pass the network namespace into request_key mechanism · a58946c1
      David Howells authored
      
      Create a request_key_net() function and use it to pass the network
      namespace domain tag into DNS revolver keys and rxrpc/AFS keys so that keys
      for different domains can coexist in the same keyring.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: netdev@vger.kernel.org
      cc: linux-nfs@vger.kernel.org
      cc: linux-cifs@vger.kernel.org
      cc: linux-afs@lists.infradead.org
      a58946c1
  11. Jun 26, 2019
    • David Howells's avatar
      keys: Network namespace domain tag · 9b242610
      David Howells authored
      
      Create key domain tags for network namespaces and make it possible to
      automatically tag keys that are used by networked services (e.g. AF_RXRPC,
      AFS, DNS) with the default network namespace if not set by the caller.
      
      This allows keys with the same description but in different namespaces to
      coexist within a keyring.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: netdev@vger.kernel.org
      cc: linux-nfs@vger.kernel.org
      cc: linux-cifs@vger.kernel.org
      cc: linux-afs@lists.infradead.org
      9b242610
    • David Howells's avatar
      keys: Garbage collect keys for which the domain has been removed · 218e6424
      David Howells authored
      
      If a key operation domain (such as a network namespace) has been removed
      then attempt to garbage collect all the keys that use it.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      218e6424
    • David Howells's avatar
      keys: Include target namespace in match criteria · 3b6e4de0
      David Howells authored
      
      Currently a key has a standard matching criteria of { type, description }
      and this is used to only allow keys with unique criteria in a keyring.
      This means, however, that you cannot have keys with the same type and
      description but a different target namespace in the same keyring.
      
      This is a potential problem for a containerised environment where, say, a
      container is made up of some parts of its mount space involving netfs
      superblocks from two different network namespaces.
      
      This is also a problem for shared system management keyrings such as the
      DNS records keyring or the NFS idmapper keyring that might contain keys
      from different network namespaces.
      
      Fix this by including a namespace component in a key's matching criteria.
      Keyring types are marked to indicate which, if any, namespace is relevant
      to keys of that type, and that namespace is set when the key is created
      from the current task's namespace set.
      
      The capability bit KEYCTL_CAPS1_NS_KEY_TAG is set if the kernel is
      employing this feature.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      3b6e4de0
    • David Howells's avatar
      keys: Move the user and user-session keyrings to the user_namespace · 0f44e4d9
      David Howells authored
      
      Move the user and user-session keyrings to the user_namespace struct rather
      than pinning them from the user_struct struct.  This prevents these
      keyrings from propagating across user-namespaces boundaries with regard to
      the KEY_SPEC_* flags, thereby making them more useful in a containerised
      environment.
      
      The issue is that a single user_struct may be represent UIDs in several
      different namespaces.
      
      The way the patch does this is by attaching a 'register keyring' in each
      user_namespace and then sticking the user and user-session keyrings into
      that.  It can then be searched to retrieve them.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Jann Horn <jannh@google.com>
      0f44e4d9
    • David Howells's avatar
      keys: Namespace keyring names · b206f281
      David Howells authored
      
      Keyring names are held in a single global list that any process can pick
      from by means of keyctl_join_session_keyring (provided the keyring grants
      Search permission).  This isn't very container friendly, however.
      
      Make the following changes:
      
       (1) Make default session, process and thread keyring names begin with a
           '.' instead of '_'.
      
       (2) Keyrings whose names begin with a '.' aren't added to the list.  Such
           keyrings are system specials.
      
       (3) Replace the global list with per-user_namespace lists.  A keyring adds
           its name to the list for the user_namespace that it is currently in.
      
       (4) When a user_namespace is deleted, it just removes itself from the
           keyring name list.
      
      The global keyring_name_lock is retained for accessing the name lists.
      This allows (4) to work.
      
      This can be tested by:
      
      	# keyctl newring foo @s
      	995906392
      	# unshare -U
      	$ keyctl show
      	...
      	 995906392 --alswrv  65534 65534   \_ keyring: foo
      	...
      	$ keyctl session foo
      	Joined session keyring: 935622349
      
      As can be seen, a new session keyring was created.
      
      The capability bit KEYCTL_CAPS1_NS_KEYRING_NAME is set if the kernel is
      employing this feature.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Eric W. Biederman <ebiederm@xmission.com>
      b206f281
    • David Howells's avatar
      keys: Add a 'recurse' flag for keyring searches · dcf49dbc
      David Howells authored
      
      Add a 'recurse' flag for keyring searches so that the flag can be omitted
      and recursion disabled, thereby allowing just the nominated keyring to be
      searched and none of the children.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      dcf49dbc
    • David Howells's avatar
      keys: Cache the hash value to avoid lots of recalculation · 355ef8e1
      David Howells authored
      
      Cache the hash of the key's type and description in the index key so that
      we're not recalculating it every time we look at a key during a search.
      The hash function does a bunch of multiplications, so evading those is
      probably worthwhile - especially as this is done for every key examined
      during a search.
      
      This also allows the methods used by assoc_array to get chunks of index-key
      to be simplified.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      355ef8e1
    • David Howells's avatar
      keys: Simplify key description management · f771fde8
      David Howells authored
      
      Simplify key description management by cramming the word containing the
      length with the first few chars of the description also.  This simplifies
      the code that generates the index-key used by assoc_array.  It should speed
      up key searching a bit too.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      f771fde8
    • David Howells's avatar
      keys: Kill off request_key_async{,_with_auxdata} · 3b8c4a08
      David Howells authored
      
      Kill off request_key_async{,_with_auxdata}() as they're not currently used.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      3b8c4a08
  12. Jun 24, 2019
  13. Jun 19, 2019
    • Matthew Garrett's avatar
      IMA: support for per policy rule template formats · 19453ce0
      Matthew Garrett authored
      
      Admins may wish to log different measurements using different IMA
      templates. Add support for overriding the default template on a per-rule
      basis.
      
      Inspired-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarMatthew Garrett <mjg59@google.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      19453ce0
    • David Howells's avatar
      keys: Cache result of request_key*() temporarily in task_struct · 7743c48e
      David Howells authored
      
      If a filesystem uses keys to hold authentication tokens, then it needs a
      token for each VFS operation that might perform an authentication check -
      either by passing it to the server, or using to perform a check based on
      authentication data cached locally.
      
      For open files this isn't a problem, since the key should be cached in the
      file struct since it represents the subject performing operations on that
      file descriptor.
      
      During pathwalk, however, there isn't anywhere to cache the key, except
      perhaps in the nameidata struct - but that isn't exposed to the
      filesystems.  Further, a pathwalk can incur a lot of operations, calling
      one or more of the following, for instance:
      
      	->lookup()
      	->permission()
      	->d_revalidate()
      	->d_automount()
      	->get_acl()
      	->getxattr()
      
      on each dentry/inode it encounters - and each one may need to call
      request_key().  And then, at the end of pathwalk, it will call the actual
      operation:
      
      	->mkdir()
      	->mknod()
      	->getattr()
      	->open()
      	...
      
      which may need to go and get the token again.
      
      However, it is very likely that all of the operations on a single
      dentry/inode - and quite possibly a sequence of them - will all want to use
      the same authentication token, which suggests that caching it would be a
      good idea.
      
      To this end:
      
       (1) Make it so that a positive result of request_key() and co. that didn't
           require upcalling to userspace is cached temporarily in task_struct.
      
       (2) The cache is 1 deep, so a new result displaces the old one.
      
       (3) The key is released by exit and by notify-resume.
      
       (4) The cache is cleared in a newly forked process.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      7743c48e
    • David Howells's avatar
      keys: Provide request_key_rcu() · 896f1950
      David Howells authored
      
      Provide a request_key_rcu() function that can be used to request a key
      under RCU conditions.  It can only search and check permissions; it cannot
      allocate a new key, upcall or wait for an upcall to complete.  It may
      return a partially constructed key.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      896f1950
Loading