All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Shuah Khan <shuah@kernel.org>,
	James Bottomley <James.Bottomley@HansenPartnership.com>,
	kernel@collabora.com, "kernelci.org bot" <bot@kernelci.org>,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests: secretmem: Floor the memory size to the multiple of page_size
Date: Fri, 15 Dec 2023 12:59:33 +0200	[thread overview]
Message-ID: <20231215105933.GO636165@kernel.org> (raw)
In-Reply-To: <20231214101931.1155586-1-usama.anjum@collabora.com>

On Thu, Dec 14, 2023 at 03:19:30PM +0500, Muhammad Usama Anjum wrote:
> 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.
> 
> Fixes: 76fe17ef588a ("secretmem: test: add basic selftest for memfd_secret(2)")
> Reported-by: "kernelci.org bot" <bot@kernelci.org>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
>  tools/testing/selftests/mm/memfd_secret.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/memfd_secret.c b/tools/testing/selftests/mm/memfd_secret.c
> index 957b9e18c729..9b298f6a04b3 100644
> --- a/tools/testing/selftests/mm/memfd_secret.c
> +++ b/tools/testing/selftests/mm/memfd_secret.c
> @@ -62,6 +62,9 @@ static void test_mlock_limit(int fd)
>  	char *mem;
>  
>  	len = mlock_limit_cur;
> +	if (len % page_size != 0)
> +		len = (len/page_size) * page_size;
> +

With mlock limit smaller than a page we get zero length here and mmap will
fail with -EINVAL because of it.
In this case I think we can just skip the first mmap and only check that
mmaping more than mlock limit fails.

>  	mem = mmap(NULL, len, prot, mode, fd, 0);
>  	if (mem == MAP_FAILED) {
>  		fail("unable to mmap secret memory\n");
> -- 
> 2.42.0
> 

-- 
Sincerely yours,
Mike.

  parent reply	other threads:[~2023-12-15 10:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-14 10:19 [PATCH] selftests: secretmem: Floor the memory size to the multiple of page_size Muhammad Usama Anjum
2023-12-14 19:40 ` Andrew Morton
2023-12-15  7:56   ` Muhammad Usama Anjum
2023-12-15 10:59 ` Mike Rapoport [this message]
2023-12-15 13:26   ` Muhammad Usama Anjum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231215105933.GO636165@kernel.org \
    --to=rppt@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=akpm@linux-foundation.org \
    --cc=bot@kernelci.org \
    --cc=kernel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shuah@kernel.org \
    --cc=usama.anjum@collabora.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.