lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 24 Jan 2024 15:03:15 +0800
From: Muchun Song <muchun.song@...ux.dev>
To: Prakash Sangappa <prakash.sangappa@...cle.com>, linux-mm@...ck.org,
 linux-kernel@...r.kernel.org
Cc: mike.kravetz@...cle.com, akpm@...ux-foundation.org
Subject: Re: [PATCH v3] Hugetlb pages should not be reserved by shmat() if
 SHM_NORESERVE



On 2024/1/24 04:04, Prakash Sangappa wrote:
> For shared memory of type SHM_HUGETLB, hugetlb pages are reserved in
> shmget() call. If SHM_NORESERVE flags is specified then the hugetlb
> pages are not reserved. However when the shared memory is attached
> with the shmat() call the hugetlb pages are getting reserved incorrectly
> for SHM_HUGETLB shared memory created with SHM_NORESERVE which is a bug.
>
> -------------------------------
> Following test shows the issue.
>
> $cat shmhtb.c
>
> int main()
> {
> 	int shmflags = 0660 | IPC_CREAT | SHM_HUGETLB | SHM_NORESERVE;
> 	int shmid;
>
> 	shmid = shmget(SKEY, SHMSZ, shmflags);
> 	if (shmid < 0)
> 	{
> 		printf("shmat: shmget() failed, %d\n", errno);
> 		return 1;
> 	}
> 	printf("After shmget()\n");
> 	system("cat /proc/meminfo | grep -i hugepages_");
>
> 	shmat(shmid, NULL, 0);
> 	printf("\nAfter shmat()\n");
> 	system("cat /proc/meminfo | grep -i hugepages_");
>
> 	shmctl(shmid, IPC_RMID, NULL);
> 	return 0;
> }
>
>   #sysctl -w vm.nr_hugepages=20
>   #./shmhtb
>
> After shmget()
> HugePages_Total:      20
> HugePages_Free:       20
> HugePages_Rsvd:        0
> HugePages_Surp:        0
>
> After shmat()
> HugePages_Total:      20
> HugePages_Free:       20
> HugePages_Rsvd:        5 <--
> HugePages_Surp:        0
> --------------------------------
>
> Fix is to ensure that hugetlb pages are not reserved for SHM_HUGETLB shared
> memory in the shmat() call.
> Signed-off-by: Prakash Sangappa <prakash.sangappa@...cle.com>

BTW, it is better to add a Fixes tag to specify which commit
that this commit aims to fix.

Acked-by: Muchun Song <muchun.song@...ux.dev>

Thanks.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ