From aae833788f9b24a450acd661aedbf582149f5bd2 Mon Sep 17 00:00:00 2001 From: York Jasper Niebuhr Date: Fri, 3 Apr 2026 23:25:30 +0200 Subject: [PATCH] Nested anonymous randomization boundaries --- plan.txt | 4 ++-- subject/main.c | 9 ++++++--- subject/task_struct.h | 20 ++++++++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/plan.txt b/plan.txt index 7728dbd..6f881ee 100644 --- a/plan.txt +++ b/plan.txt @@ -1,5 +1,5 @@ -Collect alignment data on struct members -Fix bit fields and dynamic size fields (at end of structs) in place +Collect alignment data from struct members +Fix bit fields in place Move patcher generation to pre-link stage - Aggregate meta data files diff --git a/subject/main.c b/subject/main.c index 0555413..b8a42dc 100644 --- a/subject/main.c +++ b/subject/main.c @@ -10,9 +10,12 @@ struct task_struct global = { .pid = 42, .comm = "main_global" }; static void print_layout() { // TODO -> Make builtin __spslr_initial_offsetof(type, field) that is not patched printf("Current task_struct layout:\n"); - printf(" pid (int) : %2llu -> %2llu\n", 0, offsetof(struct task_struct, pid)); - printf(" comm (const char*) : %2llu -> %2llu\n", 8, offsetof(struct task_struct, comm)); - printf(" tasks (struct list_head) : %2llu -> %2llu\n", 16, offsetof(struct task_struct, tasks)); + printf(" stuck0 (int) : %2llu -> %2llu\n", 0, offsetof(struct task_struct, stuck0)); + printf(" pid (int) : %2llu -> %2llu\n", 8, offsetof(struct task_struct, pid)); + printf(" comm (const char*) : %2llu -> %2llu\n", 16, offsetof(struct task_struct, comm)); + printf(" tasks (struct list_head) : %2llu -> %2llu\n", 24, offsetof(struct task_struct, tasks)); + printf(" stuck1 (int) : %2llu -> %2llu\n", 40, offsetof(struct task_struct, stuck1)); + printf(" stuck2 (int) : %2llu -> %2llu\n", 44, offsetof(struct task_struct, stuck2)); } int main(void) diff --git a/subject/task_struct.h b/subject/task_struct.h index 5cf4f70..6d16631 100644 --- a/subject/task_struct.h +++ b/subject/task_struct.h @@ -5,6 +5,9 @@ const typeof(((type*)0)->member)* __mptr = (ptr); \ (type*)((char*)__mptr - offsetof(type, member)); }) +# define randomized_struct_fields_start struct { +# define randomized_struct_fields_end } __attribute__((spslr)); + // Minimal doubly linked list struct list_head { struct list_head *next, *prev; @@ -42,8 +45,21 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head) // A small struct like the Linux kernel's task_struct struct task_struct { + int stuck0; + + randomized_struct_fields_start + + randomized_struct_fields_start + int pid; const char *comm; - struct list_head tasks; // linkage for global task list -} __attribute__((spslr)); + + randomized_struct_fields_end + + struct list_head tasks; // linkage for global task list + + randomized_struct_fields_end + + int stuck1, stuck2; +};