Re: [PATCH bpf-next v9 7/8] bpf: lsm: Add selftests for BPF_PROG_TYPE_LSM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 02, 2020 at 01:53:06PM +0200, KP Singh wrote:
>  
> -int heap_mprotect(void)
> +#define PAGE_SIZE 4096
> +#define GET_PAGE_ADDR(ADDR)                                    \
> +       (char *)(((unsigned long) ADDR) & ~(PAGE_SIZE-1))
> +
> +int stack_mprotect(void)
>  {
> +
>         void *buf;
>         long sz;
>         int ret;
> @@ -25,12 +30,9 @@ int heap_mprotect(void)
>         if (sz < 0)
>                 return sz;
>  
> -       buf = memalign(sz, 2 * sz);
> -       if (buf == NULL)
> -               return -ENOMEM;
> -
> -       ret = mprotect(buf, sz, PROT_READ | PROT_WRITE | PROT_EXEC);
> -       free(buf);
> +       buf = alloca(PAGE_SIZE * 3);
> +       ret = mprotect(GET_PAGE_ADDR(buf + PAGE_SIZE), PAGE_SIZE,
> +                      PROT_READ | PROT_WRITE | PROT_EXEC);

Great. Something like this should work.
Please use sysconf(_SC_PAGE_SIZE); like prog_tests/mmap.c does.
selftests/bpf are run not only on x86



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux