FreeBSD Bugzilla – Attachment 179980 Details for
Bug 217062
for file systems mounted with -o noexec, exec=off property does not work for mmap
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Minimal test
test_noexec.c (text/plain), 1.27 KB, created by
shamaz.mazum
on 2017-02-14 10:42:23 UTC
(
hide
)
Description:
Minimal test
Filename:
MIME Type:
Creator:
shamaz.mazum
Created:
2017-02-14 10:42:23 UTC
Size:
1.27 KB
patch
obsolete
>#include <fcntl.h> >#include <unistd.h> >#include <sys/mman.h> >#include <stdlib.h> >#include <stdio.h> > >int main (int argc, char *argv[]) >{ > if (argc != 2) > { > fprintf (stderr, "Usage: test <path-to-file-in-noexec-fs>\n"); > return 1; > } > > int fd = open (argv[1], O_RDONLY); > if (fd == -1) > { > perror ("Cannot open the file"); > return 1; > } > > /* > * Here is the interesting part. The file associated with fd lies on no-exec file system, > * Is it correct behaviour to allow PROT_EXEC protection here? > */ > > void *area = mmap (NULL, 4096, PROT_READ | PROT_EXEC, MAP_PRIVATE, fd, 0); > if (area == MAP_FAILED) > { > perror ("mmap test OK. Cannot map a file with PROT_EXEC"); > goto done; > } > > /* > * Here is the trick. You can set PROT_EXEC in mmap but cannot in mprotect. > */ > > printf ("mmap test failure. Mapped a no-exec file with PROT_EXEC\n"); > int res; > mprotect (area, 4096, PROT_NONE); > res = mprotect (area, 4096, PROT_READ|PROT_EXEC); > if (res == -1) > { > perror ("mprotect test OK."); > goto done; > } > printf ("mprotect test failure. Mapped a no-exec file with PROT_EXEC\n"); > >done: > > if (area != MAP_FAILED) munmap (area, 4096); > close (fd); > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 217062
:
179941
| 179980 |
179995