security: Define CAP_SYSLOG
authorSerge E. Hallyn <serge@hallyn.com>
Thu, 25 Nov 2010 17:11:32 +0000 (17:11 +0000)
committerJames Morris <jmorris@namei.org>
Sun, 28 Nov 2010 21:35:12 +0000 (08:35 +1100)
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>
include/linux/capability.h
kernel/printk.c
security/selinux/include/classmap.h

index 90012b9ddbf3e5f999983bf7d2f6e388a99d25a1..fb16a3699b99f682c88bea8cdbb71c0862ca368f 100644 (file)
@@ -246,7 +246,6 @@ struct cpu_vfs_cap_data {
 /* Allow configuration of the secure attention key */
 /* Allow administration of the random device */
 /* Allow examination and configuration of disk quotas */
-/* Allow configuring the kernel's syslog (printk behaviour) */
 /* Allow setting the domainname */
 /* Allow setting the hostname */
 /* Allow calling bdflush() */
@@ -352,7 +351,11 @@ struct cpu_vfs_cap_data {
 
 #define CAP_MAC_ADMIN        33
 
-#define CAP_LAST_CAP         CAP_MAC_ADMIN
+/* Allow configuring the kernel's syslog (printk behaviour) */
+
+#define CAP_SYSLOG           34
+
+#define CAP_LAST_CAP         CAP_SYSLOG
 
 #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
 
index 9a2264fc42cafac30d9264d569e4e673e9617f19..0712380737b39dc42045ec612685fb4f43f0684f 100644 (file)
@@ -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);
index 8858d2b2d4b6ad1dd1b005b20a06afa4a3505d03..7ed3663332ecf16a9f8c237e00b2963fe561cfa7 100644 (file)
@@ -142,7 +142,7 @@ struct security_class_mapping secclass_map[] = {
            "node_bind", "name_connect", NULL } },
        { "memprotect", { "mmap_zero", NULL } },
        { "peer", { "recv", NULL } },
-       { "capability2", { "mac_override", "mac_admin", NULL } },
+       { "capability2", { "mac_override", "mac_admin", "syslog", NULL } },
        { "kernel_service", { "use_as_override", "create_files_as", NULL } },
        { "tun_socket",
          { COMMON_SOCK_PERMS, NULL } },