From faf4ff43ae5ab9c2e0f6f3b8a31b1d6bb142572e Mon Sep 17 00:00:00 2001 From: Shi Jin Date: Tue, 14 Nov 2023 01:38:14 +0000 Subject: [PATCH] util/memhooks: Fix a bug when calculating mprotect region In ofi_write_patch, the bound should be the page end for the end of the address + data_size. And since it's the end of the page, when calculating the length, it needs to add 1 to make the length a multiple of page size. Signed-off-by: Shi Jin --- prov/util/src/util_mem_hooks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prov/util/src/util_mem_hooks.c b/prov/util/src/util_mem_hooks.c index ce69e64fc27..f8a151ebecd 100644 --- a/prov/util/src/util_mem_hooks.c +++ b/prov/util/src/util_mem_hooks.c @@ -220,8 +220,8 @@ static inline int ofi_write_patch(unsigned char *patch_data, void *address, } base = ofi_get_page_start(address, page_size); - bound = ofi_get_page_end(address, page_size); - length = (uintptr_t) bound - (uintptr_t) base; + bound = ofi_get_page_end( (void *) ((uintptr_t) address + data_size - 1), page_size); + length = (uintptr_t) bound - (uintptr_t) base + 1; if (mprotect(base, length, PROT_EXEC|PROT_READ|PROT_WRITE)) { FI_WARN(&core_prov, FI_LOG_MR,