public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] cheri: Fix capability permissions of PROT_NONE maps in test code
@ 2022-10-26 15:17 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-10-26 15:17 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c071b1720e7bfdaf4c2da1ec8ede1fd6948af001
commit c071b1720e7bfdaf4c2da1ec8ede1fd6948af001
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue Oct 25 09:14:46 2022 +0100
cheri: Fix capability permissions of PROT_NONE maps in test code
Diff:
---
support/blob_repeat.c | 2 +-
support/support_stack_alloc.c | 2 +-
support/xunistd.h | 8 ++++++++
sysdeps/unix/sysv/linux/tst-pkey.c | 2 +-
4 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/support/blob_repeat.c b/support/blob_repeat.c
index 2c952906ea..5e5fecac00 100644
--- a/support/blob_repeat.c
+++ b/support/blob_repeat.c
@@ -151,7 +151,7 @@ allocate_big (size_t total_size, const void *element, size_t element_size,
/* Reserve the memory region. If we cannot create the mapping,
there is no reason to set up the backing file. */
- void *target = mmap (NULL, total_size, PROT_NONE,
+ void *target = mmap (NULL, total_size, PROT_NONE | PROT_MAX_RW,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (target == MAP_FAILED)
return (struct support_blob_repeat) { 0 };
diff --git a/support/support_stack_alloc.c b/support/support_stack_alloc.c
index 77115fceb1..c138c0d4f9 100644
--- a/support/support_stack_alloc.c
+++ b/support/support_stack_alloc.c
@@ -60,7 +60,7 @@ support_stack_alloc (size_t size)
so we know they are allocated. */
void *alloc_base = xmmap (0,
alloc_size,
- PROT_NONE,
+ PROT_NONE|PROT_MAX_RW,
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_STACK,
-1);
/* Some architecture still requires executable stack for the signal return
diff --git a/support/xunistd.h b/support/xunistd.h
index 960a62d412..2429424443 100644
--- a/support/xunistd.h
+++ b/support/xunistd.h
@@ -25,6 +25,7 @@
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/mman.h>
#include <unistd.h>
__BEGIN_DECLS
@@ -77,6 +78,13 @@ void xclose (int);
/* Write the buffer. Retry on short writes. */
void xwrite (int, const void *, size_t);
+/* On CHERI targets ensure the mmap returned capability has RW permissions. */
+#ifdef PROT_MAX
+# define PROT_MAX_RW PROT_MAX (PROT_READ | PROT_WRITE)
+#else
+# define PROT_MAX_RW 0
+#endif
+
/* Invoke mmap with a zero file offset. */
void *xmmap (void *addr, size_t length, int prot, int flags, int fd);
void xmprotect (void *addr, size_t length, int prot);
diff --git a/sysdeps/unix/sysv/linux/tst-pkey.c b/sysdeps/unix/sysv/linux/tst-pkey.c
index df51f695bc..48b4308d63 100644
--- a/sysdeps/unix/sysv/linux/tst-pkey.c
+++ b/sysdeps/unix/sysv/linux/tst-pkey.c
@@ -175,7 +175,7 @@ do_test (void)
/* pkey_mprotect with key -1 should work even when there is no
protection key support. */
{
- int *page = xmmap (NULL, pagesize, PROT_NONE,
+ int *page = xmmap (NULL, pagesize, PROT_NONE | PROT_MAX_RW,
MAP_ANONYMOUS | MAP_PRIVATE, -1);
TEST_COMPARE (pkey_mprotect (page, pagesize, PROT_READ | PROT_WRITE, -1),
0);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/arm/morello/main] cheri: Fix capability permissions of PROT_NONE maps in test code
@ 2022-11-23 14:46 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-11-23 14:46 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=8f6565fa273e95dfedf84366629e815f759d3f76
commit 8f6565fa273e95dfedf84366629e815f759d3f76
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue Oct 25 09:14:46 2022 +0100
cheri: Fix capability permissions of PROT_NONE maps in test code
Diff:
---
support/blob_repeat.c | 2 +-
support/support_stack_alloc.c | 2 +-
support/xunistd.h | 8 ++++++++
sysdeps/unix/sysv/linux/tst-pkey.c | 2 +-
4 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/support/blob_repeat.c b/support/blob_repeat.c
index 2c952906ea..5e5fecac00 100644
--- a/support/blob_repeat.c
+++ b/support/blob_repeat.c
@@ -151,7 +151,7 @@ allocate_big (size_t total_size, const void *element, size_t element_size,
/* Reserve the memory region. If we cannot create the mapping,
there is no reason to set up the backing file. */
- void *target = mmap (NULL, total_size, PROT_NONE,
+ void *target = mmap (NULL, total_size, PROT_NONE | PROT_MAX_RW,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (target == MAP_FAILED)
return (struct support_blob_repeat) { 0 };
diff --git a/support/support_stack_alloc.c b/support/support_stack_alloc.c
index 77115fceb1..c138c0d4f9 100644
--- a/support/support_stack_alloc.c
+++ b/support/support_stack_alloc.c
@@ -60,7 +60,7 @@ support_stack_alloc (size_t size)
so we know they are allocated. */
void *alloc_base = xmmap (0,
alloc_size,
- PROT_NONE,
+ PROT_NONE|PROT_MAX_RW,
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_STACK,
-1);
/* Some architecture still requires executable stack for the signal return
diff --git a/support/xunistd.h b/support/xunistd.h
index 960a62d412..2429424443 100644
--- a/support/xunistd.h
+++ b/support/xunistd.h
@@ -25,6 +25,7 @@
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/mman.h>
#include <unistd.h>
__BEGIN_DECLS
@@ -77,6 +78,13 @@ void xclose (int);
/* Write the buffer. Retry on short writes. */
void xwrite (int, const void *, size_t);
+/* On CHERI targets ensure the mmap returned capability has RW permissions. */
+#ifdef PROT_MAX
+# define PROT_MAX_RW PROT_MAX (PROT_READ | PROT_WRITE)
+#else
+# define PROT_MAX_RW 0
+#endif
+
/* Invoke mmap with a zero file offset. */
void *xmmap (void *addr, size_t length, int prot, int flags, int fd);
void xmprotect (void *addr, size_t length, int prot);
diff --git a/sysdeps/unix/sysv/linux/tst-pkey.c b/sysdeps/unix/sysv/linux/tst-pkey.c
index df51f695bc..48b4308d63 100644
--- a/sysdeps/unix/sysv/linux/tst-pkey.c
+++ b/sysdeps/unix/sysv/linux/tst-pkey.c
@@ -175,7 +175,7 @@ do_test (void)
/* pkey_mprotect with key -1 should work even when there is no
protection key support. */
{
- int *page = xmmap (NULL, pagesize, PROT_NONE,
+ int *page = xmmap (NULL, pagesize, PROT_NONE | PROT_MAX_RW,
MAP_ANONYMOUS | MAP_PRIVATE, -1);
TEST_COMPARE (pkey_mprotect (page, pagesize, PROT_READ | PROT_WRITE, -1),
0);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/arm/morello/main] cheri: Fix capability permissions of PROT_NONE maps in test code
@ 2022-10-27 13:56 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-10-27 13:56 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=29844295c53af4dae2f88a62464a596414b4d269
commit 29844295c53af4dae2f88a62464a596414b4d269
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue Oct 25 09:14:46 2022 +0100
cheri: Fix capability permissions of PROT_NONE maps in test code
Diff:
---
support/blob_repeat.c | 2 +-
support/support_stack_alloc.c | 2 +-
support/xunistd.h | 8 ++++++++
sysdeps/unix/sysv/linux/tst-pkey.c | 2 +-
4 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/support/blob_repeat.c b/support/blob_repeat.c
index 2c952906ea..5e5fecac00 100644
--- a/support/blob_repeat.c
+++ b/support/blob_repeat.c
@@ -151,7 +151,7 @@ allocate_big (size_t total_size, const void *element, size_t element_size,
/* Reserve the memory region. If we cannot create the mapping,
there is no reason to set up the backing file. */
- void *target = mmap (NULL, total_size, PROT_NONE,
+ void *target = mmap (NULL, total_size, PROT_NONE | PROT_MAX_RW,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (target == MAP_FAILED)
return (struct support_blob_repeat) { 0 };
diff --git a/support/support_stack_alloc.c b/support/support_stack_alloc.c
index 77115fceb1..c138c0d4f9 100644
--- a/support/support_stack_alloc.c
+++ b/support/support_stack_alloc.c
@@ -60,7 +60,7 @@ support_stack_alloc (size_t size)
so we know they are allocated. */
void *alloc_base = xmmap (0,
alloc_size,
- PROT_NONE,
+ PROT_NONE|PROT_MAX_RW,
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_STACK,
-1);
/* Some architecture still requires executable stack for the signal return
diff --git a/support/xunistd.h b/support/xunistd.h
index 960a62d412..2429424443 100644
--- a/support/xunistd.h
+++ b/support/xunistd.h
@@ -25,6 +25,7 @@
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/mman.h>
#include <unistd.h>
__BEGIN_DECLS
@@ -77,6 +78,13 @@ void xclose (int);
/* Write the buffer. Retry on short writes. */
void xwrite (int, const void *, size_t);
+/* On CHERI targets ensure the mmap returned capability has RW permissions. */
+#ifdef PROT_MAX
+# define PROT_MAX_RW PROT_MAX (PROT_READ | PROT_WRITE)
+#else
+# define PROT_MAX_RW 0
+#endif
+
/* Invoke mmap with a zero file offset. */
void *xmmap (void *addr, size_t length, int prot, int flags, int fd);
void xmprotect (void *addr, size_t length, int prot);
diff --git a/sysdeps/unix/sysv/linux/tst-pkey.c b/sysdeps/unix/sysv/linux/tst-pkey.c
index df51f695bc..48b4308d63 100644
--- a/sysdeps/unix/sysv/linux/tst-pkey.c
+++ b/sysdeps/unix/sysv/linux/tst-pkey.c
@@ -175,7 +175,7 @@ do_test (void)
/* pkey_mprotect with key -1 should work even when there is no
protection key support. */
{
- int *page = xmmap (NULL, pagesize, PROT_NONE,
+ int *page = xmmap (NULL, pagesize, PROT_NONE | PROT_MAX_RW,
MAP_ANONYMOUS | MAP_PRIVATE, -1);
TEST_COMPARE (pkey_mprotect (page, pagesize, PROT_READ | PROT_WRITE, -1),
0);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/arm/morello/main] cheri: Fix capability permissions of PROT_NONE maps in test code
@ 2022-10-26 14:49 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-10-26 14:49 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=df30ef1b0d68ffde8dfb0a18ac08b97fe375d813
commit df30ef1b0d68ffde8dfb0a18ac08b97fe375d813
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue Oct 25 09:14:46 2022 +0100
cheri: Fix capability permissions of PROT_NONE maps in test code
Diff:
---
support/blob_repeat.c | 2 +-
support/support_stack_alloc.c | 2 +-
support/xunistd.h | 8 ++++++++
sysdeps/unix/sysv/linux/tst-pkey.c | 2 +-
4 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/support/blob_repeat.c b/support/blob_repeat.c
index 2c952906ea..5e5fecac00 100644
--- a/support/blob_repeat.c
+++ b/support/blob_repeat.c
@@ -151,7 +151,7 @@ allocate_big (size_t total_size, const void *element, size_t element_size,
/* Reserve the memory region. If we cannot create the mapping,
there is no reason to set up the backing file. */
- void *target = mmap (NULL, total_size, PROT_NONE,
+ void *target = mmap (NULL, total_size, PROT_NONE | PROT_MAX_RW,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (target == MAP_FAILED)
return (struct support_blob_repeat) { 0 };
diff --git a/support/support_stack_alloc.c b/support/support_stack_alloc.c
index 77115fceb1..c138c0d4f9 100644
--- a/support/support_stack_alloc.c
+++ b/support/support_stack_alloc.c
@@ -60,7 +60,7 @@ support_stack_alloc (size_t size)
so we know they are allocated. */
void *alloc_base = xmmap (0,
alloc_size,
- PROT_NONE,
+ PROT_NONE|PROT_MAX_RW,
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_STACK,
-1);
/* Some architecture still requires executable stack for the signal return
diff --git a/support/xunistd.h b/support/xunistd.h
index 960a62d412..2429424443 100644
--- a/support/xunistd.h
+++ b/support/xunistd.h
@@ -25,6 +25,7 @@
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/mman.h>
#include <unistd.h>
__BEGIN_DECLS
@@ -77,6 +78,13 @@ void xclose (int);
/* Write the buffer. Retry on short writes. */
void xwrite (int, const void *, size_t);
+/* On CHERI targets ensure the mmap returned capability has RW permissions. */
+#ifdef PROT_MAX
+# define PROT_MAX_RW PROT_MAX (PROT_READ | PROT_WRITE)
+#else
+# define PROT_MAX_RW 0
+#endif
+
/* Invoke mmap with a zero file offset. */
void *xmmap (void *addr, size_t length, int prot, int flags, int fd);
void xmprotect (void *addr, size_t length, int prot);
diff --git a/sysdeps/unix/sysv/linux/tst-pkey.c b/sysdeps/unix/sysv/linux/tst-pkey.c
index df51f695bc..48b4308d63 100644
--- a/sysdeps/unix/sysv/linux/tst-pkey.c
+++ b/sysdeps/unix/sysv/linux/tst-pkey.c
@@ -175,7 +175,7 @@ do_test (void)
/* pkey_mprotect with key -1 should work even when there is no
protection key support. */
{
- int *page = xmmap (NULL, pagesize, PROT_NONE,
+ int *page = xmmap (NULL, pagesize, PROT_NONE | PROT_MAX_RW,
MAP_ANONYMOUS | MAP_PRIVATE, -1);
TEST_COMPARE (pkey_mprotect (page, pagesize, PROT_READ | PROT_WRITE, -1),
0);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-23 14:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-26 15:17 [glibc/arm/morello/main] cheri: Fix capability permissions of PROT_NONE maps in test code Szabolcs Nagy
-- strict thread matches above, loose matches on Subject: below --
2022-11-23 14:46 Szabolcs Nagy
2022-10-27 13:56 Szabolcs Nagy
2022-10-26 14:49 Szabolcs Nagy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).