public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Zack Weinberg <zackw@panix.com>
To: Stephen Smalley <sds@tycho.nsa.gov>,
	jmorris@namei.org, Chris Wright <chrisw@sous-sol.org>
Cc: linux-kernel@vger.kernel.org
Subject: [patch 4/4] Distinguish /proc/kmsg access from sys_syslog
Date: Thu, 14 Dec 2006 16:16:43 -0800	[thread overview]
Message-ID: <20061215002334.387333000@panix.com> (raw)
In-Reply-To: 20061215001639.988521000@panix.com

[-- Attachment #1: distinguish_kmsg_security.diff --]
[-- Type: text/plain, Size: 3867 bytes --]

Finally, add a new security class for access to /proc/kmsg, distinct
from the class used for the "read current messages" operations on
sys_syslog.  The dummy and capability modules permit access to
/proc/kmsg to any user (who has somehow acquired an open fd on it);
SELinux is unchanged.  This accomplishes what I was trying to do in
the first place, i.e. enable running klogd unprivileged without a root
shim, in a non-SELinux installation.  Please remember that the
default DAC permissions for /proc/kmsg restrict it to root, so unless
you chmod it in your installation or modify klogd to open the file and
then drop privs, the actual restrictions are unchanged.

zw


Index: linux-2.6/fs/proc/kmsg.c
===================================================================
--- linux-2.6.orig/fs/proc/kmsg.c	2006-12-13 16:36:56.000000000 -0800
+++ linux-2.6/fs/proc/kmsg.c	2006-12-13 16:41:33.000000000 -0800
@@ -23,7 +23,7 @@
 
 static int kmsg_open(struct inode * inode, struct file * file)
 {
-	int error = security_syslog(LSM_KLOG_READ);
+	int error = security_syslog(LSM_KLOG_READ_PROC);
 	if (error)
 		return error;
 	return nonseekable_open(inode, file);
@@ -37,7 +37,7 @@
 static ssize_t kmsg_read(struct file *file, char __user *buf,
 			 size_t count, loff_t *ppos)
 {
-	int error = security_syslog(LSM_KLOG_READ);
+	int error = security_syslog(LSM_KLOG_READ_PROC);
 	if (error)
 		return error;
 	return klog_read(buf, count, !(file->f_flags & O_NONBLOCK));
@@ -45,7 +45,7 @@
 
 static unsigned int kmsg_poll(struct file *file, poll_table *wait)
 {
-	int error = security_syslog(LSM_KLOG_READ);
+	int error = security_syslog(LSM_KLOG_READ_PROC);
 	if (error)
 		return error;
 	return klog_poll(file, wait);
Index: linux-2.6/security/commoncap.c
===================================================================
--- linux-2.6.orig/security/commoncap.c	2006-12-13 16:11:13.000000000 -0800
+++ linux-2.6/security/commoncap.c	2006-12-13 16:41:33.000000000 -0800
@@ -311,7 +311,14 @@
 
 int cap_syslog (int type)
 {
-	if (type != LSM_KLOG_READHIST && !capable(CAP_SYS_ADMIN))
+	/*
+	 * Reading history is allowed to any user, and so is reading
+	 * current messages via /proc/kmsg (by default that file is
+	 * only readable by root, but root is allowed to change that,
+	 * or open it and hand the fd to an unprivileged process).
+	 */
+	if (type != LSM_KLOG_READHIST && type != LSM_KLOG_READ_PROC
+	    && !capable(CAP_SYS_ADMIN))
 		return -EPERM;
 	return 0;
 }
Index: linux-2.6/security/selinux/hooks.c
===================================================================
--- linux-2.6.orig/security/selinux/hooks.c	2006-12-13 16:11:41.000000000 -0800
+++ linux-2.6/security/selinux/hooks.c	2006-12-13 16:41:33.000000000 -0800
@@ -1515,7 +1515,14 @@
 	case LSM_KLOG_CONSOLE:
 		return task_has_system(current, SYSTEM__SYSLOG_CONSOLE);
 
+		/*
+		 * N.B. Unlike the default security model, with
+		 * SELinux active you have to have SYSTEM__SYSLOG_MOD
+		 * privilege to read current messages either with the
+		 * system call or from /proc/kmsg.
+		 */
 	case LSM_KLOG_READ:
+	case LSM_KLOG_READ_PROC:
 	case LSM_KLOG_CLEARHIST:
 	default:
 		return task_has_system(current, SYSTEM__SYSLOG_MOD);
Index: linux-2.6/include/linux/security.h
===================================================================
--- linux-2.6.orig/include/linux/security.h	2006-12-13 16:41:45.000000000 -0800
+++ linux-2.6/include/linux/security.h	2006-12-13 16:42:26.000000000 -0800
@@ -94,6 +94,8 @@
 #define LSM_KLOG_READHIST  1  /* read message history (dmesg) */
 #define LSM_KLOG_CLEARHIST 2  /* clear message history (dmesg -c) */
 #define LSM_KLOG_CONSOLE   3  /* set console log level */
+#define LSM_KLOG_READ_PROC 4  /* read current messages, but from /proc/kmsg
+				rather than the system call */
 
 /* forward declares to avoid warnings */
 struct nfsctl_arg;

--


  parent reply	other threads:[~2006-12-15  0:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-15  0:16 [patch 0/4] /proc/kmsg permissions, take three Zack Weinberg
2006-12-15  0:16 ` [patch 1/4] Add <linux/klog.h> Zack Weinberg
2006-12-15  0:59   ` Randy Dunlap
2006-12-15  1:21     ` Zack Weinberg
2006-12-15  0:16 ` [patch 2/4] permission mapping for sys_syslog operations Zack Weinberg
2006-12-15  1:02   ` Randy Dunlap
2006-12-15  1:21     ` Zack Weinberg
2006-12-15 17:08       ` Randy Dunlap
2006-12-15  0:16 ` [patch 3/4] Refactor do_syslog interface Zack Weinberg
2006-12-15  0:16 ` Zack Weinberg [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-12-24 20:22 [patch 0/4] /proc/kmsg permissions, take four Zack Weinberg
2006-12-24 20:22 ` [patch 4/4] Distinguish /proc/kmsg access from sys_syslog Zack Weinberg
2006-11-13  6:40 [patch 0/4] Syslog permissions, revised Zack Weinberg
2006-11-13  6:40 ` [patch 4/4] Distinguish /proc/kmsg access from sys_syslog Zack Weinberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061215002334.387333000@panix.com \
    --to=zackw@panix.com \
    --cc=chrisw@sous-sol.org \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sds@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox