Skip to content

Commit

Permalink
util/memhooks: Fix a bug when calculating mprotect region
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
shijin-aws committed Nov 14, 2023
1 parent 1ba6048 commit faf4ff4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions prov/util/src/util_mem_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit faf4ff4

Please sign in to comment.