1. Oct 11, 2023
  2. Oct 10, 2023
  3. Sep 29, 2023
  4. Sep 28, 2023
  5. Sep 26, 2023
    • Justin Stitt's avatar
      md: replace deprecated strncpy with memcpy · ceb04163
      Justin Stitt authored
      `strncpy` is deprecated for use on NUL-terminated destination strings
      [1] and as such we should prefer more robust and less ambiguous string
      interfaces.
      
      There are three such strncpy uses that this patch addresses:
      
      The respective destination buffers are:
      1) mddev->clevel
      2) clevel
      3) mddev->metadata_type
      
      We expect mddev->clevel to be NUL-terminated due to its use with format
      strings:
      |       ret = sprintf(page, "%s\n", mddev->clevel);
      
      Furthermore, we can see that mddev->clevel is not expected to be
      NUL-padded as `md_clean()` merely set's its first byte to NULL -- not
      the entire buffer:
      |       static void md_clean(struct mddev *mddev)
      |       {
      |       	mddev->array_sectors = 0;
      |       	mddev->external_size = 0;
      |               ...
      |       	mddev->level = LEVEL_NONE;
      |       	mddev->clevel[0] = 0;
      |               ...
      
      A suitable replacement for this instance is `memcpy` as we know the
      number of bytes to copy and perform manual NUL-termination at a
      specified offset. This really decays to just a byte copy from one buffer
      to another. `strscpy` is also a considerable replacement but using
      `slen` as the length argument would result in truncation of the last
      byte unless something like `slen + 1` was provided which isn't the most
      idiomatic strscpy usage.
      
      For the next case, the destination buffer `clevel` is expected to be
      NUL-terminated based on its usage within kstrtol() which expects
      NUL-terminated strings. Note that, in context, this code removes a
      trailing newline which is seemingly not required as kstrtol() can handle
      trailing newlines implicitly. However, there exists further usage of
      clevel (or buf) that would also like to have the newline removed. All in
      all, with similar reasoning to the first case, let's just use memcpy as
      this is just a byte copy and NUL-termination is handled manually.
      
      The third and final case concerning `mddev->metadata_type` is more or
      less the same as the other two. We expect that it be NUL-terminated
      based on its usage with seq_printf:
      |       seq_printf(seq, " super external:%s",
      |       	   mddev->metadata_type);
      ... and we can surmise that NUL-padding isn't required either due to how
      it is handled in md_clean():
      |       static void md_clean(struct mddev *mddev)
      |       {
      |       ...
      |       mddev->metadata_type[0] = 0;
      |       ...
      
      So really, all these instances have precisely calculated lengths and
      purposeful NUL-termination so we can just use memcpy to remove ambiguity
      surrounding strncpy.
      
      Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
      Link: https://github.com/KSPP/linux/issues/90
      
      
      Cc: linux-hardening@vger.kernel.org
      Signed-off-by: default avatarJustin Stitt <justinstitt@google.com>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20230925-strncpy-drivers-md-md-c-v1-1-2b0093b89c2b@google.com
      ceb04163
  6. Sep 23, 2023
  7. Sep 22, 2023
  8. Sep 18, 2023
  9. Sep 17, 2023
    • Song Liu's avatar
      x86/purgatory: Remove LTO flags · 75b2f7e4
      Song Liu authored
      -flto* implies -ffunction-sections. With LTO enabled, ld.lld generates
      multiple .text sections for purgatory.ro:
      
        $ readelf -S purgatory.ro  | grep " .text"
          [ 1] .text             PROGBITS         0000000000000000  00000040
          [ 7] .text.purgatory   PROGBITS         0000000000000000  000020e0
          [ 9] .text.warn        PROGBITS         0000000000000000  000021c0
          [13] .text.sha256_upda PROGBITS         0000000000000000  000022f0
          [15] .text.sha224_upda PROGBITS         0000000000000000  00002be0
          [17] .text.sha256_fina PROGBITS         0000000000000000  00002bf0
          [19] .text.sha224_fina PROGBITS         0000000000000000  00002cc0
      
      This causes WARNING from kexec_purgatory_setup_sechdrs():
      
        WARNING: CPU: 26 PID: 110894 at kernel/kexec_file.c:919
        kexec_load_purgatory+0x37f/0x390
      
      Fix this by disabling LTO for purgatory.
      
      [ AFAICT, x86 is the only arch that supports LTO and purgatory. ]
      
      We could also fix this with an explicit linker script to rejoin .text.*
      sections back into .text. However, given the benefit of LTOing purgatory
      is small, simply disable the production of more .text.* sections for now.
      
      Fixes: b33fff07
      
       ("x86, build: allow LTO to be selected")
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Reviewed-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Link: https://lore.kernel.org/r/20230914170138.995606-1-song@kernel.org
      75b2f7e4
    • Kirill A. Shutemov's avatar
      x86/boot/compressed: Reserve more memory for page tables · f530ee95
      Kirill A. Shutemov authored
      The decompressor has a hard limit on the number of page tables it can
      allocate. This limit is defined at compile-time and will cause boot
      failure if it is reached.
      
      The kernel is very strict and calculates the limit precisely for the
      worst-case scenario based on the current configuration. However, it is
      easy to forget to adjust the limit when a new use-case arises. The
      worst-case scenario is rarely encountered during sanity checks.
      
      In the case of enabling 5-level paging, a use-case was overlooked. The
      limit needs to be increased by one to accommodate the additional level.
      This oversight went unnoticed until Aaron attempted to run the kernel
      via kexec with 5-level paging and unaccepted memory enabled.
      
      Update wost-case calculations to include 5-level paging.
      
      To address this issue, let's allocate some extra space for page tables.
      128K should be sufficient for any use-case. The logic can be simplified
      by using a single value for all kernel configurations.
      
      [ Also add a warning, should this memory run low - by Dave Hansen. ]
      
      Fixes: 34bbb000
      
       ("x86/boot/compressed: Enable 5-level paging during decompression stage")
      Reported-by: default avatarAaron Lu <aaron.lu@intel.com>
      Signed-off-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Link: https://lore.kernel.org/r/20230915070221.10266-1-kirill.shutemov@linux.intel.com
      f530ee95
    • Linus Torvalds's avatar
      Merge tag 'kbuild-fixes-v6.6' of... · f0b0d403
      Linus Torvalds authored
      Merge tag 'kbuild-fixes-v6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
      
      Pull Kbuild fixes from Masahiro Yamada:
      
       - Fix kernel-devel RPM and linux-headers Deb package
      
       - Fix too long argument list error in 'make modules_install'
      
      * tag 'kbuild-fixes-v6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
        kbuild: avoid long argument lists in make modules_install
        kbuild: fix kernel-devel RPM package and linux-headers Deb package
      f0b0d403