Specify a permission for do_file_open() [2/7]
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 3 Sep 2015 22:04:54 +0000 (18:04 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 28 Sep 2015 19:14:00 +0000 (15:14 -0400)
We had been getting away with passing 0, even though we needed at least
readable permission.

kern/include/linux_compat.h
kern/src/devfs.c
kern/src/elf.c
kern/src/ktest/pb_ktests.c
kern/src/manager.c
kern/src/monitor.c
kern/src/syscall.c

index 4aff8af..8407e9c 100644 (file)
@@ -716,7 +716,7 @@ static inline int request_firmware(const struct firmware **fwp,
        char fullpath[sizeof(dirname) + strlen(file_name) + 1];
 
        snprintf(fullpath, sizeof(fullpath), "%s%s", dirname, file_name);
-       fw_file = do_file_open(fullpath, 0, 0);
+       fw_file = do_file_open(fullpath, O_READ, 0);
        if (!fw_file) {
                printk("Unable to find firmware file %s!\n", fullpath);
                return -1;
index 2cc2764..7bcdb51 100644 (file)
@@ -50,7 +50,7 @@ void devfs_init(void)
 struct file *make_device(char *path, int mode, int type,
                          struct file_operations *fop)
 {
-       struct file *f_dev = do_file_open(path, O_CREAT, mode);
+       struct file *f_dev = do_file_open(path, O_CREAT | O_RDWR, mode);
        assert(f_dev);
        /* Overwrite the f_op with our own f_ops */
        f_dev->f_dentry->d_inode->i_fop = fop;
index 8e80fdc..2c94920 100644 (file)
@@ -362,7 +362,7 @@ int load_elf(struct proc* p, struct file* f,
                return -1;
 
        if (ei.dynamic) {
-               struct file *interp = do_file_open(ei.interp, 0, 0);
+               struct file *interp = do_file_open(ei.interp, O_READ, 0);
                if (!interp)
                        return -1;
                /* Load dynamic linker at 1M. Obvious MIB joke avoided.
index a40d713..5dfd003 100644 (file)
@@ -1038,7 +1038,7 @@ bool test_ucq(void)
        set_alarm(tchain, waiter);
        /* Just spawn the program */
        struct file *program;
-       program = do_file_open("/bin/ucq", 0, 0);
+       program = do_file_open("/bin/ucq", O_READ, 0);
        
        KT_ASSERT_M("We should be able to find /bin/ucq", 
                    program);
index be80396..cd3c5bf 100644 (file)
@@ -59,7 +59,7 @@ char *p_argv[] = {0, 0, 0};
 /* Helper macro for quickly running a process.  Pass it a string, *file, and a
  * *proc. */
 #define quick_proc_run(x, p, f)                                                  \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
        (p) = proc_create((f), p_argv, NULL);                                        \
@@ -71,7 +71,7 @@ char *p_argv[] = {0, 0, 0};
        proc_decref((p));
 
 #define quick_proc_create(x, p, f)                                               \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
        (p) = proc_create((f), p_argv, NULL);                                        \
@@ -81,7 +81,7 @@ char *p_argv[] = {0, 0, 0};
        spin_unlock(&(p)->proc_lock);
 
 #define quick_proc_color_run(x, p, c, f)                                         \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
        (p) = proc_create((f), p_argv, NULL);                                        \
@@ -96,7 +96,7 @@ char *p_argv[] = {0, 0, 0};
        proc_decref((p));
 
 #define quick_proc_color_create(x, p, c, f)                                      \
-       (f) = do_file_open((x), 0, 0);                                               \
+       (f) = do_file_open((x), O_READ, 0);                                          \
        assert((f));                                                                 \
        p_argv[0] = file_name((f));                                                  \
        (p) = proc_create((f), p_argv, NULL);                                        \
@@ -236,7 +236,7 @@ void manager_jenkins()
                char exec[] = "/bin/ash";
                char *p_argv[] = {exec, CONFIG_USERSPACE_TESTING_SCRIPT, 0};
 
-               struct file *program = do_file_open(exec, 0, 0);
+               struct file *program = do_file_open(exec, O_READ, 0);
                struct proc *p = proc_create(program, p_argv, NULL);
                proc_wakeup(p);
                proc_decref(p); /* let go of the reference created in proc_create() */
index 8020416..9082849 100644 (file)
@@ -285,7 +285,7 @@ int mon_bin_ls(int argc, char **argv, struct hw_trapframe *hw_tf)
        struct file *bin_dir;
        int retval = 0;
 
-       bin_dir = do_file_open("/bin", 0, 0);
+       bin_dir = do_file_open("/bin", O_READ, 0);
        if (!bin_dir) {
                printk("No /bin directory!\n");
                return 1;
@@ -309,7 +309,7 @@ int mon_bin_run(int argc, char **argv, struct hw_trapframe *hw_tf)
        int retval = 0;
        char buf[6 + MAX_FILENAME_SZ] = "/bin/";        /* /bin/ + max + \0 */
        strncpy(buf + 5, argv[1], MAX_FILENAME_SZ);
-       program = do_file_open(buf, 0, 0);
+       program = do_file_open(buf, O_READ, 0);
        if (!program) {
                printk("No such program!\n");
                return 1;
index ddd03ec..53ae09c 100644 (file)
@@ -544,7 +544,7 @@ static int sys_proc_create(struct proc *p, char *path, size_t path_l,
        if (!t_path)
                return -1;
        /* TODO: 9ns support */
-       program = do_file_open(t_path, 0, 0);
+       program = do_file_open(t_path, O_READ, 0);
        free_path(p, t_path);
        if (!program)
                return -1;                      /* presumably, errno is already set */
@@ -822,7 +822,7 @@ static int sys_exec(struct proc *p, char *path, size_t path_l,
 
        /* This could block: */
        /* TODO: 9ns support */
-       program = do_file_open(t_path, 0, 0);
+       program = do_file_open(t_path, O_READ, 0);
        free_path(p, t_path);
        if (!program)
                goto early_error;
@@ -2128,7 +2128,7 @@ intreg_t sys_wstat(struct proc *p, char *path, size_t path_l,
                return stat_sz;
        }
        /* 9ns failed, we'll need to check the VFS */
-       file = do_file_open(t_path, 0, 0);
+       file = do_file_open(t_path, O_READ, 0);
        free_path(p, t_path);
        if (!file)
                return -1;