public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Szabolcs Nagy <nsz@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] TODO(l_addr): cheri: rtld: elfptr_t fixes in dl-map-segments.h Date: Fri, 5 Aug 2022 19:36:46 +0000 (GMT) [thread overview] Message-ID: <20220805193646.4C7933856969@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d15c9f859ffdd3fbcfdeae01be72e4f59be70b4b commit d15c9f859ffdd3fbcfdeae01be72e4f59be70b4b Author: Szabolcs Nagy <szabolcs.nagy@arm.com> Date: Thu Apr 7 08:43:00 2022 +0100 TODO(l_addr): cheri: rtld: elfptr_t fixes in dl-map-segments.h Ensure map_end is derived from map_start. Use stricter mmap bounds when using MAP_FIXED: c->mapend is aligned up to pagesize, but the capability representing the mapping has bounds that are not page aligned, so use c->dataend that is the actual end bound of the loaded segment. TODO: l_addr of a pde is 0 but it should cover the exe. this will have to be fixed. (and must not use morello asm) Diff: --- elf/dl-map-segments.h | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h index 024175b2d5..5439c20233 100644 --- a/elf/dl-map-segments.h +++ b/elf/dl-map-segments.h @@ -21,12 +21,12 @@ /* Map a segment and align it properly. */ -static __always_inline ElfW(Addr) +static __always_inline elfptr_t _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 (ElfW(Addr)) __mmap ((void *) mappref, maplength, c->prot, + return (elfptr_t) __mmap ((void *) mappref, maplength, c->prot, MAP_COPY|MAP_FILE, fd, c->mapoff); /* If the segment alignment > the page size, allocate enough space to @@ -34,15 +34,15 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref, ElfW(Addr) maplen = (maplength >= c->mapalign ? (maplength + c->mapalign) : (2 * c->mapalign)); - ElfW(Addr) map_start = (ElfW(Addr)) __mmap ((void *) mappref, maplen, + elfptr_t map_start = (elfptr_t) __mmap ((void *) mappref, maplen, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if (__glibc_unlikely ((void *) map_start == MAP_FAILED)) return map_start; - ElfW(Addr) map_start_aligned = ALIGN_UP (map_start, c->mapalign); - map_start_aligned = (ElfW(Addr)) __mmap ((void *) map_start_aligned, + elfptr_t map_start_aligned = ALIGN_UP (map_start, c->mapalign); + map_start_aligned = (elfptr_t) __mmap ((void *) map_start_aligned, maplength, c->prot, MAP_COPY|MAP_FILE|MAP_FIXED, fd, c->mapoff); @@ -54,7 +54,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref, ElfW(Addr) delta = map_start_aligned - map_start; if (delta) __munmap ((void *) map_start, delta); - ElfW(Addr) map_end = map_start_aligned + maplength; + elfptr_t map_end = map_start + (map_start_aligned - map_start) + maplength; map_end = ALIGN_UP (map_end, GLRO(dl_pagesize)); delta = map_start + maplen - map_end; if (delta) @@ -126,6 +126,18 @@ _dl_map_segments (struct link_map *l, int fd, goto postmap; } +#ifdef __CHERI_PURE_CAPABILITY__ + else + { + /* TODO: l_addr is 0 in an exe, but it should cover the load segments. */ + uintptr_t l_addr = 0; + unsigned long allocend = ALIGN_UP (loadcmds[nloadcmds - 1].allocend, + GLRO(dl_pagesize)); + asm volatile ("cvtd %0, %x0" : "+r"(l_addr)); + asm volatile ("scbnds %0, %0, %x1" : "+r"(l_addr) : "r"(allocend)); + l->l_addr = l_addr; + } +#endif /* Remember which part of the address space this object uses. */ l->l_map_start = c->mapstart + l->l_addr; @@ -134,10 +146,10 @@ _dl_map_segments (struct link_map *l, int fd, while (c < &loadcmds[nloadcmds]) { - if (c->mapend > c->mapstart + if (c->dataend > c->mapstart /* Map the segment contents from the file. */ && (__mmap ((void *) (l->l_addr + c->mapstart), - c->mapend - c->mapstart, c->prot, + c->dataend - c->mapstart, c->prot, MAP_FIXED|MAP_COPY|MAP_FILE, fd, c->mapoff) == MAP_FAILED)) @@ -150,7 +162,7 @@ _dl_map_segments (struct link_map *l, int fd, { /* Extra zero pages should appear at the end of this segment, after the data mapped from the file. */ - ElfW(Addr) zero, zeroend, zeropage; + elfptr_t zero, zeroend, zeropage; zero = l->l_addr + c->dataend; zeroend = l->l_addr + c->allocend;
reply other threads:[~2022-08-05 19:36 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220805193646.4C7933856969@sourceware.org \ --to=nsz@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).