From ce6ada35bdf710d16582cc4869c26722547e6f11 Mon Sep 17 00:00:00 2001
From: "Serge E. Hallyn" <serge@hallyn.com>
Date: Thu, 25 Nov 2010 17:11:32 +0000
Subject: security: Define CAP_SYSLOG

Privileged syslog operations currently require CAP_SYS_ADMIN.  Split
this off into a new CAP_SYSLOG privilege which we can sanely take away
from a container through the capability bounding set.

With this patch, an lxc container can be prevented from messing with
the host's syslog (i.e. dmesg -c).

Changelog: mar 12 2010: add selinux capability2:cap_syslog perm
Changelog: nov 22 2010:
	. port to new kernel
	. add a WARN_ONCE if userspace isn't using CAP_SYSLOG

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Andrew G. Morgan <morgan@kernel.org>
Acked-By: Kees Cook <kees.cook@canonical.com>
Cc: James Morris <jmorris@namei.org>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: "Christopher J. PeBenito" <cpebenito@tresys.com>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: James Morris <jmorris@namei.org>
---
 kernel/printk.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

(limited to 'kernel/printk.c')

diff --git a/kernel/printk.c b/kernel/printk.c
index 9a2264fc42c..0712380737b 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -283,8 +283,14 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
 			return -EPERM;
 		if ((type != SYSLOG_ACTION_READ_ALL &&
 		     type != SYSLOG_ACTION_SIZE_BUFFER) &&
-		    !capable(CAP_SYS_ADMIN))
+		    !capable(CAP_SYSLOG)) {
+			/* remove after 2.6.38 */
+			if (capable(CAP_SYS_ADMIN))
+				WARN_ONCE(1, "Attempt to access syslog with "
+				  "CAP_SYS_ADMIN but no CAP_SYSLOG "
+				  "(deprecated and denied).\n");
 			return -EPERM;
+		}
 	}
 
 	error = security_syslog(type);
-- 
cgit v1.2.3-18-g5258