public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] cheri: elf: Fix segment mapping permissions
@ 2022-11-23 14:47 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-11-23 14:47 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=81c2de89c6f6e9ade26f28e2ff65c5c0510600da
commit 81c2de89c6f6e9ade26f28e2ff65c5c0510600da
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Fri Oct 21 12:38:26 2022 +0100
cheri: elf: Fix segment mapping permissions
Ensure mmap returns pointers with RWX permission covering all segments.
These pointers later get restricted to RX and RW permission.
Diff:
---
elf/dl-map-segments.h | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h
index ce51585ce4..e25fb579df 100644
--- a/elf/dl-map-segments.h
+++ b/elf/dl-map-segments.h
@@ -22,6 +22,13 @@
# include <cheri_perms.h>
#endif
+/* Allow RWX mprotect later, on CHERI this means RWX capability permission. */
+#ifdef PROT_MAX
+# define PROT_MAX_RWX PROT_MAX (PROT_READ | PROT_WRITE | PROT_EXEC)
+#else
+# define PROT_MAX_RWX 0
+#endif
+
/* Map a segment and align it properly. */
static __always_inline elfptr_t
@@ -29,7 +36,8 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
const size_t maplength, int fd)
{
if (__glibc_likely (c->mapalign <= GLRO(dl_pagesize)))
- return (elfptr_t) __mmap ((void *) mappref, maplength, c->prot,
+ return (elfptr_t) __mmap ((void *) mappref, maplength,
+ c->prot|PROT_MAX_RWX,
MAP_COPY|MAP_FILE, fd, c->mapoff);
/* If the segment alignment > the page size, allocate enough space to
@@ -38,7 +46,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
? (maplength + c->mapalign)
: (2 * c->mapalign));
elfptr_t map_start = (elfptr_t) __mmap ((void *) mappref, maplen,
- PROT_NONE,
+ PROT_NONE|PROT_MAX_RWX,
MAP_ANONYMOUS|MAP_PRIVATE,
-1, 0);
if (__glibc_unlikely ((void *) map_start == MAP_FAILED))
@@ -46,7 +54,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
elfptr_t map_start_aligned = ALIGN_UP (map_start, c->mapalign);
map_start_aligned = (elfptr_t) __mmap ((void *) map_start_aligned,
- maplength, c->prot,
+ maplength, c->prot|PROT_MAX_RWX,
MAP_COPY|MAP_FILE|MAP_FIXED,
fd, c->mapoff);
if (__glibc_unlikely ((void *) map_start_aligned == MAP_FAILED))
@@ -137,7 +145,8 @@ _dl_map_segments (struct link_map *l, int fd,
else
{
/* Need a single capability to cover all load segments. */
- void *p = __mmap ((void *) c->mapstart, maplength, c->prot,
+ void *p = __mmap ((void *) c->mapstart, maplength,
+ c->prot|PROT_MAX_RWX,
MAP_FIXED|MAP_COPY|MAP_FILE,
fd, c->mapoff);
if (p == MAP_FAILED)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/arm/morello/main] cheri: elf: Fix segment mapping permissions
@ 2022-10-27 13:57 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-10-27 13:57 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=28bd4285ad0f8ce6026583e9cc0a612018d461ba
commit 28bd4285ad0f8ce6026583e9cc0a612018d461ba
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Fri Oct 21 12:38:26 2022 +0100
cheri: elf: Fix segment mapping permissions
Ensure mmap returns pointers with RWX permission covering all segments.
These pointers later get restricted to RX and RW permission.
Diff:
---
elf/dl-map-segments.h | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h
index ce51585ce4..e25fb579df 100644
--- a/elf/dl-map-segments.h
+++ b/elf/dl-map-segments.h
@@ -22,6 +22,13 @@
# include <cheri_perms.h>
#endif
+/* Allow RWX mprotect later, on CHERI this means RWX capability permission. */
+#ifdef PROT_MAX
+# define PROT_MAX_RWX PROT_MAX (PROT_READ | PROT_WRITE | PROT_EXEC)
+#else
+# define PROT_MAX_RWX 0
+#endif
+
/* Map a segment and align it properly. */
static __always_inline elfptr_t
@@ -29,7 +36,8 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
const size_t maplength, int fd)
{
if (__glibc_likely (c->mapalign <= GLRO(dl_pagesize)))
- return (elfptr_t) __mmap ((void *) mappref, maplength, c->prot,
+ return (elfptr_t) __mmap ((void *) mappref, maplength,
+ c->prot|PROT_MAX_RWX,
MAP_COPY|MAP_FILE, fd, c->mapoff);
/* If the segment alignment > the page size, allocate enough space to
@@ -38,7 +46,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
? (maplength + c->mapalign)
: (2 * c->mapalign));
elfptr_t map_start = (elfptr_t) __mmap ((void *) mappref, maplen,
- PROT_NONE,
+ PROT_NONE|PROT_MAX_RWX,
MAP_ANONYMOUS|MAP_PRIVATE,
-1, 0);
if (__glibc_unlikely ((void *) map_start == MAP_FAILED))
@@ -46,7 +54,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
elfptr_t map_start_aligned = ALIGN_UP (map_start, c->mapalign);
map_start_aligned = (elfptr_t) __mmap ((void *) map_start_aligned,
- maplength, c->prot,
+ maplength, c->prot|PROT_MAX_RWX,
MAP_COPY|MAP_FILE|MAP_FIXED,
fd, c->mapoff);
if (__glibc_unlikely ((void *) map_start_aligned == MAP_FAILED))
@@ -137,7 +145,8 @@ _dl_map_segments (struct link_map *l, int fd,
else
{
/* Need a single capability to cover all load segments. */
- void *p = __mmap ((void *) c->mapstart, maplength, c->prot,
+ void *p = __mmap ((void *) c->mapstart, maplength,
+ c->prot|PROT_MAX_RWX,
MAP_FIXED|MAP_COPY|MAP_FILE,
fd, c->mapoff);
if (p == MAP_FAILED)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/arm/morello/main] cheri: elf: Fix segment mapping permissions
@ 2022-10-26 15:19 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-10-26 15:19 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b87eb52c0f6016f2adbcb7c5de004fc5dde22cb9
commit b87eb52c0f6016f2adbcb7c5de004fc5dde22cb9
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Fri Oct 21 12:38:26 2022 +0100
cheri: elf: Fix segment mapping permissions
Ensure mmap returns pointers with RWX permission covering all segments.
These pointers later get restricted to RX and RW permission.
Diff:
---
elf/dl-map-segments.h | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h
index ce51585ce4..e25fb579df 100644
--- a/elf/dl-map-segments.h
+++ b/elf/dl-map-segments.h
@@ -22,6 +22,13 @@
# include <cheri_perms.h>
#endif
+/* Allow RWX mprotect later, on CHERI this means RWX capability permission. */
+#ifdef PROT_MAX
+# define PROT_MAX_RWX PROT_MAX (PROT_READ | PROT_WRITE | PROT_EXEC)
+#else
+# define PROT_MAX_RWX 0
+#endif
+
/* Map a segment and align it properly. */
static __always_inline elfptr_t
@@ -29,7 +36,8 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
const size_t maplength, int fd)
{
if (__glibc_likely (c->mapalign <= GLRO(dl_pagesize)))
- return (elfptr_t) __mmap ((void *) mappref, maplength, c->prot,
+ return (elfptr_t) __mmap ((void *) mappref, maplength,
+ c->prot|PROT_MAX_RWX,
MAP_COPY|MAP_FILE, fd, c->mapoff);
/* If the segment alignment > the page size, allocate enough space to
@@ -38,7 +46,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
? (maplength + c->mapalign)
: (2 * c->mapalign));
elfptr_t map_start = (elfptr_t) __mmap ((void *) mappref, maplen,
- PROT_NONE,
+ PROT_NONE|PROT_MAX_RWX,
MAP_ANONYMOUS|MAP_PRIVATE,
-1, 0);
if (__glibc_unlikely ((void *) map_start == MAP_FAILED))
@@ -46,7 +54,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
elfptr_t map_start_aligned = ALIGN_UP (map_start, c->mapalign);
map_start_aligned = (elfptr_t) __mmap ((void *) map_start_aligned,
- maplength, c->prot,
+ maplength, c->prot|PROT_MAX_RWX,
MAP_COPY|MAP_FILE|MAP_FIXED,
fd, c->mapoff);
if (__glibc_unlikely ((void *) map_start_aligned == MAP_FAILED))
@@ -137,7 +145,8 @@ _dl_map_segments (struct link_map *l, int fd,
else
{
/* Need a single capability to cover all load segments. */
- void *p = __mmap ((void *) c->mapstart, maplength, c->prot,
+ void *p = __mmap ((void *) c->mapstart, maplength,
+ c->prot|PROT_MAX_RWX,
MAP_FIXED|MAP_COPY|MAP_FILE,
fd, c->mapoff);
if (p == MAP_FAILED)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/arm/morello/main] cheri: elf: Fix segment mapping permissions
@ 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=40b60cc1dbed3ab3f742177374300f3ba87eb550
commit 40b60cc1dbed3ab3f742177374300f3ba87eb550
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Fri Oct 21 12:38:26 2022 +0100
cheri: elf: Fix segment mapping permissions
Ensure mmap returns pointers with RWX permission covering all segments.
These pointers later get restricted to RX and RW permission.
Diff:
---
elf/dl-map-segments.h | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h
index ce51585ce4..e25fb579df 100644
--- a/elf/dl-map-segments.h
+++ b/elf/dl-map-segments.h
@@ -22,6 +22,13 @@
# include <cheri_perms.h>
#endif
+/* Allow RWX mprotect later, on CHERI this means RWX capability permission. */
+#ifdef PROT_MAX
+# define PROT_MAX_RWX PROT_MAX (PROT_READ | PROT_WRITE | PROT_EXEC)
+#else
+# define PROT_MAX_RWX 0
+#endif
+
/* Map a segment and align it properly. */
static __always_inline elfptr_t
@@ -29,7 +36,8 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
const size_t maplength, int fd)
{
if (__glibc_likely (c->mapalign <= GLRO(dl_pagesize)))
- return (elfptr_t) __mmap ((void *) mappref, maplength, c->prot,
+ return (elfptr_t) __mmap ((void *) mappref, maplength,
+ c->prot|PROT_MAX_RWX,
MAP_COPY|MAP_FILE, fd, c->mapoff);
/* If the segment alignment > the page size, allocate enough space to
@@ -38,7 +46,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
? (maplength + c->mapalign)
: (2 * c->mapalign));
elfptr_t map_start = (elfptr_t) __mmap ((void *) mappref, maplen,
- PROT_NONE,
+ PROT_NONE|PROT_MAX_RWX,
MAP_ANONYMOUS|MAP_PRIVATE,
-1, 0);
if (__glibc_unlikely ((void *) map_start == MAP_FAILED))
@@ -46,7 +54,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
elfptr_t map_start_aligned = ALIGN_UP (map_start, c->mapalign);
map_start_aligned = (elfptr_t) __mmap ((void *) map_start_aligned,
- maplength, c->prot,
+ maplength, c->prot|PROT_MAX_RWX,
MAP_COPY|MAP_FILE|MAP_FIXED,
fd, c->mapoff);
if (__glibc_unlikely ((void *) map_start_aligned == MAP_FAILED))
@@ -137,7 +145,8 @@ _dl_map_segments (struct link_map *l, int fd,
else
{
/* Need a single capability to cover all load segments. */
- void *p = __mmap ((void *) c->mapstart, maplength, c->prot,
+ void *p = __mmap ((void *) c->mapstart, maplength,
+ c->prot|PROT_MAX_RWX,
MAP_FIXED|MAP_COPY|MAP_FILE,
fd, c->mapoff);
if (p == MAP_FAILED)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-23 14:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23 14:47 [glibc/arm/morello/main] cheri: elf: Fix segment mapping permissions Szabolcs Nagy
-- strict thread matches above, loose matches on Subject: below --
2022-10-27 13:57 Szabolcs Nagy
2022-10-26 15:19 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).