Skip to content
Snippets Groups Projects
  1. Jul 17, 2019
  2. Jul 15, 2019
    • Mauro Carvalho Chehab's avatar
      docs: locking: convert docs to ReST and rename to *.rst · 387b1468
      Mauro Carvalho Chehab authored
      
      Convert the locking documents to ReST and add them to the
      kernel development book where it belongs.
      
      Most of the stuff here is just to make Sphinx to properly
      parse the text file, as they're already in good shape,
      not requiring massive changes in order to be parsed.
      
      The conversion is actually:
        - add blank lines and identation in order to identify paragraphs;
        - fix tables markups;
        - add some lists markups;
        - mark literal blocks;
        - adjust title markups.
      
      At its new index.rst, let's add a :orphan: while this is not linked to
      the main index.rst file, in order to avoid build warnings.
      
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Acked-by: default avatarFederico Vaga <federico.vaga@vaga.pv.it>
      387b1468
  3. Jul 12, 2019
  4. Jul 11, 2019
  5. Jul 08, 2019
  6. Jul 05, 2019
  7. Jul 04, 2019
  8. Jul 03, 2019
  9. Jul 02, 2019
  10. Jul 01, 2019
  11. Jun 28, 2019
  12. 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
  13. Jun 26, 2019
    • 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
    • Ferdinand Blomqvist's avatar
      rslib: Fix remaining decoder flaws · 991305de
      Ferdinand Blomqvist authored
      
      The decoder is flawed in the following ways:
      
      - The decoder sometimes fails silently, i.e. it announces success but
        returns a word that is not a codeword.
      
      - The return value of the decoder is incoherent with respect to how
        fixed erasures are counted. If the word to be decoded is a codeword,
        then the decoder always returns zero even if some erasures are given.
        On the other hand, if the word to be decoded contains errors, then the
        number of erasures is always included in the count of corrected
        symbols. So the decoder handles erasures without symbol corruption
        inconsistently. This inconsistency probably doesn't affect anyone
        using the decoder, but it is inconsistent with the documentation.
      
      - The error positions returned in eras_pos include all erasures, but the
        corrections are only set in the correction buffer if there actually is
        a symbol error. So if there are erasures without symbol corruption,
        then the correction buffer will contain errors (unless initialized to
        zero before calling the decoder) or some values will be unset (if the
        correction buffer is uninitialized).
      
      - When correcting data in-place the decoder does not correct errors in
        the parity. On the other hand, when returning the errors in correction
        buffers, errors in the parity are included.
      
      The respective fixed are:
      
      - The syndrome of a codeword is always zero, and the syndrome is linear,
        .i.e, S(x+e) = S(x) + S(e). So compute the syndrome for the error and
        check whether it equals the syndrome of the received word. If it does,
        then we have decoded to a valid codeword, otherwise we know that we
        have an uncorrectable error. Fortunately, some unrecoverable error
        conditions can be detected earlier in the decoding, which saves some
        processing power.
      
      - Simply count and return the number of symbols actually corrected.
      
      - Make sure to only return positions where symbols were corrected.
      
      - Also fix errors in parity when correcting in-place. Another option
        would be to completely disregard errors in the parity, but then the
        interface makes it impossible to write tests that test for silent
        failures.
      
      Other changes:
      
      - Only fill the correction buffer and error position buffer if both of
        them are provided. Otherwise correct in place. Previously the error
        position buffer was always populated with the positions of the
        corrected errors, irrespective of whether a correction buffer was
        supplied or not. The rationale for this change is that there seems to
        be two use cases for the decoder; correct in-place or use the
        correction buffers. The caller does not need the positions of the
        corrected errors when in-place correction is used. If in-place
        correction is not used, then both the correction buffer and error
        position buffer need to be populated.
      
      Signed-off-by: default avatarFerdinand Blomqvist <ferdinand.blomqvist@gmail.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Link: https://lkml.kernel.org/r/20190620141039.9874-8-ferdinand.blomqvist@gmail.com
      991305de
    • Ferdinand Blomqvist's avatar
      rslib: Update documentation · 38cbae14
      Ferdinand Blomqvist authored
      
      The decoder returns the number of corrected symbols, not bits.
      The caller provided syndrome must be in index form.
      
      Signed-off-by: default avatarFerdinand Blomqvist <ferdinand.blomqvist@gmail.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Link: https://lkml.kernel.org/r/20190620141039.9874-7-ferdinand.blomqvist@gmail.com
      38cbae14
    • Ferdinand Blomqvist's avatar
      rslib: Fix handling of of caller provided syndrome · ef4d6a85
      Ferdinand Blomqvist authored
      
      Check if the syndrome provided by the caller is zero, and act
      accordingly.
      
      Signed-off-by: default avatarFerdinand Blomqvist <ferdinand.blomqvist@gmail.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Link: https://lkml.kernel.org/r/20190620141039.9874-6-ferdinand.blomqvist@gmail.com
      ef4d6a85
    • Ferdinand Blomqvist's avatar
      rslib: decode_rs: Code cleanup · 647cc9ec
      Ferdinand Blomqvist authored
      
      Nothing useful was done after the finish label when count is negative so
      return directly instead of jumping to finish.
      
      Signed-off-by: default avatarFerdinand Blomqvist <ferdinand.blomqvist@gmail.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Link: https://lkml.kernel.org/r/20190620141039.9874-5-ferdinand.blomqvist@gmail.com
      647cc9ec
    • Ferdinand Blomqvist's avatar
      rslib: decode_rs: Fix length parameter check · a343536f
      Ferdinand Blomqvist authored
      
      The length of the data load must be at least one. Or in other words,
      there must be room for at least 1 data and nroots parity symbols after
      shortening the RS code.
      
      Signed-off-by: default avatarFerdinand Blomqvist <ferdinand.blomqvist@gmail.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Link: https://lkml.kernel.org/r/20190620141039.9874-4-ferdinand.blomqvist@gmail.com
      a343536f
    • Ferdinand Blomqvist's avatar
      rslib: Fix decoding of shortened codes · 2034a42d
      Ferdinand Blomqvist authored
      
      The decoding of shortenend codes is broken. It only works as expected if
      there are no erasures.
      
      When decoding with erasures, Lambda (the error and erasure locator
      polynomial) is initialized from the given erasure positions. The pad
      parameter is not accounted for by the initialisation code, and hence
      Lambda is initialized from incorrect erasure positions.
      
      The fix is to adjust the erasure positions by the supplied pad.
      
      Signed-off-by: default avatarFerdinand Blomqvist <ferdinand.blomqvist@gmail.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Link: https://lkml.kernel.org/r/20190620141039.9874-3-ferdinand.blomqvist@gmail.com
      2034a42d
    • Ferdinand Blomqvist's avatar
      rslib: Add tests for the encoder and decoder · 4b4f3acc
      Ferdinand Blomqvist authored
      
      A Reed-Solomon code with minimum distance d can correct any error and
      erasure pattern that satisfies 2 * #error + #erasures < d. If the
      error correction capacity is exceeded, then correct decoding cannot be
      guaranteed. The decoder must, however, return a valid codeword or report
      failure.
      
      There are two main tests:
      
      - Check for correct behaviour up to the error correction capacity
      - Check for correct behaviour beyond error corrupted capacity
      
      Both tests are simple:
      
      1. Generate random data
      2. Encode data with the chosen code
      3. Add errors and erasures to data
      4. Decode the corrupted word
      5. Check for correct behaviour
      
      When testing up to capacity we test for:
      
      - Correct decoding
      - Correct return value (i.e. the number of corrected symbols)
      - That the returned error positions are correct
      
      There are two kinds of erasures; the erased symbol can be corrupted or
      not. When counting the number of corrected symbols, erasures without
      symbol corruption should not be counted. Similarly, the returned error
      positions should only include positions where a correction is necessary.
      
      We run the up to capacity tests for three different interfaces of
      decode_rs:
      
      - Use the correction buffers
      - Use the correction buffers with syndromes provided by the caller
      - Error correction in place (does not check the error positions)
      
      When testing beyond capacity test for silent failures. A silent failure is
      when the decoder returns success but the returned word is not a valid
      codeword.
      
      There are a couple of options for the tests:
      
      - Verbosity.
      
      - Whether to test for correct behaviour beyond capacity. Default is to
        test beyond capacity.
      
      - Whether to allow erasures without symbol corruption. Defaults to yes.
      
      Note that the tests take a couple of minutes to complete.
      
      Signed-off-by: default avatarFerdinand Blomqvist <ferdinand.blomqvist@gmail.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Link: https://lkml.kernel.org/r/20190620141039.9874-2-ferdinand.blomqvist@gmail.com
      4b4f3acc
    • Thomas Gleixner's avatar
      lib/vdso: Make delta calculation work correctly · 9d90b93b
      Thomas Gleixner authored
      
      The x86 vdso implementation on which the generic vdso library is based on
      has subtle (unfortunately undocumented) twists:
      
       1) The code assumes that the clocksource mask is U64_MAX which means that
          no bits are masked. Which is true for any valid x86 VDSO clocksource.
          Stupidly it still did the mask operation for no reason and at the wrong
          place right after reading the clocksource.
      
       2) It contains a sanity check to catch the case where slightly
          unsynchronized TSC values can be observed which would cause the delta
          calculation to make a huge jump. It therefore checks whether the
          current TSC value is larger than the value on which the current
          conversion is based on. If it's not larger the base value is used to
          prevent time jumps.
      
      #1 Is not only stupid for the X86 case because it does the masking for no
      reason it is also completely wrong for clocksources with a smaller mask
      which can legitimately wrap around during a conversion period. The core
      timekeeping code does it correct by applying the mask after the delta
      calculation:
      
      	(now - base) & mask
      
      #2 is equally broken for clocksources which have smaller masks and can wrap
      around during a conversion period because there the now > base check is
      just wrong and causes stale time stamps and time going backwards issues.
      
      Unbreak it by:
      
        1) Removing the mask operation from the clocksource read which makes the
           fallback detection work for all clocksources
      
        2) Replacing the conditional delta calculation with a overrideable inline
           function.
      
      #2 could reuse clocksource_delta() from the timekeeping code but that
      results in a significant performance hit for the x86 VSDO. The timekeeping
      core code must have the non optimized version as it has to operate
      correctly with clocksources which have smaller masks as well to handle the
      case where TSC is discarded as timekeeper clocksource and replaced by HPET
      or pmtimer. For the VDSO there is no replacement clocksource. If TSC is
      unusable the syscall is enforced which does the right thing.
      
      To accommodate to the needs of various architectures provide an
      override-able inline function which defaults to the regular delta
      calculation with masking:
      
      	(now - base) & mask
      
      Override it for x86 with the non-masking and checking version.
      
      This unbreaks the ARM64 syscall fallback operation, allows to use
      clocksources with arbitrary width and preserves the performance
      optimization for x86.
      
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarVincenzo Frascino <vincenzo.frascino@arm.com>
      Cc: linux-arch@vger.kernel.org
      Cc: LAK <linux-arm-kernel@lists.infradead.org>
      Cc: linux-mips@vger.kernel.org
      Cc: linux-kselftest@vger.kernel.org
      Cc: catalin.marinas@arm.com
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: linux@armlinux.org.uk
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: paul.burton@mips.com
      Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
      Cc: salyzyn@android.com
      Cc: pcc@google.com
      Cc: shuah@kernel.org
      Cc: 0x7f454c46@gmail.com
      Cc: linux@rasmusvillemoes.dk
      Cc: huw@codeweavers.com
      Cc: sthotton@marvell.com
      Cc: andre.przywara@arm.com
      Cc: Andy Lutomirski <luto@kernel.org>
      Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1906261159230.32342@nanos.tec.linutronix.de
      9d90b93b
Loading