[PATCH] posix-timers: use try_to_del_timer_sync()
[safe/jmp/linux-2.6] / kernel / auditsc.c
index 78d7a13..e75f84e 100644 (file)
@@ -34,6 +34,7 @@
 #include <asm/types.h>
 #include <linux/mm.h>
 #include <linux/module.h>
+#include <linux/mount.h>
 #include <linux/socket.h>
 #include <linux/audit.h>
 #include <linux/personality.h>
@@ -124,6 +125,11 @@ struct audit_aux_data_sockaddr {
        char                    a[0];
 };
 
+struct audit_aux_data_path {
+       struct audit_aux_data   d;
+       struct dentry           *dentry;
+       struct vfsmount         *mnt;
+};
 
 /* The per-task audit context. */
 struct audit_context {
@@ -139,6 +145,8 @@ struct audit_context {
        int                 auditable;  /* 1 if record should be written */
        int                 name_count;
        struct audit_names  names[AUDIT_NAMES];
+       struct dentry *     pwd;
+       struct vfsmount *   pwdmnt;
        struct audit_context *previous; /* For nested syscalls */
        struct audit_aux_data *aux;
 
@@ -301,7 +309,7 @@ int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
                if (!err && (flags & AUDIT_AT_EXIT))
                        err = audit_add_rule(entry, &audit_extlist);
                audit_log(NULL, AUDIT_CONFIG_CHANGE, 
-                               "auid %u added an audit rule\n", loginuid);
+                               "auid=%u added an audit rule\n", loginuid);
                break;
        case AUDIT_DEL:
                flags =((struct audit_rule *)data)->flags;
@@ -312,7 +320,7 @@ int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
                if (!err && (flags & AUDIT_AT_EXIT))
                        err = audit_del_rule(data, &audit_extlist);
                audit_log(NULL, AUDIT_CONFIG_CHANGE,
-                               "auid %u removed an audit rule\n", loginuid);
+                               "auid=%u removed an audit rule\n", loginuid);
                break;
        default:
                return -EINVAL;
@@ -546,6 +554,12 @@ static inline void audit_free_names(struct audit_context *context)
                if (context->names[i].name)
                        __putname(context->names[i].name);
        context->name_count = 0;
+       if (context->pwd)
+               dput(context->pwd);
+       if (context->pwdmnt)
+               mntput(context->pwdmnt);
+       context->pwd = NULL;
+       context->pwdmnt = NULL;
 }
 
 static inline void audit_free_aux(struct audit_context *context)
@@ -553,6 +567,11 @@ static inline void audit_free_aux(struct audit_context *context)
        struct audit_aux_data *aux;
 
        while ((aux = context->aux)) {
+               if (aux->type == AUDIT_AVC_PATH) {
+                       struct audit_aux_data_path *axi = (void *)aux;
+                       dput(axi->dentry);
+                       mntput(axi->mnt);
+               }
                context->aux = aux->next;
                kfree(aux);
        }
@@ -639,7 +658,8 @@ static void audit_log_task_info(struct audit_buffer *ab)
        struct vm_area_struct *vma;
 
        get_task_comm(name, current);
-       audit_log_format(ab, " comm=%s", name);
+       audit_log_format(ab, " comm=");
+       audit_log_untrustedstring(ab, name);
 
        if (!mm)
                return;
@@ -663,23 +683,24 @@ static void audit_log_exit(struct audit_context *context)
 {
        int i;
        struct audit_buffer *ab;
+       struct audit_aux_data *aux;
 
        ab = audit_log_start(context, AUDIT_SYSCALL);
        if (!ab)
                return;         /* audit_panic has been called */
-       audit_log_format(ab, "syscall=%d", context->major);
+       audit_log_format(ab, "arch=%x syscall=%d",
+                        context->arch, context->major);
        if (context->personality != PER_LINUX)
                audit_log_format(ab, " per=%lx", context->personality);
-       audit_log_format(ab, " arch=%x", context->arch);
        if (context->return_valid)
                audit_log_format(ab, " success=%s exit=%ld", 
                                 (context->return_valid==AUDITSC_SUCCESS)?"yes":"no",
                                 context->return_code);
        audit_log_format(ab,
                  " a0=%lx a1=%lx a2=%lx a3=%lx items=%d"
-                 " pid=%d loginuid=%d uid=%d gid=%d"
-                 " euid=%d suid=%d fsuid=%d"
-                 " egid=%d sgid=%d fsgid=%d",
+                 " pid=%d auid=%u uid=%u gid=%u"
+                 " euid=%u suid=%u fsuid=%u"
+                 " egid=%u sgid=%u fsgid=%u",
                  context->argv[0],
                  context->argv[1],
                  context->argv[2],
@@ -693,10 +714,8 @@ static void audit_log_exit(struct audit_context *context)
                  context->egid, context->sgid, context->fsgid);
        audit_log_task_info(ab);
        audit_log_end(ab);
-       while (context->aux) {
-               struct audit_aux_data *aux;
 
-               aux = context->aux;
+       for (aux = context->aux; aux; aux = aux->next) {
 
                ab = audit_log_start(context, aux->type);
                if (!ab)
@@ -706,7 +725,7 @@ static void audit_log_exit(struct audit_context *context)
                case AUDIT_IPC: {
                        struct audit_aux_data_ipcctl *axi = (void *)aux;
                        audit_log_format(ab, 
-                                        " qbytes=%lx iuid=%d igid=%d mode=%x",
+                                        " qbytes=%lx iuid=%u igid=%u mode=%x",
                                         axi->qbytes, axi->uid, axi->gid, axi->mode);
                        break; }
 
@@ -724,17 +743,28 @@ static void audit_log_exit(struct audit_context *context)
                        audit_log_format(ab, "saddr=");
                        audit_log_hex(ab, axs->a, axs->len);
                        break; }
+
+               case AUDIT_AVC_PATH: {
+                       struct audit_aux_data_path *axi = (void *)aux;
+                       audit_log_d_path(ab, "path=", axi->dentry, axi->mnt);
+                       break; }
+
                }
                audit_log_end(ab);
-
-               context->aux = aux->next;
-               kfree(aux);
        }
 
+       if (context->pwd && context->pwdmnt) {
+               ab = audit_log_start(context, AUDIT_CWD);
+               if (ab) {
+                       audit_log_d_path(ab, "cwd=", context->pwd, context->pwdmnt);
+                       audit_log_end(ab);
+               }
+       }
        for (i = 0; i < context->name_count; i++) {
                ab = audit_log_start(context, AUDIT_PATH);
                if (!ab)
                        continue; /* audit_panic has been called */
+
                audit_log_format(ab, "item=%d", i);
                if (context->names[i].name) {
                        audit_log_format(ab, " name=");
@@ -742,7 +772,7 @@ static void audit_log_exit(struct audit_context *context)
                }
                if (context->names[i].ino != (unsigned long)-1)
                        audit_log_format(ab, " inode=%lu dev=%02x:%02x mode=%#o"
-                                            " ouid=%d ogid=%d rdev=%02x:%02x",
+                                            " ouid=%u ogid=%u rdev=%02x:%02x",
                                         context->names[i].ino,
                                         MAJOR(context->names[i].dev),
                                         MINOR(context->names[i].dev),
@@ -776,36 +806,6 @@ void audit_free(struct task_struct *tsk)
        audit_free_context(context);
 }
 
-/* Compute a serial number for the audit record.  Audit records are
- * written to user-space as soon as they are generated, so a complete
- * audit record may be written in several pieces.  The timestamp of the
- * record and this serial number are used by the user-space tools to
- * determine which pieces belong to the same audit record.  The
- * (timestamp,serial) tuple is unique for each syscall and is live from
- * syscall entry to syscall exit.
- *
- * Atomic values are only guaranteed to be 24-bit, so we count down.
- *
- * NOTE: Another possibility is to store the formatted records off the
- * audit context (for those records that have a context), and emit them
- * all at syscall exit.  However, this could delay the reporting of
- * significant errors until syscall exit (or never, if the system
- * halts). */
-static inline unsigned int audit_serial(void)
-{
-       static atomic_t serial = ATOMIC_INIT(0xffffff);
-       unsigned int a, b;
-
-       do {
-               a = atomic_read(&serial);
-               if (atomic_dec_and_test(&serial))
-                       atomic_set(&serial, 0xffffff);
-               b = atomic_read(&serial);
-       } while (b != a - 1);
-
-       return 0xffffff - b;
-}
-
 /* Fill in audit context at syscall entry.  This only happens if the
  * audit context was created when the task was created and the state or
  * filters demand the audit context be built.  If the state from the
@@ -945,6 +945,13 @@ void audit_getname(const char *name)
        context->names[context->name_count].name = name;
        context->names[context->name_count].ino  = (unsigned long)-1;
        ++context->name_count;
+       if (!context->pwd) {
+               read_lock(&current->fs->lock);
+               context->pwd = dget(current->fs->pwd);
+               context->pwdmnt = mntget(current->fs->pwdmnt);
+               read_unlock(&current->fs->lock);
+       }
+               
 }
 
 /* Intercept a putname request.  Called from
@@ -1023,17 +1030,13 @@ void audit_inode(const char *name, const struct inode *inode)
        context->names[idx].rdev = inode->i_rdev;
 }
 
-int audit_get_stamp(struct audit_context *ctx,
-                    struct timespec *t, unsigned int *serial)
+void auditsc_get_stamp(struct audit_context *ctx,
+                      struct timespec *t, unsigned int *serial)
 {
-       if (ctx) {
-               t->tv_sec  = ctx->ctime.tv_sec;
-               t->tv_nsec = ctx->ctime.tv_nsec;
-               *serial    = ctx->serial;
-               ctx->auditable = 1;
-               return 1;
-       }
-       return 0;
+       t->tv_sec  = ctx->ctime.tv_sec;
+       t->tv_nsec = ctx->ctime.tv_nsec;
+       *serial    = ctx->serial;
+       ctx->auditable = 1;
 }
 
 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
@@ -1044,7 +1047,7 @@ int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
                ab = audit_log_start(NULL, AUDIT_LOGIN);
                if (ab) {
                        audit_log_format(ab, "login pid=%d uid=%u "
-                               "old loginuid=%u new loginuid=%u",
+                               "old auid=%u new auid=%u",
                                task->pid, task->uid, 
                                task->audit_context->loginuid, loginuid);
                        audit_log_end(ab);
@@ -1124,6 +1127,27 @@ int audit_sockaddr(int len, void *a)
        return 0;
 }
 
+int audit_avc_path(struct dentry *dentry, struct vfsmount *mnt)
+{
+       struct audit_aux_data_path *ax;
+       struct audit_context *context = current->audit_context;
+
+       if (likely(!context))
+               return 0;
+
+       ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
+       if (!ax)
+               return -ENOMEM;
+
+       ax->dentry = dget(dentry);
+       ax->mnt = mntget(mnt);
+
+       ax->d.type = AUDIT_AVC_PATH;
+       ax->d.next = context->aux;
+       context->aux = (void *)ax;
+       return 0;
+}
+
 void audit_signal_info(int sig, struct task_struct *t)
 {
        extern pid_t audit_sig_pid;