Skip to content
Snippets Groups Projects
  1. Jul 10, 2018
  2. Jun 12, 2018
    • Kees Cook's avatar
      treewide: kmalloc() -> kmalloc_array() · 6da2ec56
      Kees Cook authored
      
      The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
      patch replaces cases of:
      
              kmalloc(a * b, gfp)
      
      with:
              kmalloc_array(a * b, gfp)
      
      as well as handling cases of:
      
              kmalloc(a * b * c, gfp)
      
      with:
      
              kmalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kmalloc_array(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kmalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The tools/ directory was manually excluded, since it has its own
      implementation of kmalloc().
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kmalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kmalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kmalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kmalloc
      + kmalloc_array
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kmalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kmalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kmalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kmalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kmalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kmalloc(C1 * C2 * C3, ...)
      |
        kmalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kmalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kmalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kmalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kmalloc(sizeof(THING) * C2, ...)
      |
        kmalloc(sizeof(TYPE) * C2, ...)
      |
        kmalloc(C1 * C2 * C3, ...)
      |
        kmalloc(C1 * C2, ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      6da2ec56
  3. Apr 25, 2018
    • Thomas Gleixner's avatar
      rslib: Allocate decoder buffers to avoid VLAs · 45888b40
      Thomas Gleixner authored
      
      To get rid of the variable length arrays on stack in the RS decoder it's
      necessary to allocate the decoder buffers per control structure instance.
      
      All usage sites have been checked for potential parallel decoder usage and
      fixed where necessary. Kees confirmed that the pstore decoding is strictly
      single threaded so there should be no surprises.
      
      Allocate them in the rs control structure sized depending on the number of
      roots for the chosen codec and adapt the decoder code to make use of them.
      
      Document the fact that decode operations based on a particular rs control
      instance cannot run in parallel and the caller has to ensure that as it's
      not possible to provide a proper locking construct which fits all use
      cases.
      
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Cc: Kernel Hardening <kernel-hardening@lists.openwall.com>
      Cc: Richard Weinberger <richard@nod.at>
      Cc: Mike Snitzer <snitzer@redhat.com>
      Cc: Anton Vorontsov <anton@enomsg.org>
      Cc: Colin Cross <ccross@android.com>
      Cc: Andrew Morton <akpm@linuxfoundation.org>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Alasdair Kergon <agk@redhat.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      45888b40
    • Thomas Gleixner's avatar
      rslib: Split rs control struct · 21633981
      Thomas Gleixner authored
      
      The decoder library uses variable length arrays on stack. To get rid of
      them it would be simple to allocate fixed length arrays on stack, but those
      might become rather large. The other solution is to allocate the buffers in
      the rs control structure, but this cannot be done as long as the structure
      can be shared by several users. Sharing is desired because the RS polynom
      tables are large and initialization is time consuming.
      
      To solve this split the codec information out of the control structure and
      have a pointer to a shared codec in it. Instantiate the control structure
      for each user, create a new codec if no shareable is avaiable yet.  Adjust
      all affected usage sites to the new scheme.
      
      This allows to add per instance decoder buffers to the control structure
      later on.
      
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Acked-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Cc: Kernel Hardening <kernel-hardening@lists.openwall.com>
      Cc: Richard Weinberger <richard@nod.at>
      Cc: Mike Snitzer <snitzer@redhat.com>
      Cc: Anton Vorontsov <anton@enomsg.org>
      Cc: Colin Cross <ccross@android.com>
      Cc: Andrew Morton <akpm@linuxfoundation.org>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Alasdair Kergon <agk@redhat.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      21633981
    • Thomas Gleixner's avatar
      rslib: Simplify error path · a85e126a
      Thomas Gleixner authored
      
      The four error path labels in rs_init() can be reduced to one by allocating
      the struct with kzalloc so the pointers in the struct are NULL and can be
      unconditionally handed in to kfree() because they either point to an
      allocation or are NULL.
      
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      a85e126a
    • Thomas Gleixner's avatar
      rslib: Remove GPL boilerplate · 689c6efd
      Thomas Gleixner authored
      
      Now that SPDX identifiers are in place, remove the GPL boiler plate
      text. Leave the notices which document that Phil Karn granted permission in
      place (encode/decode source code). The modified files are code written for
      the kernel by me.
      
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Cc: Kernel Hardening <kernel-hardening@lists.openwall.com>
      Cc: Richard Weinberger <richard@nod.at>
      Cc: Mike Snitzer <snitzer@redhat.com>
      Cc: Anton Vorontsov <anton@enomsg.org>
      Cc: Colin Cross <ccross@android.com>
      Cc: Andrew Morton <akpm@linuxfoundation.org>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Alasdair Kergon <agk@redhat.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      689c6efd
    • Thomas Gleixner's avatar
      rslib: Add SPDX identifiers · dc8f923e
      Thomas Gleixner authored
      The Reed-Solomon library is based on code from Phil Karn who granted
      permission to import it into the kernel under the GPL V2.
      
      See commit 15b5423757a7 ("Shared Reed-Solomon ECC library") in the history
      git tree at: git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git
      
      
      
        ...
        The encoder/decoder code is lifted from the GPL'd userspace RS-library
        written by Phil Karn. I modified/wrapped it to provide the different
        functions which we need in the MTD/NAND code.
        ...
      Signed-Off-By: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-Off-By: default avatarDavid Woodhouse <dwmw2@infradead.org>
        "No objections at all. Just keep the authorship notices." -- Phil Karn
      
      Add the proper SPDX identifiers according to
      Documentation/process/license-rules.rst.
      
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Cc: Kernel Hardening <kernel-hardening@lists.openwall.com>
      Cc: Richard Weinberger <richard@nod.at>
      Cc: Mike Snitzer <snitzer@redhat.com>
      Cc: Anton Vorontsov <anton@enomsg.org>
      Cc: Colin Cross <ccross@android.com>
      Cc: Andrew Morton <akpm@linuxfoundation.org>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Alasdair Kergon <agk@redhat.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      dc8f923e
    • Thomas Gleixner's avatar
      rslib: Cleanup top level comments · 3413e189
      Thomas Gleixner authored
      
      File references and stale CVS ids are really not useful.
      
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Cc: Kernel Hardening <kernel-hardening@lists.openwall.com>
      Cc: Richard Weinberger <richard@nod.at>
      Cc: Mike Snitzer <snitzer@redhat.com>
      Cc: Anton Vorontsov <anton@enomsg.org>
      Cc: Colin Cross <ccross@android.com>
      Cc: Andrew Morton <akpm@linuxfoundation.org>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Alasdair Kergon <agk@redhat.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      3413e189
    • Thomas Gleixner's avatar
      rslib: Cleanup whitespace damage · cc4b86e4
      Thomas Gleixner authored
      
      Instead of mixing the whitespace cleanup into functional changes, mop it up
      first.
      
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Cc: Kernel Hardening <kernel-hardening@lists.openwall.com>
      Cc: Richard Weinberger <richard@nod.at>
      Cc: Mike Snitzer <snitzer@redhat.com>
      Cc: Anton Vorontsov <anton@enomsg.org>
      Cc: Colin Cross <ccross@android.com>
      Cc: Andrew Morton <akpm@linuxfoundation.org>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Alasdair Kergon <agk@redhat.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      cc4b86e4
    • Thomas Gleixner's avatar
      rslib: Add GFP aware init function · 83a530e1
      Thomas Gleixner authored
      
      The rslib usage in dm/verity_fec is broken because init_rs() can nest in
      GFP_NOIO mempool allocations as init_rs() is invoked from the mempool alloc
      callback.
      
      Provide a variant which takes gfp_t flags as argument.
      
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: Mike Snitzer <snitzer@redhat.com>
      Cc: Alasdair Kergon <agk@redhat.com>
      Cc: Neil Brown <neilb@suse.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      83a530e1
  4. Apr 19, 2008
  5. Oct 20, 2007
  6. May 02, 2007
  7. Oct 03, 2006
  8. Jun 25, 2006
  9. Mar 23, 2006
  10. Nov 07, 2005
  11. Apr 16, 2005
    • Linus Torvalds's avatar
      Linux-2.6.12-rc2 · 1da177e4
      Linus Torvalds authored
      Initial git repository build. I'm not bothering with the full history,
      even though we have it. We can create a separate "historical" git
      archive of that later if we want to, and in the meantime it's about
      3.2GB when imported into git - space that would just make the early
      git days unnecessarily complicated, when we don't have a lot of good
      infrastructure for it.
      
      Let it rip!
Loading