[PATCH] split linux/file.h
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / char / tty_audit.c
index d222012c1b0ca039a4c41c6f7a450a4fbe2ba8a0..3582f43345a8c1d40397d2284dd2bc11d77a9fd4 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/audit.h>
 #include <linux/file.h>
+#include <linux/fdtable.h>
 #include <linux/tty.h>
 
 struct tty_audit_buf {
@@ -27,7 +28,7 @@ static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor,
 {
        struct tty_audit_buf *buf;
 
-       buf = kmalloc(sizeof (*buf), GFP_KERNEL);
+       buf = kmalloc(sizeof(*buf), GFP_KERNEL);
        if (!buf)
                goto err;
        if (PAGE_SIZE != N_TTY_BUF_SIZE)
@@ -73,6 +74,7 @@ static void tty_audit_buf_put(struct tty_audit_buf *buf)
  *     @tsk with @loginuid.  @buf->mutex must be locked.
  */
 static void tty_audit_buf_push(struct task_struct *tsk, uid_t loginuid,
+                              unsigned int sessionid,
                               struct tty_audit_buf *buf)
 {
        struct audit_buffer *ab;
@@ -85,13 +87,13 @@ static void tty_audit_buf_push(struct task_struct *tsk, uid_t loginuid,
        if (ab) {
                char name[sizeof(tsk->comm)];
 
-               audit_log_format(ab, "tty pid=%u uid=%u auid=%u major=%d "
-                                "minor=%d comm=", tsk->pid, tsk->uid,
-                                loginuid, buf->major, buf->minor);
+               audit_log_format(ab, "tty pid=%u uid=%u auid=%u ses=%u "
+                                "major=%d minor=%d comm=", tsk->pid, tsk->uid,
+                                loginuid, sessionid, buf->major, buf->minor);
                get_task_comm(name, tsk);
                audit_log_untrustedstring(ab, name);
                audit_log_format(ab, " data=");
-               audit_log_n_untrustedstring(ab, buf->valid, buf->data);
+               audit_log_n_untrustedstring(ab, buf->data, buf->valid);
                audit_log_end(ab);
        }
        buf->valid = 0;
@@ -105,8 +107,9 @@ static void tty_audit_buf_push(struct task_struct *tsk, uid_t loginuid,
  */
 static void tty_audit_buf_push_current(struct tty_audit_buf *buf)
 {
-       tty_audit_buf_push(current, audit_get_loginuid(current->audit_context),
-                          buf);
+       uid_t auid = audit_get_loginuid(current);
+       unsigned int sessionid = audit_get_sessionid(current);
+       tty_audit_buf_push(current, auid, sessionid, buf);
 }
 
 /**
@@ -149,7 +152,7 @@ void tty_audit_fork(struct signal_struct *sig)
 /**
  *     tty_audit_push_task     -       Flush task's pending audit data
  */
-void tty_audit_push_task(struct task_struct *tsk, uid_t loginuid)
+void tty_audit_push_task(struct task_struct *tsk, uid_t loginuid, u32 sessionid)
 {
        struct tty_audit_buf *buf;
 
@@ -162,7 +165,7 @@ void tty_audit_push_task(struct task_struct *tsk, uid_t loginuid)
                return;
 
        mutex_lock(&buf->mutex);
-       tty_audit_buf_push(tsk, loginuid, buf);
+       tty_audit_buf_push(tsk, loginuid, sessionid, buf);
        mutex_unlock(&buf->mutex);
 
        tty_audit_buf_put(buf);
@@ -231,6 +234,10 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
        if (unlikely(size == 0))
                return;
 
+       if (tty->driver->type == TTY_DRIVER_TYPE_PTY
+           && tty->driver->subtype == PTY_TYPE_MASTER)
+               return;
+
        buf = tty_audit_buf_get(tty);
        if (!buf)
                return;
@@ -293,53 +300,3 @@ void tty_audit_push(struct tty_struct *tty)
                tty_audit_buf_put(buf);
        }
 }
-
-/**
- *     tty_audit_opening       -       A TTY is being opened.
- *
- *     As a special hack, tasks that close all their TTYs and open new ones
- *     are assumed to be system daemons (e.g. getty) and auditing is
- *     automatically disabled for them.
- */
-void tty_audit_opening(void)
-{
-       int disable;
-
-       disable = 1;
-       spin_lock_irq(&current->sighand->siglock);
-       if (current->signal->audit_tty == 0)
-               disable = 0;
-       spin_unlock_irq(&current->sighand->siglock);
-       if (!disable)
-               return;
-
-       task_lock(current);
-       if (current->files) {
-               struct fdtable *fdt;
-               unsigned i;
-
-               /*
-                * We don't take a ref to the file, so we must hold ->file_lock
-                * instead.
-                */
-               spin_lock(&current->files->file_lock);
-               fdt = files_fdtable(current->files);
-               for (i = 0; i < fdt->max_fds; i++) {
-                       struct file *filp;
-
-                       filp = fcheck_files(current->files, i);
-                       if (filp && is_tty(filp)) {
-                               disable = 0;
-                               break;
-                       }
-               }
-               spin_unlock(&current->files->file_lock);
-       }
-       task_unlock(current);
-       if (!disable)
-               return;
-
-       spin_lock_irq(&current->sighand->siglock);
-       current->signal->audit_tty = 0;
-       spin_unlock_irq(&current->sighand->siglock);
-}