From b2e31a6e7493c56f923cb7d86f7a8a32940393ec Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Wed, 7 Jun 2023 14:07:23 +0200 Subject: seitan,cooker: op_resolvefd ops: - update resolvefd with the description - add debug prints cooker: - add emit_resolvefd when match has type FDPATH --- cooker/call.c | 1 + cooker/emit.c | 41 ++++++++++++++++++++++++++++++++++++++++- cooker/emit.h | 3 +++ cooker/match.c | 13 ++++++++++++- 4 files changed, 56 insertions(+), 2 deletions(-) (limited to 'cooker') diff --git a/cooker/call.c b/cooker/call.c index 289a0cb..7aef157 100644 --- a/cooker/call.c +++ b/cooker/call.c @@ -275,6 +275,7 @@ bool arg_needs_temp(struct field *f, int pos, JSON_Value *jvalue, return arg_needs_temp(f, pos, jvalue, NULL, level + 1); return false; + case FDPATH: case STRING: return false; case STRUCT: diff --git a/cooker/emit.c b/cooker/emit.c index d0928e3..7b1b14d 100644 --- a/cooker/emit.c +++ b/cooker/emit.c @@ -163,6 +163,40 @@ void emit_load(struct gluten_ctx *g, struct gluten_offset dst, die("Too many instructions"); } +/** + * emit_resolved() - Emit OP_RESOLVEFD instruction: resolve file descriptor with path + * @g: gluten context + * @fd: offset of the file descriptor value + * @path: offset of the path + * @path_size: size of the path + */ +void emit_resolvefd(struct gluten_ctx *g, struct gluten_offset fd, + struct gluten_offset path, size_t path_size) +{ + struct op *op = (struct op *)gluten_ptr(&g->g, g->ip); + struct op_resolvefd *resfd = &op->op.resfd; + struct gluten_offset o; + struct resolvefd_desc *desc; + + op->type = OP_RESOLVEDFD; + o = gluten_ro_alloc(g, sizeof(struct resolvefd_desc)); + desc = (struct resolvefd_desc *)gluten_ptr(&g->g, o); + + desc->fd = fd; + desc->path = path; + desc->path_max = path_size; + + resfd->desc = o; + + debug(" %i: OP_RESOLVEDFD:", g->ip.offset); + debug(" \tfd: %s offset=%d", gluten_offset_name[fd.type], fd.offset); + debug(" \tpath: %s offset=%d size=%d", gluten_offset_name[path.type], + path.offset, path_size); + + if (++g->ip.offset > INST_MAX) + die("Too many instructions"); +} + /** * emit_mask(): Emit OP_MASK instruction: mask and store * @g: gluten context @@ -422,7 +456,7 @@ static struct gluten_offset emit_data_do(struct gluten_ctx *g, break; case STRING: strncpy(p, value->v_str, str_len); - debug(" C#%i: (%s:%i) %s", g->cp.offset, type_str[type], + debug(" C#%i: (%s:%i) %s", ret.offset, type_str[type], str_len, value->v_str); break; @@ -459,6 +493,11 @@ struct gluten_offset emit_data_or(struct gluten_ctx *g, true); } +struct gluten_offset emit_seccomp_data(int index) { + struct gluten_offset o = { OFFSET_SECCOMP_DATA, index }; + return o; +} + static void gluten_link(struct gluten_ctx *g, enum jump_type type, struct op *start) { diff --git a/cooker/emit.h b/cooker/emit.h index 9ec64e0..18618ee 100644 --- a/cooker/emit.h +++ b/cooker/emit.h @@ -16,6 +16,7 @@ void emit_load(struct gluten_ctx *g, struct gluten_offset dst, struct gluten_offset emit_mask(struct gluten_ctx *g, enum type type, struct gluten_offset src, struct gluten_offset mask); +struct gluten_offset emit_seccomp_data(int index); void emit_cmp(struct gluten_ctx *g, enum op_cmp_type cmp, struct gluten_offset x, struct gluten_offset y, size_t size, enum jump_type jmp); @@ -29,6 +30,8 @@ void emit_copy(struct gluten_ctx *g, struct gluten_offset dst, struct gluten_offset src, size_t size); void emit_copy_field(struct gluten_ctx *g, struct field *field, struct gluten_offset dst, struct gluten_offset src); +void emit_resolvefd(struct gluten_ctx *g, struct gluten_offset fd, + struct gluten_offset path, size_t path_size); void emit_end(struct gluten_ctx *g); struct gluten_offset emit_data(struct gluten_ctx *g, enum type type, size_t str_len, union value *value); diff --git a/cooker/match.c b/cooker/match.c index e9aed16..3c7650c 100644 --- a/cooker/match.c +++ b/cooker/match.c @@ -78,13 +78,14 @@ static union value parse_field(struct gluten_ctx *g, enum op_cmp_type cmp, enum jump_type jump, int index, struct field *f, JSON_Value *jvalue) { - struct gluten_offset const_offset, mask_offset, data_offset; + struct gluten_offset const_offset, mask_offset, data_offset, seccomp_offset; union value v = { .v_num = 0 }; struct field *f_inner; const char *tag_name; JSON_Object *tmp; JSON_Array *set; JSON_Value *sel; + size_t size; if (f->name) debug(" parsing field name %s", f->name); @@ -202,6 +203,16 @@ xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx emit_cmp(g, CMP_NE, offset, const_offset, strlen(v.v_str) + 1, JUMP_NEXT_BLOCK); break; + case FDPATH: + v.v_str = json_value_get_string(jvalue); + size = strlen(v.v_str) + 1; + offset = gluten_rw_alloc(g, size); + const_offset = emit_data(g, STRING, size, &v); + seccomp_offset = emit_seccomp_data(index); + emit_resolvefd(g, seccomp_offset, offset, size); + emit_cmp(g, CMP_NE, offset, const_offset, size, + JUMP_NEXT_BLOCK); + break; case STRUCT: for (f_inner = f->desc.d_struct; f_inner->name; f_inner++) { JSON_Value *field_value; -- cgit v1.2.3