1. Losing three CVE patches to a single = in BitBake
Upstream meta-oe on Kirkstone already lists three fixes for CVE-2024-10918 in libmodbus.inc. When we inspected the resolved recipe variables (bitbake -e libmodbus) with every board and distribution layer enabled, all three patch files had vanished from SRC_URI, leaving only a Git repository:
# meta-oe/recipes-extended/libmodbus/libmodbus.inc
SRC_URI = " \
http://libmodbus.org/releases/${BP}.tar.gz \
file://CVE-2024-10918-01.patch \
file://CVE-2024-10918-02.patch \
file://CVE-2024-10918-03.patch \
"
# Downstream libmodbus_3.1.7.bbappend: '=' overwrites the whole list
SRC_URI = "git://...;protocol=https;branch=..."
Pointing a .bbappend at a custom Git tree with SRC_URI = wipes every file:// security patch inherited from the base recipe without raising a BitBake warning. Restoring the three CVE-2024-10918 patches closed that configuration gap, and we wrote a local C regression fixture around modbus_reply() to verify how 3.1.7 handled malformed frames.
2. Returning an exception after mutating 0x5678
Our fixture initialized holding register 0 to 0x5678 and passed a Function Code 22 (Mask Write Register, 0x16) request with an inconsistent length. On the wire, modbus_reply() sent back the expected exception code for an illegal data value. Reading mb_mapping->tab_registers[0] right after the call showed that 0x5678 had already been overwritten:
/* src/modbus.c in 3.1.7: updates the register before validating req_length */
- data = (data & and) | (or & (~and));
- mb_mapping->tab_registers[mapping_address] = data;
-
rsp_length = compute_response_length_from_request(ctx, (uint8_t *) req);
if (rsp_length != req_length) {
/* sends MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE and breaks */
...
}
+ data = mb_mapping->tab_registers[mapping_address];
+ data = (data & and) | (or & (~and));
+ mb_mapping->tab_registers[mapping_address] = data;
In industrial control, an exception reply tells the caller that the requested write did not happen. A controller that caches its last confirmed setpoint keeps operating on 0x5678 while the server holds mutated bits. Because that ordering lived in libmodbus 3.1.7 itself, even a stock Kirkstone build with all three meta-oe patches intact remained exposed.
Upstream maintainer Stéphane Raimbault had already moved the register update past the length check in a newer branch (commit 9b99334df2b7). We backported that change to Kirkstone 3.1.7, verified on ARM64 QEMU that rejected FC22 writes left 0x5678 untouched while valid mask writes updated only the selected bits over both Modbus TCP and Modbus RTU (across paired pseudo-terminals), and submitted the backport in garmin/meta-lts-collab#284, now merged into the Garmin-hosted community layer.