security_syslog() should be called once only
authorVasily Averin <vvs@virtuozzo.com>
Thu, 25 Jun 2015 22:01:44 +0000 (15:01 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 26 Jun 2015 00:00:39 +0000 (17:00 -0700)
The final version of commit 637241a900cb ("kmsg: honor dmesg_restrict
sysctl on /dev/kmsg") lost few hooks, as result security_syslog() are
processed incorrectly:

- open of /dev/kmsg checks syslog access permissions by using
  check_syslog_permissions() where security_syslog() is not called if
  dmesg_restrict is set.

- syslog syscall and /proc/kmsg calls do_syslog() where security_syslog
  can be executed twice (inside check_syslog_permissions() and then
  directly in do_syslog())

With this patch security_syslog() is called once only in all
syslog-related operations regardless of dmesg_restrict value.

Fixes: 637241a900cb ("kmsg: honor dmesg_restrict sysctl on /dev/kmsg")
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Josh Boyer <jwboyer@redhat.com>
Cc: Eric Paris <eparis@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/printk/printk.c

index ae980dc..45fa8c8 100644 (file)
@@ -496,11 +496,11 @@ int check_syslog_permissions(int type, bool from_file)
         * already done the capabilities checks at open time.
         */
        if (from_file && type != SYSLOG_ACTION_OPEN)
-               return 0;
+               goto ok;
 
        if (syslog_action_restricted(type)) {
                if (capable(CAP_SYSLOG))
-                       return 0;
+                       goto ok;
                /*
                 * For historical reasons, accept CAP_SYS_ADMIN too, with
                 * a warning.
@@ -510,10 +510,11 @@ int check_syslog_permissions(int type, bool from_file)
                                     "CAP_SYS_ADMIN but no CAP_SYSLOG "
                                     "(deprecated).\n",
                                 current->comm, task_pid_nr(current));
-                       return 0;
+                       goto ok;
                }
                return -EPERM;
        }
+ok:
        return security_syslog(type);
 }
 
@@ -1299,10 +1300,6 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
        if (error)
                goto out;
 
-       error = security_syslog(type);
-       if (error)
-               return error;
-
        switch (type) {
        case SYSLOG_ACTION_CLOSE:       /* Close log */
                break;