isundil 9 лет назад
Родитель
Сommit
d0f772118d
4 измененных файлов с 157 добавлено и 9 удалено
  1. 127 0
      README.md
  2. 3 4
      src/ovr_syscall/ovr_write.c
  3. 4 0
      src/sandbox_syscall.h
  4. 23 5
      test/write/main.c

+ 127 - 0
README.md

@@ -1,2 +1,129 @@
 # sandbox
 
+# Syscall list
+
+
+| Syscall | Involve fs | Involve time | Involve network |
+| --- | :---: | :---: | :---: |
+| io_setup       | ? | ? | ? |
+| io_destroy     | ? | ? | ? |
+| io_submit      | ? | ? | ? |
+| io_cancel      | ? | ? | ? |
+| io_getevents   | ? | ? | ? |
+| fs/xattr.c                 |
+| setxattr       | ? | ? | ? |
+| lsetxattr      | ? | ? | ? |
+| fsetxattr      | ? | ? | ? |
+| getxattr       | ? | ? | ? |
+| lgetxattr      | ? | ? | ? |
+| fgetxattr      | ? | ? | ? |
+| listxattr      | ? | ? | ? |
+| llistxattr     | ? | ? | ? |
+| flistxattr     | ? | ? | ? |
+| removexattr    | ? | ? | ? |
+| lremoveattr    | ? | ? | ? |
+| fremoveattr    | ? | ? | ? |
+| fs/dcache.c                |
+| getcwd         | * | ✗ | ✗ |
+| fs/cookies.c               |
+| lookup_dcookie | ? | ? | ? |
+| fs/eventfd.c               |
+| eventfd2       | ? | ? | ? |
+| fs/eventpoll.c                |
+| epoll_create1     | ? | ? | ? |
+| epoll_ctl         | ? | ? | ? |
+| epoll_pwait       | ? | ? | ? |
+| fs/fcntl.c                    |
+| dup               | ? | ? | ? |
+| dup3              | ? | ? | ? |
+| fcntl (?)         | ? | ? | ? |
+| fs/inotify_user.c             |
+| inotify_init1     | ? | ? | ? |
+| inotify_add_watch | ? | ? | ? |
+| inotify_rm_watch  | ? | ? | ? |
+| fs/ioctl.c                    |
+| ioctl             | ? | ? | ? |
+| fs/ioprio.c                   |
+| ioprio_set        | ? | ? | ? |
+| ioprio_get        | ? | ? | ? |
+| fs/locks.c                    |
+| flock             | ? | ? | ? |
+| fs/namei.c                    |
+| mknodat           | ? | ? | ? |
+| mkdirat           | ? | ? | ? |
+| unlinkat          | ? | ? | ? |
+| symlinkat         | ? | ? | ? |
+| linkat            | ? | ? | ? |
+| renameat          | ? | ? | ? |
+| fs/namespace.c                |
+| umount2           | ? | ? | ? |
+| mount             | ? | ? | ? |
+| pivot_root        | ? | ? | ? |
+| fs/nfsctl.c                   |
+| nfsservctl        | ? | ? | ? |
+| fs/open.c                     |
+| statfs (?)        | ? | ? | ? |
+| fstatfs (?)       | ? | ? | ? |
+| truncate (?)      | ? | ? | ? |
+| ftruncate (?)     | ? | ? | ? |
+| fallocate         | ? | ? | ? |
+| faccessat         | ? | ? | ? |
+| chdir             | * | ✗ | ✗ |
+| fchdir            | * | ✗ | ✗ |
+| chroot            | ? | ? | ? |
+| fchmod            | ? | ? | ? |
+| fchmodat          | ? | ? | ? |
+| fchownat          | ? | ? | ? |
+| fchown            | ? | ? | ? |
+| openat            | ? | ? | ? |
+| close             | ✔ | ✗ | ✗ |
+| vhangup           | ? | ? | ? |
+| fs/pipe.c                     |
+| pipe              | □ | ✗ | ✗ |
+| fs/quota.c                    |
+| quotactl          | ? | ? | ? |
+| fs/readdir.c                  |
+| getdents64        | ? | ? | ? |
+| lseek (?)         | ? | ? | ? |
+| read              | □ | ✗ | □ |
+| write             | □ | ✗ | □ |
+| readv             | □ | ✗ | □ |
+| writev            | □ | ✗ | □ |
+| pread64           | □ | ✗ | □ |
+| pwrite64          | □ | ✗ | □ |
+| preadv            | □ | ✗ | □ |
+| pwritev           | □ | ✗ | □ |
+| fs/sendfile.c                 |
+| sendfile (?)      | ? | ? | ? |
+| fs/select.c                   |
+| pselect6          | ? | ? | ? |
+| ppoll             | ? | ? | ? |
+| fs/signalfd.c                 |
+| signalfd4         | ? | ? | ? |
+| fs/splice.c                   |
+| vmsplice          | ? | ? | ? |
+| splice            | ? | ? | ? |
+| tee               | ? | ? | ? |
+| fs/stat.c                     |
+| readlinkat        | ? | ? | ? |
+| fstatat (?)       | ? | ? | ? |
+| fstat (?)         | ? | ? | ? |
+| fs/sync.c                     |
+| sync              | ? | ? | ? |
+| fsync             | ? | ? | ? |
+| fdatasync         | ? | ? | ? |
+| sync_file_range2 ?| ? | ? | ? |
+| sync_file_range  ?| ? | ? | ? |
+| fs/timerfd.c                  |
+| timerfd_create    | ? | ? | ? |
+| timerfd_settime   | ? | ? | ? |
+| timerfd_gettime   | ? | ? | ? |
+| fs/utime.c                    |
+| utimensat         | ? | ? | ? |
+| kernel/acct.c                 |
+
+✗: Syscall do not involve capacity
+□: Syscall do involve capacity, TODO
+✔: Syscall do involve capacity, override done
+*: Syscall do involve capacity, but no override needed
+

+ 3 - 4
src/ovr_syscall/ovr_write.c

@@ -8,10 +8,9 @@ int ovr_write(struct s_sandboxenv *env)
 	int buflen = (int) env->syscall_args[2];
 	t_fileinfo *file = get_fileinfo_fd(env, fd);
 
-	if (file)
-		printf("DO WRITE ! ([%s], [%s], [%d])\n", file->filename, buf, buflen);
-	else
-		printf("DO WRITE ! ([unmanaged], [%s], [%d])\n", buf, buflen);
+	if (!file)
+		return 0;
+	printf("DO WRITE ! ([%s], [%s], [%d])\n", file->filename, buf, buflen);
 	fflush(stdout);
 	free(buf);
 	//env->registers.orig_rax = -1;

+ 4 - 0
src/sandbox_syscall.h

@@ -1,6 +1,10 @@
 #ifndef  SANDBOX_SYSCALL_H__
 # define SANDBOX_SYSCALL_H__
 
+/**
+ * Function return non-zero value to inject registers
+**/
+
 int ovr_open(struct s_sandboxenv *);
 int ovr_close(struct s_sandboxenv *);
 int ovr_write(struct s_sandboxenv *);

+ 23 - 5
test/write/main.c

@@ -12,9 +12,9 @@ int fakeopen(const char *path, int flags, int mod, struct s_sandboxenv *env)
 {
 	int fd;
 #ifdef __x86_64__
-	env->syscall_no.syscall_no = env->registers.orig_rax = (unsigned long long) __NR_open;
+	env->syscall_no.syscall_no = env->registers.orig_rax = (REGISTER_TYPE) __NR_open;
 	env->syscall_no.syscall_return = fd = open(path, flags, mod);
-	env->syscall_args[0] = env->registers.rdi = (unsigned long long) path;
+	env->syscall_args[0] = env->registers.rdi = (REGISTER_TYPE) path;
 	env->syscall_args[1] = env->registers.rsi = flags;
 	env->syscall_args[2] = env->registers.rdx = mod;
 #else
@@ -27,7 +27,7 @@ int fakeopen(const char *path, int flags, int mod, struct s_sandboxenv *env)
 int fakeclose(int fd, struct s_sandboxenv *env)
 {
 #ifdef __x86_64__
-	env->syscall_no.syscall_no = env->registers.orig_rax = (unsigned long long) __NR_close;
+	env->syscall_no.syscall_no = env->registers.orig_rax = (REGISTER_TYPE) __NR_close;
 	env->syscall_args[0] = env->registers.rdi = fd;
 #else
 # error "non-x86 unsupported"
@@ -36,6 +36,22 @@ int fakeclose(int fd, struct s_sandboxenv *env)
 	return fd;
 }
 
+int fakewrite(int fd, char *buf, int len, struct s_sandboxenv *env)
+{
+#ifdef __x86_64__
+	env->syscall_no.syscall_no = env->registers.orig_rax = (REGISTER_TYPE) __NR_write;
+	env->syscall_args[0] = env->registers.rdi = fd;
+	env->syscall_args[1] = env->registers.rsi = (REGISTER_TYPE) buf;
+	env->syscall_args[2] = env->registers.rdx = len;
+#else
+# error "non-x86 unsupported"
+#endif
+	ovr_write(env);
+	if (env->registers.orig_rax == __NR_write)
+		env->registers.rax = write(fd, buf, len);
+	return env->registers.rax;
+}
+
 
 int test_open(struct s_sandboxenv *env, int *final_fd)
 {
@@ -71,8 +87,10 @@ int test_open(struct s_sandboxenv *env, int *final_fd)
 	return 0;
 }
 
-int test_write(struct s_sandboxenv *env)
+int test_write(struct s_sandboxenv *env, int fd)
 {
+	_assertEqual(fakewrite(fd, "test", 5, env), 5);
+#warning TODO
 	return 0;
 }
 
@@ -86,7 +104,7 @@ int main()
 	tests_init_env(&env, &params);
 
 	success &= !test_open(&env, &fd);
-	success &= !test_write(&env);
+	success &= !test_write(&env, fd);
 
 	fakeclose(fd, &env);
 	tests_release_env(&env, &params);