From 976726e727ea54777a2af26e6e0276db1370d10f Mon Sep 17 00:00:00 2001 From: Aditya K Kamath Date: Sun, 31 Mar 2024 17:52:37 +0000 Subject: [PATCH] Fix missing UFFDIO_WRITEPROTECT ioctl for write protecting --- src/copy_interpose.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/copy_interpose.c b/src/copy_interpose.c index c397e7a..417c71b 100644 --- a/src/copy_interpose.c +++ b/src/copy_interpose.c @@ -353,6 +353,18 @@ void *memcpy(void *dest, const void *src, size_t n) { perror("register with WP"); abort(); } + struct uffdio_writeprotect wp; + wp.range.start = (uint64_t)(src_entry->addr + src_entry->offset); + wp.range.len = (uint64_t)src_entry->len; + wp.mode = UFFDIO_WRITEPROTECT_MODE_WP; + if (ioctl(uffd, UFFDIO_WRITEPROTECT, &wp) == -1) { + if (errno == EINVAL) { + LOG("[%s] write-protection fault by userfaultfd may not be" + "supported by the current kernel\n"); + } + perror("Writeprotect pages"); + abort(); + } } size_t left_fringe_len = LEFT_FRINGE_LEN(dest);