• Ricardo Ribalda's avatar
    kexec: introduce sysctl parameters kexec_load_limit_* · a42aaad2
    Ricardo Ribalda authored
    kexec allows replacing the current kernel with a different one.  This is
    usually a source of concerns for sysadmins that want to harden a system.
    
    Linux already provides a way to disable loading new kexec kernel via
    kexec_load_disabled, but that control is very coard, it is all or nothing
    and does not make distinction between a panic kexec and a normal kexec.
    
    This patch introduces new sysctl parameters, with finer tuning to specify
    how many times a kexec kernel can be loaded.  The sysadmin can set
    different limits for kexec panic and kexec reboot kernels.  The value can
    be modified at runtime via sysctl, but only with a stricter value.
    
    With these new parameters on place, a system with loadpin and verity
    enabled, using the following kernel parameters:
    sysctl.kexec_load_limit_reboot=0 sysct.kexec_load_limit_panic=1 can have a
    good warranty that if initrd tries to load a panic kernel, a malitious
    user will have small chances to replace that kernel with a different one,
    even if they can trigger timeouts on the disk where the panic kernel
    lives.
    
    Link: https://lkml.kernel.org/r/20221114-disable-kexec-reset-v6-3-6a8531a09b9a@chromium.orgSigned-off-by: default avatarRicardo Ribalda <ribalda@chromium.org>
    Reviewed-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
    Acked-by: default avatarBaoquan He <bhe@redhat.com>
    Cc: Bagas Sanjaya <bagasdotme@gmail.com>
    Cc: "Eric W. Biederman" <ebiederm@xmission.com>
    Cc: Guilherme G. Piccoli <gpiccoli@igalia.com> # Steam Deck
    Cc: Joel Fernandes (Google) <joel@joelfernandes.org>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Philipp Rudo <prudo@redhat.com>
    Cc: Ross Zwisler <zwisler@kernel.org>
    Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    a42aaad2
kexec_core.c 32.9 KB