[LTP] [RFC PATCH 2/9] lib: Add a canary for guarded buffers
Jan Stancek
jstancek@redhat.com
Thu Aug 1 12:43:10 CEST 2019
----- Original Message -----
> In a case that the buffer size is not a multiple of a page size there is
> unused space before the start of the buffer. Let's fill that with
> center mirrored random bytes and check that the buffer wasn't modified
> before we unmap it.
>
> void *tst_alloc(size_t size)
> {
> size_t page_size = getpagesize();
> @@ -34,9 +61,13 @@ void *tst_alloc(size_t size)
> maps = map;
>
> if (size % page_size)
> - ret += page_size - (size % page_size);
> + map->buf_shift = page_size - (size % page_size);
> + else
> + map->buf_shift = 0;
> +
> + setup_canary(map);
>
> - return ret;
> + return ret + map->buf_shift;
My concern here is alignment.
More information about the ltp
mailing list