aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/mremap.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2022-08-05 11:44:57 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2022-10-27 14:46:51 +0100
commit1635be334baa886f7576b078c05e529742828ca8 (patch)
tree439a4370ed93935a412ab016135413629c6eac0f /sysdeps/unix/sysv/linux/mremap.c
parentab15a586a0d679878bc3034bc1db5540cda63911 (diff)
downloadglibc-1635be334baa886f7576b078c05e529742828ca8.tar
glibc-1635be334baa886f7576b078c05e529742828ca8.tar.gz
glibc-1635be334baa886f7576b078c05e529742828ca8.tar.bz2
glibc-1635be334baa886f7576b078c05e529742828ca8.zip
TODO(uapi): narrow capability in mmap and mremap
This is a temporary workaround. length is rounded up to pagesize and don't use exact bound (bounds will be larger if exact value is not representable). capability permissions are roughly emulated too. TODO: kernel should do this
Diffstat (limited to 'sysdeps/unix/sysv/linux/mremap.c')
-rw-r--r--sysdeps/unix/sysv/linux/mremap.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/sysdeps/unix/sysv/linux/mremap.c b/sysdeps/unix/sysv/linux/mremap.c
index e829a29dbd..2e89f43faa 100644
--- a/sysdeps/unix/sysv/linux/mremap.c
+++ b/sysdeps/unix/sysv/linux/mremap.c
@@ -20,6 +20,7 @@
#include <sysdep.h>
#include <stdarg.h>
#include <stddef.h>
+#include <ldsodefs.h>
void *
__mremap (void *addr, size_t old_len, size_t new_len, int flags, ...)
@@ -34,8 +35,17 @@ __mremap (void *addr, size_t old_len, size_t new_len, int flags, ...)
va_end (va);
}
- return (void *) INLINE_SYSCALL_CALL (mremap, addr, old_len, new_len, flags,
+ void *ret;
+ ret = (void *) INLINE_SYSCALL_CALL (mremap, addr, old_len, new_len, flags,
new_addr);
+#ifdef __CHERI_PURE_CAPABILITY__
+ if (ret != MAP_FAILED)
+ {
+ size_t ps = GLRO(dl_pagesize);
+ ret = __builtin_cheri_bounds_set (ret, (new_len + ps - 1) & -ps);
+ }
+#endif
+ return ret;
}
libc_hidden_def (__mremap)
weak_alias (__mremap, mremap)