Skip to content

Commit 0aac13a

Browse files
musamaanjumakpm00
authored andcommitted
selftests: secretmem: floor the memory size to the multiple of page_size
The "locked-in-memory size" limit per process can be non-multiple of page_size. The mmap() fails if we try to allocate locked-in-memory with same size as the allowed limit if it isn't multiple of the page_size because mmap() rounds off the memory size to be allocated to next multiple of page_size. Fix this by flooring the length to be allocated with mmap() to the previous multiple of the page_size. This was getting triggered on KernelCI regularly because of different ulimit settings which wasn't multiple of the page_size. Find logs here: https://linux.kernelci.org/test/plan/id/657654bd8e81e654fae13532/ The bug in was present from the time test was first added. Link: https://lkml.kernel.org/r/[email protected] Fixes: 76fe17e ("secretmem: test: add basic selftest for memfd_secret(2)") Signed-off-by: Muhammad Usama Anjum <[email protected]> Reported-by: "kernelci.org bot" <[email protected]> Closes: https://linux.kernelci.org/test/plan/id/657654bd8e81e654fae13532/ Cc: "James E.J. Bottomley" <[email protected]> Cc: Mike Rapoport (IBM) <[email protected]> Cc: Shuah Khan <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent fc346d0 commit 0aac13a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tools/testing/selftests/mm/memfd_secret.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ static void test_mlock_limit(int fd)
6262
char *mem;
6363

6464
len = mlock_limit_cur;
65+
if (len % page_size != 0)
66+
len = (len/page_size) * page_size;
67+
6568
mem = mmap(NULL, len, prot, mode, fd, 0);
6669
if (mem == MAP_FAILED) {
6770
fail("unable to mmap secret memory\n");

0 commit comments

Comments
 (0)