Skip to content
  • Borislav Petkov's avatar
    printk: add kernel parameter to control writes to /dev/kmsg · 750afe7b
    Borislav Petkov authored
    Add a "printk.devkmsg" kernel command line parameter which controls how
    userspace writes into /dev/kmsg.  It has three options:
    
     * ratelimit - ratelimit logging from userspace.
     * on  - unlimited logging from userspace
     * off - logging from userspace gets ignored
    
    The default setting is to ratelimit the messages written to it.
    
    This changes the kernel default setting of "on" to "ratelimit" and we do
    that because we want to keep userspace spamming /dev/kmsg to sane
    levels.  This is especially moot when a small kernel log buffer wraps
    around and messages get lost.  So the ratelimiting setting should be a
    sane setting where kernel messages should have a bit higher chance of
    survival from all the spamming.
    
    It additionally does not limit logging to /dev/kmsg while the system is
    booting if we haven't disabled it on the command line.
    
    Furthermore, we can control the logging from a lower priority sysctl
    interface - kernel.printk_devkmsg.
    
    That interface will succeed only if printk.devkmsg *hasn't* been
    supplied on the command line.  If it has, then printk.devkmsg is a
    one-time setting which remains for the duration of the system lifetime.
    This "locking" of the setting is to prevent userspace from changing the
    logging on us through sysctl(2).
    
    This patch is based on previous patches from Linus and Steven.
    
    [bp@suse.de: fixes]
      Link: http://lkml.kernel.org/r/20160719072344.GC25563@nazgul.tnic
    Link: http://lkml.kernel.org/r/20160716061745.15795-3-bp@alien8.de
    
    
    Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
    Cc: Dave Young <dyoung@redhat.com>
    Cc: Franck Bui <fbui@suse.com>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Steven Rostedt <rostedt@goodmis.org>
    Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    750afe7b