Merge branch 'linus' into cont_syslog
[safe/jmp/linux-2.6] / arch / mips / kernel / kspd.c
index f6704ab..80e2ba6 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/sched.h>
 #include <linux/unistd.h>
 #include <linux/file.h>
+#include <linux/fdtable.h>
 #include <linux/fs.h>
 #include <linux/syscalls.h>
 #include <linux/workqueue.h>
@@ -30,7 +31,7 @@
 #include <asm/rtlx.h>
 #include <asm/kspd.h>
 
-static struct workqueue_struct *workqueue = NULL;
+static struct workqueue_struct *workqueue;
 static struct work_struct work;
 
 extern unsigned long cpu_khz;
@@ -57,7 +58,7 @@ struct mtsp_syscall_generic {
 };
 
 static struct list_head kspd_notifylist;
-static int sp_stopping = 0;
+static int sp_stopping;
 
 /* these should match with those in the SDE kit */
 #define MTSP_SYSCALL_BASE      0
@@ -81,6 +82,7 @@ static int sp_stopping = 0;
 #define MTSP_O_SHLOCK          0x0010
 #define MTSP_O_EXLOCK          0x0020
 #define MTSP_O_ASYNC           0x0040
+/* XXX: check which of these is actually O_SYNC vs O_DSYNC */
 #define MTSP_O_FSYNC           O_SYNC
 #define MTSP_O_NOFOLLOW                0x0100
 #define MTSP_O_SYNC            0x0080
@@ -171,13 +173,20 @@ static unsigned int translate_open_flags(int flags)
 }
 
 
-static void sp_setfsuidgid( uid_t uid, gid_t gid)
+static int sp_setfsuidgid(uid_t uid, gid_t gid)
 {
-       current->fsuid = uid;
-       current->fsgid = gid;
+       struct cred *new;
 
-       key_fsuid_changed(current);
-       key_fsgid_changed(current);
+       new = prepare_creds();
+       if (!new)
+               return -ENOMEM;
+
+       new->fsuid = uid;
+       new->fsgid = gid;
+
+       commit_creds(new);
+
+       return 0;
 }
 
 /*
@@ -195,7 +204,7 @@ void sp_work_handle_request(void)
        mm_segment_t old_fs;
        struct timeval tv;
        struct timezone tz;
-       int cmd;
+       int err, cmd;
 
        char *vcwd;
        int size;
@@ -221,11 +230,14 @@ void sp_work_handle_request(void)
                }
        }
 
-       /* Run the syscall at the priviledge of the user who loaded the
+       /* Run the syscall at the privilege of the user who loaded the
           SP program */
 
-       if (vpe_getuid(tclimit))
-               sp_setfsuidgid(vpe_getuid(tclimit), vpe_getgid(tclimit));
+       if (vpe_getuid(tclimit)) {
+               err = sp_setfsuidgid(vpe_getuid(tclimit), vpe_getgid(tclimit));
+               if (!err)
+                       pr_err("Change of creds failed\n");
+       }
 
        switch (sc.cmd) {
        /* needs the flags argument translating from SDE kit to
@@ -256,7 +268,7 @@ void sp_work_handle_request(void)
 
                vcwd = vpe_getcwd(tclimit);
 
-               /* change to the cwd of the process that loaded the SP program */
+               /* change to cwd of the process that loaded the SP program */
                old_fs = get_fs();
                set_fs(KERNEL_DS);
                sys_chdir(vcwd);
@@ -282,8 +294,11 @@ void sp_work_handle_request(void)
                break;
        } /* switch */
 
-       if (vpe_getuid(tclimit))
-               sp_setfsuidgid( 0, 0);
+       if (vpe_getuid(tclimit)) {
+               err = sp_setfsuidgid(0, 0);
+               if (!err)
+                       pr_err("restoring old creds failed\n");
+       }
 
        old_fs = get_fs();
        set_fs(KERNEL_DS);
@@ -322,9 +337,12 @@ static void sp_cleanup(void)
                        set >>= 1;
                }
        }
+
+       /* Put daemon cwd back to root to avoid umount problems */
+       sys_chdir("/");
 }
 
-static int channel_open = 0;
+static int channel_open;
 
 /* the work handler */
 static void sp_work(struct work_struct *unused)