Manual Page Search Parameters

MRS(3) Library Functions Manual MRS(3)

MRSMalloc Revocation Shim

Standard C Library (libc, -lc)

#include <stdlib.h>

void *
malloc(size_t size);

void *
calloc(size_t number, size_t size);

int
posix_memalign(void **ptr, size_t alignment, size_t size);

void *
aligned_alloc(size_t alignment, size_t size);

void *
realloc(void *ptr, size_t size);

void
free(void *ptr);

The Malloc Revocation Shim (MRS) extends a CHERI-aware malloc implemention with revocation support, providing heap temporal safety. MRS wraps the underlying allocator and manages quarantine queues which are revoked by cheri_revoke(2).

MRS implements all standard malloc interfaces. For detailed documentation of those interfaces see jemalloc(3). It also provides partial implementations of the non-standard jemalloc(3) interfaces (), (), (), and (). These differ from the underlying implementations in that the MALLOCX_TCACHE and MALLOCX_ARENA flags are ignored if revocation is enabled. The undocumented jemalloc(3) 3.0 interfaces are not implemented by MRS because no CheriABI program should have ever used them.

Because heap temporal safety is an experimental feature with performance impacts that are not fully characterized, MRS provides a number of policy mechanisms to control MRS revocation. When a program using MRS starts up, an array of parameters are evaluated to determine if free'd objects should be quarantined and revoked or if the underlying implementations should be exposed directly. If the ELF_BSDF_CHERI_REVOKE flag of the AT_BSDFLAGS ELF auxiliary argument variable is set then the program will revoke.

The kernel considers the following factors in order of decreasing precedence when setting AT_BSDFLAGS flags:

A program can determine at runtime if MRS or similar revocation is enabled by checking the return value of ().

MRS supports utrace(2) event logging which can be enabled by setting the _MRS_UTRACE environmental variable, collected by ktrace(1) and viewed by kdump(1). This produces output like:

$ kdump -H -t u
21593 101243 git USER 0x45e00000 = malloc(50708)
21593 101243 git USER 0x45e00000 = mrs_malloc(50708)
21593 101243 git USER mrs_free(0x45e00000)
21593 101243 git USER quarantine_insert(0x45e00000, 57344)
21593 101242 git USER quarantine_flush()

MRS requires that allocators be extended to provide a void * malloc_underlying_allocation(void *) interface which takes a capability passed to free() or realloc() and returns a capability to the underlying allocator bearing the permission. This capability will not be revoked and thus can be stored in the quarantine structure. This interface must not be exported outside the implementation.

To alter a binary to disable use of revocation, use:

elfctl -e +nocherirevoke <program>

To override the system default and binary settings run the program as follows:

proccontrol -m cherirevoke -s enable <program>

elfctl(1), kdump(1), ktrace(1), proccontrol(1), jemalloc(3), malloc_revoke_enabled(3), malloc_revoke_quarantine_force_flush(3), sysctl(8)

MRS currently has a single quarantine queue protected by a mutex. For multi-threaded applications where concurent malloc(3) performance is important, this will be a significant bottleneck.

This software and this manual page were developed by SRI International, the University of Cambridge Computer Laboratory (Department of Computer Science and Technology), and Capabilities Limited under contract (HR001123C0031) (“MTSS”).

December 12, 2023 dev