• Ard Biesheuvel's avatar
    lkdtm: avoid printk() in recursive_loop() · 026c6fa1
    Ard Biesheuvel authored
    The recursive_loop() function is intended as a diagnostic to ensure that
    exhausting the stack is caught and mitigated. Currently, it uses
    pr_info() to ensure that the function has side effects that the compiler
    cannot simply optimize away, so that the stack footprint does not get
    reduced inadvertently.
    
    The typical mitigation for stack overflow is to kill the task, and this
    overflow may occur inside the call to pr_info(), which means it could be
    holding the console lock when this happens. This means that the console
    lock is never going to be released again, preventing the diagnostic
    prints related to the stack overflow handling from being visible on the
    console.
    
    So let's replace the call to pr_info() with a call to
    memzero_explicit(), which is not a 'magic' function name like memset()
    or memcpy(), which the compiler may replace with plain loads and stores.
    To ensure that the stack frames are nested rather than tail-called, put
    the call to memzero_explicit() after the recursive call.
    Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
    Signed-off-by: default avatarKees Cook <keescook@chromium.org>
    Link: https://lore.kernel.org/r/20211007081235.382697-1-ardb@kernel.org
    026c6fa1
bugs.c 14.6 KB