linux-stable/include
Kees Cook 3864881bab kmsg: honor dmesg_restrict sysctl on /dev/kmsg
commit 637241a900 upstream.

The dmesg_restrict sysctl currently covers the syslog method for access
dmesg, however /dev/kmsg isn't covered by the same protections.  Most
people haven't noticed because util-linux dmesg(1) defaults to using the
syslog method for access in older versions.  With util-linux dmesg(1)
defaults to reading directly from /dev/kmsg.

To fix /dev/kmsg, let's compare the existing interfaces and what they
allow:

 - /proc/kmsg allows:
  - open (SYSLOG_ACTION_OPEN) if CAP_SYSLOG since it uses a destructive
    single-reader interface (SYSLOG_ACTION_READ).
  - everything, after an open.

 - syslog syscall allows:
  - anything, if CAP_SYSLOG.
  - SYSLOG_ACTION_READ_ALL and SYSLOG_ACTION_SIZE_BUFFER, if
    dmesg_restrict==0.
  - nothing else (EPERM).

The use-cases were:
 - dmesg(1) needs to do non-destructive SYSLOG_ACTION_READ_ALLs.
 - sysklog(1) needs to open /proc/kmsg, drop privs, and still issue the
   destructive SYSLOG_ACTION_READs.

AIUI, dmesg(1) is moving to /dev/kmsg, and systemd-journald doesn't
clear the ring buffer.

Based on the comments in devkmsg_llseek, it sounds like actions besides
reading aren't going to be supported by /dev/kmsg (i.e.
SYSLOG_ACTION_CLEAR), so we have a strict subset of the non-destructive
syslog syscall actions.

To this end, move the check as Josh had done, but also rename the
constants to reflect their new uses (SYSLOG_FROM_CALL becomes
SYSLOG_FROM_READER, and SYSLOG_FROM_FILE becomes SYSLOG_FROM_PROC).
SYSLOG_FROM_READER allows non-destructive actions, and SYSLOG_FROM_PROC
allows destructive actions after a capabilities-constrained
SYSLOG_ACTION_OPEN check.

 - /dev/kmsg allows:
  - open if CAP_SYSLOG or dmesg_restrict==0
  - reading/polling, after open

Addresses https://bugzilla.redhat.com/show_bug.cgi?id=903192

[akpm@linux-foundation.org: use pr_warn_once()]
Signed-off-by: Kees Cook <keescook@chromium.org>
Reported-by: Christian Kujau <lists@nerdbynature.de>
Tested-by: Josh Boyer <jwboyer@redhat.com>
Cc: Kay Sievers <kay@vrfy.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-06-20 12:01:29 -07:00
..
acpi ACPI / PM: Allow device power states to be used for CONFIG_PM unset 2013-06-07 12:53:23 -07:00
asm-generic mm: allow arch code to control the user page table ceiling 2013-05-07 20:33:09 -07:00
clocksource ImgTec Meta architecture changes for v3.9-rc1 2013-03-03 12:06:09 -08:00
crypto
drm drm/radeon: add new richland pci ids 2013-05-11 07:18:35 -07:00
keys
linux kmsg: honor dmesg_restrict sysctl on /dev/kmsg 2013-06-20 12:01:29 -07:00
math-emu
media [media] media: ov7670: Add possibility to disable pixclk during hblank 2013-02-08 14:35:06 -02:00
memory
misc
net Bluetooth: Fix mgmt handling of power on failures 2013-06-20 12:01:28 -07:00
pcmcia
ras edac: add support for error type "Info" 2013-02-21 14:16:27 -03:00
rdma IB/core: Add "type 2" memory windows support 2013-02-21 11:51:45 -08:00
rxrpc
scsi libfc, fcoe, bnx2fc: Split fc_disc_init into fc_disc_{init, config} 2013-03-25 16:03:03 -07:00
sound ALSA: emu10k1: Fix dock firmware loading 2013-05-07 20:33:09 -07:00
target target: Re-instate sess_wait_list for target_wait_for_sess_cmds 2013-06-07 12:53:35 -07:00
trace Revert "block: add missing block_bio_complete() tracepoint" 2013-04-18 09:00:26 -07:00
uapi virtio_console: fix uapi header 2013-05-24 11:36:03 -07:00
video ARM: at91: fix LCD-wiring mode 2013-03-13 11:05:04 +01:00
xen xen-netfront: reduce gso_max_size to account for max TCP header 2013-06-07 12:53:36 -07:00
Kbuild UAPI: Remove empty Kbuild files 2013-01-02 17:36:10 -08:00