Nested anonymous randomization boundaries

This commit is contained in:
York Jasper Niebuhr 2026-04-03 23:25:30 +02:00
parent 0eba2ac3a1
commit aae833788f
3 changed files with 26 additions and 7 deletions

View File

@ -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

View File

@ -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)

View File

@ -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;
};