From bdbec30a849807fb5e6841a38cfe0d168e5962b9 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Thu, 21 Dec 2023 12:06:05 +0100 Subject: seitan: Add netlink, sendto()/sendmsg(), iovec handling, demo with routes A bit rough at the moment, but it does the trick. Bonus: setsockopt() (with magic values only, not used in any demo yet). Signed-off-by: Stefano Brivio --- common/gluten.h | 18 ++++++++++++++++-- common/util.c | 20 ++++++++++++++++++++ common/util.h | 1 + 3 files changed, 37 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/gluten.h b/common/gluten.h index e80916a..1414d9e 100644 --- a/common/gluten.h +++ b/common/gluten.h @@ -70,6 +70,7 @@ enum op_type { OP_RETURN, OP_LOAD, OP_STORE, + OP_IOVLOAD, OP_BITWISE, OP_CMP, OP_RESOLVEDFD, @@ -210,6 +211,13 @@ struct op_store { struct gluten_offset count; }; +struct op_iovload { + struct gluten_offset iov; + struct gluten_offset iovlen; + struct gluten_offset dst; + size_t size; +}; + enum op_cmp_type { CMP_EQ, CMP_NE, @@ -278,6 +286,7 @@ struct op { struct op_fd fd; struct op_load load; struct op_store store; + struct op_iovload iovload; struct op_bitwise bitwise; struct op_cmp cmp; struct op_resolvefd resfd; @@ -291,8 +300,12 @@ struct op { # define GLUTEN_CONST const #endif +struct gluten_header { + struct gluten_offset relocation[256]; +}; + struct gluten { - GLUTEN_CONST char header[HEADER_SIZE]; + GLUTEN_CONST struct gluten_header header; GLUTEN_CONST char inst[INST_SIZE]; @@ -309,7 +322,7 @@ static inline bool is_offset_valid(const struct gluten_offset x) { switch (x.type) { case OFFSET_NULL: - return false; + return true; case OFFSET_DATA: return x.offset < DATA_SIZE; case OFFSET_RO_DATA: @@ -319,6 +332,7 @@ static inline bool is_offset_valid(const struct gluten_offset x) case OFFSET_SECCOMP_DATA: return x.offset < 6; default: + debug("unknown offset in range check"); return false; } } diff --git a/common/util.c b/common/util.c index 3e81a1c..94aeea3 100644 --- a/common/util.c +++ b/common/util.c @@ -18,6 +18,8 @@ #include "gluten.h" +#include "../cooker/calls.h" + #define logfn(name) \ void name(const char *format, ...) { \ va_list args; \ @@ -56,6 +58,24 @@ const char *cmp_type_str[CMP_MAX + 1] = { }; const char *metadata_type_str[METADATA_MAX + 1] = { "uid", "gid", "pid" }; + +const char *syscall_name(long nr) { + struct call **set, *call; + + for (set = call_sets, call = set[0]; *set; call++) { + if (!call->name) { + set++; + call = set[0]; + continue; + } + + if (nr == call->number) + break; + } + + return call ? call->name : "unknown"; +} + const char *syscall_name_str[N_SYSCALL + 1] = { [__NR_chown] = "chown", [__NR_connect] = "connect", diff --git a/common/util.h b/common/util.h index 1367c0d..61fb3fe 100644 --- a/common/util.h +++ b/common/util.h @@ -130,6 +130,7 @@ void debug(const char *format, ...); #define BITS_PER_NUM(n) (const_ilog2(n) + 1) #define N_SYSCALL 512 extern const char *syscall_name_str[N_SYSCALL + 1]; +const char *syscall_name(long nr); #define ret_clone_err(c, ...) \ do { \ -- cgit v1.2.3