From 1c1a9da7a4f9c4c1990192e14763ebf423d812a9 Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Wed, 7 Jun 2023 16:54:53 +0200 Subject: seitan, cooker: refactor op_return Refactor OP_RETURN: - merged OP_BLOCK and OP_CONT into OP_RETURN - add desc field for op_return - updated the demo files --- operations.c | 59 +++++++++++++++-------------------------------------------- 1 file changed, 15 insertions(+), 44 deletions(-) (limited to 'operations.c') diff --git a/operations.c b/operations.c index 50fdcfb..eefc746 100644 --- a/operations.c +++ b/operations.c @@ -261,54 +261,27 @@ out: return ret; } -int op_block(const struct seccomp_notif *req, int notifier, struct gluten *g, - struct op_block *op) -{ - struct seccomp_notif_resp resp; - - (void)g; - resp.id = req->id; - resp.val = 0; - resp.flags = 0; - resp.error = op->error; - - if (send_target(&resp, notifier) == -1) - return -1; - - return 0; -} - int op_return(const struct seccomp_notif *req, int notifier, struct gluten *g, struct op_return *op) { + const struct return_desc *desc = gluten_ptr(&req->data, g, op->desc); struct seccomp_notif_resp resp; resp.id = req->id; - resp.flags = 0; - resp.error = 0; - - if (gluten_read(&req->data, g, &resp.val, op->val, sizeof(resp.val)) == - -1) - return -1; - - if (send_target(&resp, notifier) == -1) - return -1; - - return 0; -} - -int op_continue(const struct seccomp_notif *req, int notifier, struct gluten *g, - void *op) -{ - struct seccomp_notif_resp resp; - - (void)g; - (void)op; - - resp.id = req->id; - resp.flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE; - resp.error = 0; - resp.val = 0; + if (desc->cont) { + resp.flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE; + resp.error = 0; + resp.val = 0; + debug(" op_return: continue the syscall"); + } else { + resp.id = req->id; + resp.flags = 0; + resp.error = desc->error; + if (gluten_read(&req->data, g, &resp.val, desc->val, + sizeof(resp.val)) == -1) + return -1; + debug(" op_return: val=%ld errno=%d", resp.val, resp.error); + } if (send_target(&resp, notifier) == -1) return -1; @@ -489,9 +462,7 @@ int eval(struct gluten *g, const struct seccomp_notif *req, debug("at instruction %i", op - (struct op *)g->inst); switch (op->type) { HANDLE_OP(OP_CALL, op_call, call, g); - HANDLE_OP(OP_BLOCK, op_block, block, g); HANDLE_OP(OP_RETURN, op_return, ret, g); - HANDLE_OP(OP_CONT, op_continue, NO_FIELD, g); HANDLE_OP(OP_FD, op_fd, fd, g); HANDLE_OP(OP_LOAD, op_load, load, g); HANDLE_OP(OP_MASK, op_mask, mask, g); -- cgit v1.2.3