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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bb2991f8-323a-c835-0b04-ff8d565df0fa@infradead.org>
Date:   Sun, 14 Apr 2019 08:24:53 -0700
From:   Randy Dunlap <rdunlap@...radead.org>
To:     Alexey Dobriyan <adobriyan@...il.com>, akpm@...ux-foundation.org
Cc:     linux-kernel@...r.kernel.org
Subject: Re: [PATCH] proc: fix map_files test on F29

On 4/14/19 5:36 AM, Alexey Dobriyan wrote:
> F29 bans mapping first 64KB even for root making test fail.

so there is an F29-only patch that prevents that?
something that is not in mainline?

thanks.

> Iterate from address 0 until mmap() works.
> 
> Gentoo (root):
> 
> 	openat(AT_FDCWD, "/dev/zero", O_RDONLY) = 3
> 	mmap(NULL, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0
> 
> Gentoo (non-root):
> 
> 	openat(AT_FDCWD, "/dev/zero", O_RDONLY) = 3
> 	mmap(NULL, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EPERM (Operation not permitted)
> 	mmap(0x1000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x1000
> 
> F29 (root):
> 
> 	openat(AT_FDCWD, "/dev/zero", O_RDONLY) = 3
> 	mmap(NULL, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0x1000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0x2000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0x3000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0x4000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0x5000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0x6000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0x7000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0x8000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0x9000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0xa000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0xb000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0xc000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0xd000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0xe000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0xf000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = -1 EACCES (Permission denied)
> 	mmap(0x10000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x10000
> 
> Now all proc tests succeed on F29 if run as root, at last!
> 
> Signed-off-by: Alexey Dobriyan <adobriyan@...il.com>
> ---
> 
>  tools/testing/selftests/proc/proc-self-map-files-002.c |   20 ++++++++---------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> --- a/tools/testing/selftests/proc/proc-self-map-files-002.c
> +++ b/tools/testing/selftests/proc/proc-self-map-files-002.c
> @@ -46,12 +46,9 @@ static void fail(const char *fmt, unsigned long a, unsigned long b)
>  
>  int main(void)
>  {
> -	const unsigned int PAGE_SIZE = sysconf(_SC_PAGESIZE);
> -#ifdef __arm__
> -	unsigned long va = 2 * PAGE_SIZE;
> -#else
> -	unsigned long va = 0;
> -#endif
> +	const int PAGE_SIZE = sysconf(_SC_PAGESIZE);
> +	const unsigned long va_max = 1UL << 32;
> +	unsigned long va;
>  	void *p;
>  	int fd;
>  	unsigned long a, b;
> @@ -60,10 +57,13 @@ int main(void)
>  	if (fd == -1)
>  		return 1;
>  
> -	p = mmap((void *)va, PAGE_SIZE, PROT_NONE, MAP_PRIVATE|MAP_FILE|MAP_FIXED, fd, 0);
> -	if (p == MAP_FAILED) {
> -		if (errno == EPERM)
> -			return 4;
> +	for (va = 0; va < va_max; va += PAGE_SIZE) {
> +		p = mmap((void *)va, PAGE_SIZE, PROT_NONE, MAP_PRIVATE|MAP_FILE|MAP_FIXED, fd, 0);
> +		if (p == (void *)va)
> +			break;
> +	}
> +	if (va == va_max) {
> +		fprintf(stderr, "error: mmap doesn't like you\n");
>  		return 1;
>  	}
>  
> 


-- 
~Randy

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ