Skip to content

Commit

Permalink
jemalloc: Clamp in malloc_usable_size() only if a tag is present
Browse files Browse the repository at this point in the history
This behaviour should be safe and is useful for testing whether the bounds
applied by jemalloc match what malloc_usable_size() reports.  That is, one
can validate bounds with a check like,

    assert(cheri_getlen(p) == malloc_usable_size(cheri_cleartag(p)));

In particular, malloc_usable_size() will look up the usable size using
allocator metadata, so it's handy to be able to compare that size with the
capability bounds.
  • Loading branch information
markjdb committed Jul 10, 2024
1 parent 393d4f3 commit e5ca2eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion contrib/jemalloc/src/jemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3770,7 +3770,7 @@ je_malloc_usable_size(JEMALLOC_USABLE_SIZE_CONST void *ptr) {
ret = isalloc(tsdn, ptr);
}
#ifdef __CHERI_PURE_CAPABILITY__
if (ret != 0) {
if (ret != 0 && cheri_gettag(ptr)) {
ret = MIN(ret, cheri_getlen(ptr));
}
#endif
Expand Down

0 comments on commit e5ca2eb

Please sign in to comment.