Skip to content
Snippets Groups Projects
  1. Aug 20, 2024
    • Fan Wu's avatar
      initramfs,lsm: add a security hook to do_populate_rootfs() · 2fea0c26
      Fan Wu authored
      
      This patch introduces a new hook to notify security system that the
      content of initramfs has been unpacked into the rootfs.
      
      Upon receiving this notification, the security system can activate
      a policy to allow only files that originated from the initramfs to
      execute or load into kernel during the early stages of booting.
      
      This approach is crucial for minimizing the attack surface by
      ensuring that only trusted files from the initramfs are operational
      in the critical boot phase.
      
      Signed-off-by: default avatarFan Wu <wufan@linux.microsoft.com>
      [PM: subject line tweak]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      2fea0c26
  2. Apr 11, 2024
  3. Apr 05, 2024
  4. Mar 26, 2024
  5. Feb 24, 2024
    • Baoquan He's avatar
      crash: split crash dumping code out from kexec_core.c · 02aff848
      Baoquan He authored
      Currently, KEXEC_CORE select CRASH_CORE automatically because crash codes
      need be built in to avoid compiling error when building kexec code even
      though the crash dumping functionality is not enabled. E.g
      --------------------
      CONFIG_CRASH_CORE=y
      CONFIG_KEXEC_CORE=y
      CONFIG_KEXEC=y
      CONFIG_KEXEC_FILE=y
      ---------------------
      
      After splitting out crashkernel reservation code and vmcoreinfo exporting
      code, there's only crash related code left in kernel/crash_core.c. Now
      move crash related codes from kexec_core.c to crash_core.c and only build it
      in when CONFIG_CRASH_DUMP=y.
      
      And also wrap up crash codes inside CONFIG_CRASH_DUMP ifdeffery scope,
      or replace inappropriate CONFIG_KEXEC_CORE ifdef with CONFIG_CRASH_DUMP
      ifdef in generic kernel files.
      
      With these changes, crash_core codes are abstracted from kexec codes and
      can be disabled at all if only kexec reboot feature is wanted.
      
      Link: https://lkml.kernel.org/r/20240124051254.67105-5-bhe@redhat.com
      
      
      Signed-off-by: default avatarBaoquan He <bhe@redhat.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Pingfan Liu <piliu@redhat.com>
      Cc: Klara Modin <klarasmodin@gmail.com>
      Cc: Michael Kelley <mhklinux@outlook.com>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Stephen Rothwell <sfr@canb.auug.org.au>
      Cc: Yang Li <yang.lee@linux.alibaba.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      02aff848
  6. Feb 08, 2024
  7. Jan 22, 2024
  8. Dec 15, 2023
  9. Aug 18, 2023
  10. Apr 16, 2023
  11. Feb 03, 2023
  12. Nov 18, 2022
  13. Sep 12, 2022
  14. May 10, 2022
  15. May 07, 2022
    • Eric W. Biederman's avatar
      init: Deal with the init process being a user mode process · 68d85f0a
      Eric W. Biederman authored
      It is silly for user_mode_thread to leave PF_KTHREAD set
      on the resulting task.  Update the init process so that
      it does not care if PF_KTHREAD is set or not.
      
      Ensure do_populate_rootfs flushes all delayed fput work by calling
      task_work_run.  In the rare instance that async_schedule_domain calls
      do_populate_rootfs synchronously it is possible do_populate_rootfs
      will be called directly from the init process.  At which point fput
      will call "task_work_add(current, ..., TWA_RESUME)".  The files on the
      initramfs need to be completely put before we attempt to exec them
      (which is before the code enters userspace).  So call task_work_run
      just in case there are any pending fput operations.
      
      Link: https://lkml.kernel.org/r/20220506141512.516114-5-ebiederm@xmission.com
      
      
      Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
      68d85f0a
  16. Nov 06, 2021
  17. Sep 08, 2021
    • Rasmus Villemoes's avatar
      init: move usermodehelper_enable() to populate_rootfs() · b234ed6d
      Rasmus Villemoes authored
      Currently, usermodehelper is enabled right before PID1 starts going
      through the initcalls. However, any call of a usermodehelper from a
      pure_, core_, postcore_, arch_, subsys_ or fs_ initcall is futile, as
      there is no filesystem contents yet.
      
      Up until commit e7cb072e ("init/initramfs.c: do unpacking
      asynchronously"), such calls, whether via some request_module(), a
      legacy uevent "/sbin/hotplug" notification or something else, would
      just fail silently with (presumably) -ENOENT from
      kernel_execve(). However, that commit introduced the
      wait_for_initramfs() synchronization hook which must be called from
      the usermodehelper exec path right before the kernel_execve, in order
      that request_module() et al done from *after* rootfs_initcall()
      time (i.e. device_ and late_ initcalls) would continue to find a
      populated initramfs as they used to.
      
      Any call of wait_for_initramfs() done before the unpacking has been
      scheduled (i.e. before rootfs_initcall time) must just return
      immediately [and let the caller find an empty file system] in order
      not to deadlock the machine. I mistakenly thought, and my limited
      testing confirmed, that there were no such calls, so I added a
      pr_warn_once() in wait_for_initramfs(). It turns out that one can
      indeed hit request_module() as well as kobject_uevent_env() during
      those early init calls, leading to a user-visible warning in the
      kernel log emitted consistently for certain configurations.
      
      We could just remove the pr_warn_once(), but I think it's better to
      postpone enabling the usermodehelper framework until there is at least
      some chance of finding the executable. That is also a little more
      efficient in that a lot of work done in umh.c will be elided. However,
      it does change the error seen by those early callers from -ENOENT to
      -EBUSY, so there is a risk of a regression if any caller care about
      the exact error value.
      
      Link: https://lkml.kernel.org/r/20210728134638.329060-1-linux@rasmusvillemoes.dk
      
      
      Fixes: e7cb072e ("init/initramfs.c: do unpacking asynchronously")
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Reported-by: default avatarAlexander Egorenkov <egorenar@linux.ibm.com>
      Reported-by: default avatarBruno Goncalves <bgoncalv@redhat.com>
      Reported-by: default avatarHeiner Kallweit <hkallweit1@gmail.com>
      Cc: Luis Chamberlain <mcgrof@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      b234ed6d
  18. May 07, 2021
    • Rasmus Villemoes's avatar
      init/initramfs.c: do unpacking asynchronously · e7cb072e
      Rasmus Villemoes authored
      Patch series "background initramfs unpacking, and CONFIG_MODPROBE_PATH", v3.
      
      These two patches are independent, but better-together.
      
      The second is a rather trivial patch that simply allows the developer to
      change "/sbin/modprobe" to something else - e.g.  the empty string, so
      that all request_module() during early boot return -ENOENT early, without
      even spawning a usermode helper, needlessly synchronizing with the
      initramfs unpacking.
      
      The first patch delegates decompressing the initramfs to a worker thread,
      allowing do_initcalls() in main.c to proceed to the device_ and late_
      initcalls without waiting for that decompression (and populating of
      rootfs) to finish.  Obviously, some of those later calls may rely on the
      initramfs being available, so I've added synchronization points in the
      firmware loader and usermodehelper paths - there might be other places
      that would need this, but so far no one has been able to think of any
      places I have missed.
      
      There's not much to win if most of the functionality needed during boot is
      only available as modules.  But systems with a custom-made .config and
      initramfs can boot faster, partly due to utilizing more than one cpu
      earlier, partly by avoiding known-futile modprobe calls (which would still
      trigger synchronization with the initramfs unpacking, thus eliminating
      most of the first benefit).
      
      This patch (of 2):
      
      Most of the boot process doesn't actually need anything from the
      initramfs, until of course PID1 is to be executed.  So instead of doing
      the decompressing and populating of the initramfs synchronously in
      populate_rootfs() itself, push that off to a worker thread.
      
      This is primarily motivated by an embedded ppc target, where unpacking
      even the rather modest sized initramfs takes 0.6 seconds, which is long
      enough that the external watchdog becomes unhappy that it doesn't get
      attention soon enough.  By doing the initramfs decompression in a worker
      thread, we get to do the device_initcalls and hence start petting the
      watchdog much sooner.
      
      Normal desktops might benefit as well.  On my mostly stock Ubuntu kernel,
      my initramfs is a 26M xz-compressed blob, decompressing to around 126M.
      That takes almost two seconds:
      
      [    0.201454] Trying to unpack rootfs image as initramfs...
      [    1.976633] Freeing initrd memory: 29416K
      
      Before this patch, these lines occur consecutively in dmesg.  With this
      patch, the timestamps on these two lines is roughly the same as above, but
      with 172 lines inbetween - so more than one cpu has been kept busy doing
      work that would otherwise only happen after the populate_rootfs()
      finished.
      
      Should one of the initcalls done after rootfs_initcall time (i.e., device_
      and late_ initcalls) need something from the initramfs (say, a kernel
      module or a firmware blob), it will simply wait for the initramfs
      unpacking to be done before proceeding, which should in theory make this
      completely safe.
      
      But if some driver pokes around in the filesystem directly and not via one
      of the official kernel interfaces (i.e.  request_firmware*(),
      call_usermodehelper*) that theory may not hold - also, I certainly might
      have missed a spot when sprinkling wait_for_initramfs().  So there is an
      escape hatch in the form of an initramfs_async= command line parameter.
      
      Link: https://lkml.kernel.org/r/20210313212528.2956377-1-linux@rasmusvillemoes.dk
      Link: https://lkml.kernel.org/r/20210313212528.2956377-2-linux@rasmusvillemoes.dk
      
      
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Reviewed-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
      Cc: Jessica Yu <jeyu@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Takashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      e7cb072e
  19. Feb 26, 2021
  20. Feb 19, 2021
  21. Dec 11, 2020
  22. Sep 04, 2020
  23. Jul 31, 2020
  24. Jul 30, 2020
Loading