48b6f5c
From feaf4959c30d0640093a607c577940d3e9351076 Mon Sep 17 00:00:00 2001
48b6f5c
From: Josh Boyer <jwboyer@redhat.com>
48b6f5c
Date: Fri, 22 Feb 2013 11:47:37 -0500
48b6f5c
Subject: [PATCH] kmsg: Honor dmesg_restrict sysctl on /dev/kmsg
48b6f5c
48b6f5c
Originally, the addition of the dmesg_restrict covered both the syslog
48b6f5c
method of accessing dmesg, as well as /dev/kmsg itself.  This was done
48b6f5c
indirectly by security_syslog calling cap_syslog before doing any LSM
48b6f5c
checks.
48b6f5c
48b6f5c
However, commit 12b3052c3ee (capabilities/syslog: open code cap_syslog
48b6f5c
logic to fix build failure) moved the code around and pushed the checks
48b6f5c
into the caller itself.  That seems to have inadvertently dropped the
48b6f5c
checks for dmesg_restrict on /dev/kmsg.  Most people haven't noticed
48b6f5c
because util-linux dmesg(1) defaults to using the syslog method for
48b6f5c
access in older versions.  With util-linux 2.22 and a kernel newer than
48b6f5c
3.5, dmesg(1) defaults to reading directly from /dev/kmsg.
48b6f5c
48b6f5c
Fix this by making an explicit check in the devkmsg_open function.
48b6f5c
48b6f5c
This fixes https://bugzilla.redhat.com/show_bug.cgi?id=903192
48b6f5c
48b6f5c
Reported-by: Christian Kujau <lists@nerdbynature.de>
48b6f5c
CC: stable@vger.kernel.org
48b6f5c
Signed-off-by: Josh Boyer <jwboyer@redhat.com>
48b6f5c
---
48b6f5c
 kernel/printk.c | 3 +++
48b6f5c
 1 file changed, 3 insertions(+)
48b6f5c
48b6f5c
diff --git a/kernel/printk.c b/kernel/printk.c
48b6f5c
index f24633a..398ef9a 100644
48b6f5c
--- a/kernel/printk.c
48b6f5c
+++ b/kernel/printk.c
48b6f5c
@@ -615,6 +615,9 @@ static int devkmsg_open(struct inode *inode, struct file *file)
48b6f5c
 	struct devkmsg_user *user;
48b6f5c
 	int err;
48b6f5c
 
48b6f5c
+	if (dmesg_restrict && !capable(CAP_SYSLOG))
48b6f5c
+		return -EACCES;
48b6f5c
+
48b6f5c
 	/* write-only does not need any file context */
48b6f5c
 	if ((file->f_flags & O_ACCMODE) == O_WRONLY)
48b6f5c
 		return 0;
48b6f5c
-- 
48b6f5c
1.8.1.2
48b6f5c