[kernel] Honor dmesg_restrict for /dev/kmsg (rhbz 903192)

Josh Boyer jwboyer at fedoraproject.org
Mon Feb 25 15:01:37 UTC 2013


commit c040d8cac33ad4e991767be5acc66a8fada2a0a1
Author: Josh Boyer <jwboyer at redhat.com>
Date:   Mon Feb 25 10:00:31 2013 -0500

    Honor dmesg_restrict for /dev/kmsg (rhbz 903192)

 ...g-Honor-dmesg_restrict-sysctl-on-dev-kmsg.patch |   46 ++++++++++++++++++++
 kernel.spec                                        |    7 +++
 2 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/0001-kmsg-Honor-dmesg_restrict-sysctl-on-dev-kmsg.patch b/0001-kmsg-Honor-dmesg_restrict-sysctl-on-dev-kmsg.patch
new file mode 100644
index 0000000..acaf5f8
--- /dev/null
+++ b/0001-kmsg-Honor-dmesg_restrict-sysctl-on-dev-kmsg.patch
@@ -0,0 +1,46 @@
+From feaf4959c30d0640093a607c577940d3e9351076 Mon Sep 17 00:00:00 2001
+From: Josh Boyer <jwboyer at redhat.com>
+Date: Fri, 22 Feb 2013 11:47:37 -0500
+Subject: [PATCH] kmsg: Honor dmesg_restrict sysctl on /dev/kmsg
+
+Originally, the addition of the dmesg_restrict covered both the syslog
+method of accessing dmesg, as well as /dev/kmsg itself.  This was done
+indirectly by security_syslog calling cap_syslog before doing any LSM
+checks.
+
+However, commit 12b3052c3ee (capabilities/syslog: open code cap_syslog
+logic to fix build failure) moved the code around and pushed the checks
+into the caller itself.  That seems to have inadvertently dropped the
+checks for dmesg_restrict on /dev/kmsg.  Most people haven't noticed
+because util-linux dmesg(1) defaults to using the syslog method for
+access in older versions.  With util-linux 2.22 and a kernel newer than
+3.5, dmesg(1) defaults to reading directly from /dev/kmsg.
+
+Fix this by making an explicit check in the devkmsg_open function.
+
+This fixes https://bugzilla.redhat.com/show_bug.cgi?id=903192
+
+Reported-by: Christian Kujau <lists at nerdbynature.de>
+CC: stable at vger.kernel.org
+Signed-off-by: Josh Boyer <jwboyer at redhat.com>
+---
+ kernel/printk.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/kernel/printk.c b/kernel/printk.c
+index f24633a..398ef9a 100644
+--- a/kernel/printk.c
++++ b/kernel/printk.c
+@@ -615,6 +615,9 @@ static int devkmsg_open(struct inode *inode, struct file *file)
+ 	struct devkmsg_user *user;
+ 	int err;
+ 
++	if (dmesg_restrict && !capable(CAP_SYSLOG))
++		return -EACCES;
++
+ 	/* write-only does not need any file context */
+ 	if ((file->f_flags & O_ACCMODE) == O_WRONLY)
+ 		return 0;
+-- 
+1.8.1.2
+
diff --git a/kernel.spec b/kernel.spec
index 23f5a7e..c99d328 100644
--- a/kernel.spec
+++ b/kernel.spec
@@ -739,6 +739,9 @@ Patch21251: sock_diag-Fix-out-of-bounds-access-to-sock_diag_handlers.patch
 #rhbz 812111
 Patch21260: alps-v2.patch
 
+#rhbz 903192
+Patch21261: 0001-kmsg-Honor-dmesg_restrict-sysctl-on-dev-kmsg.patch
+
 Patch22000: weird-root-dentry-name-debug.patch
 
 #selinux ptrace child permissions
@@ -1435,6 +1438,9 @@ ApplyPatch alps-v2.patch
 #CVE-2013-1763 rhbz 915052,915057
 ApplyPatch sock_diag-Fix-out-of-bounds-access-to-sock_diag_handlers.patch
 
+#rhbz 903192
+ApplyPatch 0001-kmsg-Honor-dmesg_restrict-sysctl-on-dev-kmsg.patch
+
 # END OF PATCH APPLICATIONS
 
 %endif
@@ -2291,6 +2297,7 @@ fi
 #                 ||     ||
 %changelog
 * Mon Feb 25 2013 Josh Boyer <jwboyer at redhat.com> - 3.9.0-0.rc0.git7.1
+- Honor dmesg_restrict for /dev/kmsg (rhbz 903192)
 - Linux v3.8-7888-gab78265
 
 * Sun Feb 24 2013 Josh Boyer <jwboyer at redhat.com> - 3.9.0-0.rc0.git6.1


More information about the scm-commits mailing list