From 52e2835061429d93abacf8d1cf00f7da69e7a853 Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Mon, 27 Feb 2023 13:19:01 +0100 Subject: seitan: add op_cmp The operation op_cmp allows to compare 2 areas of memory and if they don't match to jump to an operation. --- gluten.h | 9 +++++++++ operations.c | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/gluten.h b/gluten.h index 69a6b6b..570d82a 100644 --- a/gluten.h +++ b/gluten.h @@ -52,6 +52,7 @@ enum op_type { OP_RETURN, OP_COPY_ARGS, OP_END, + OP_CMP, }; enum value_type { @@ -106,6 +107,13 @@ struct op_copy_args { struct copy_arg args[6]; }; +struct op_cmp { + uint16_t s1_off; + uint16_t s2_off; + size_t size; + unsigned int jmp; +}; + struct op { enum op_type type; union { @@ -115,6 +123,7 @@ struct op { struct op_return ret; struct op_inject inj; struct op_copy_args copy; + struct op_cmp cmp; }; }; #endif /* GLUTEN_H */ diff --git a/operations.c b/operations.c index 8cd0828..afc4b00 100644 --- a/operations.c +++ b/operations.c @@ -313,6 +313,12 @@ int do_operations(void *data, struct op operations[], struct seccomp_notif *req, break; case OP_END: return 0; + case OP_CMP: + if (memcmp((uint16_t *)data + operations[i].cmp.s1_off, + (uint16_t *)data + operations[i].cmp.s2_off, + operations[i].cmp.size) != 0) { + i = operations[i].cmp.jmp; + } break; default: fprintf(stderr, "unknow operation %d \n", -- cgit v1.2.3