[LTP] [PATCH v2 2/2] Add mseal01 test
Cyril Hrubis
chrubis@suse.cz
Thu Jul 25 17:55:24 CEST 2024
Hi!
> +static void child(unsigned int n)
> +{
> + struct tcase *tc = &tcases[n];
> +
> + mem_addr = SAFE_MMAP(NULL, mem_size,
> + tc->prot,
> + MAP_ANONYMOUS | MAP_PRIVATE,
> + -1, 0);
> +
> + tst_res(TINFO, "Testing %s", tc->message);
> +
> + TST_EXP_PASS(sys_mseal(mem_addr + mem_offset, mem_alignment));
> +
> + tc->func_test();
> +}
> +
> +static void run(unsigned int n)
> +{
> + /* the reason why we spawn a child is that mseal() will
> + * protect VMA until process will call _exit()
> + */
> + if (!SAFE_FORK()) {
> + child(n);
> + _exit(0);
> + }
> +
> + tst_reap_children();
> +
> + if (mem_addr != MAP_FAILED)
> + SAFE_MUNMAP(mem_addr, mem_size);
The memory is mapped in the child, it's hence not propagated to the
parent. With fork() only changes done in parent before the fork happens
are visible in child as well, since the memory is CoW.
> +}
> +
> +static void setup(void)
> +{
> + mem_alignment = getpagesize();
> + mem_size = mem_alignment * MEMPAGES;
> + mem_offset = mem_alignment * MEMSEAL;
> +}
> +
> +static void cleanup(void)
> +{
> + if (mem_addr != MAP_FAILED)
> + SAFE_MUNMAP(mem_addr, mem_size);
Here as well, this is useless, since the memory was allocated in child,
and freed automatically when the child exits.
The rest look fine.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list