Security Advisory

CVE-2022-0367: libmodbus FC 0x17 Heap Overflow

Last updated:
  • CVE-2022-0367

CVE-2022-0367 is a heap-based buffer overflow in libmodbus, the open-source Modbus library used in embedded gateways: modbus_reply() never checked that the write address of a Write and Read Multiple Registers request was in range, so a crafted request writes outside the register map. NVD scores it 7.8. It is fixed in libmodbus 3.1.7, released 9 January 2022.

Vulnerability summary

CVSS base score

7.8

High severity

EPSS score (FIRST)

0.5%

Probability of exploitation in the wild in the next 30 days

CISA KEV catalog

No

Not listed

Published

Vulnerability ID: CVE-2022-0367 · Source: NVD

Affected components

ComponentCPEVersion range
libmodbus (modbus_reply, Write and Read Multiple Registers, function code 0x17)cpe:2.3:a:libmodbus:libmodbus:*:*:*:*:*:*:*:*before 3.1.7; fixed in 3.1.7 (9 January 2022) (NVD, libmodbus NEWS)
OpenWrt packages feed libmodbus—openwrt-19.07 and openwrt-21.02 branches build 3.1.6; openwrt-22.03 builds 3.1.7 (OpenWrt packages repository)
Buildroot package libmodbus—3.1.6 from August 2019; bumped to 3.1.7 on 10 February 2022 (Buildroot repository)

What does this mean for affected devices?

NVD describes CVE-2022-0367 as "a heap-based buffer overflow flaw" in "libmodbus in function modbus_reply() in src/modbus.c." NVD's Primary score is CVSS v3.1 7.8 (high), vector CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H, with CWE-787 (Red Hat gives CWE-119), for libmodbus before 3.1.7 (NVD). NVD's vector rates the attack as local with user interaction; on a gateway whose libmodbus server listens on the network, the request in the report arrives over TCP.

The report is libmodbus issue #614, opened 22 December 2021. Its proof of concept sends one 19-byte Modbus/TCP request with function code 0x17 (Write and Read Multiple Registers) to the project's unit-test server, which then aborts with heap corruption. The cause, in the words of the fix commit by Michael Heimpold, is "a simple copy and paste error": the bounds check tested mapping_address < 0 twice, so the write address (mapping_address_write) was never checked against the lower bound, and the write loop ran outside the register array. The fix landed on 8 January 2022 and shipped in 3.1.7 the next day (libmodbus NEWS).

No CISA ICS advisory in CISA's CSAF repository names this CVE (searched 2026-11-17), so device exposure comes through firmware that bundles the library. In the OpenWrt packages feed, the openwrt-21.02 branch and openwrt-19.07 still build libmodbus 3.1.6, while openwrt-22.03 builds 3.1.7, checked 2026-11-17. Buildroot carried 3.1.6 from August 2019 until it moved to 3.1.7 on 10 February 2022 (history). The Debian Security Tracker lists fixes of 3.1.4-2+deb10u2 for buster (DLA-3098-1) and 3.1.6-2+deb11u1 for bullseye (DLA-4084-1).

Our Modbus protocol security guide uses this CVE in its worked example: a drive gateway whose firmware SBOM lists libmodbus 3.1.6 is inside the range. The Buildroot and Yocto SBOM guide covers getting that SBOM from the build, and the memory corruption fix guide covers bounds checks as a class. The earlier libmodbus parser bugs in the same function are CVE-2019-14462 and CVE-2019-14463.

To fix it, update libmodbus to 3.1.7 or later, or apply commit b4ef4c1 to an older build. CVE-2022-0367 is not in the CISA KEV catalog as of 2026-11-17 (catalog version 2026.11.13). FIRST EPSS gives it 0.0046, the 40th percentile, in the 2026-11-16 dataset (CISA KEV, FIRST EPSS).

How to fix this class of issueThis advisory's weakness class is Memory corruption. Our practical guide covers how to detect, fix, verify and disclose it: How to fix memory corruption in embedded firmware.

Evidence

  • Heap-based buffer overflow in modbus_reply() in src/modbus.c; NVD Primary CVSS v3.1 7.8, vector AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H; CWE-787 (Red Hat CWE-119); before 3.1.7. — NVD
  • Issue opened 2021-12-22, closed 2022-01-08; PoC sends a function code 0x17 request to unit-test-server, which aborts with heap corruption. — libmodbus issue #614
  • For MODBUS_FC_WRITE_AND_READ_REGISTERS only the read address was checked; mapping_address < 0 duplicated instead of mapping_address_write < 0; dated 2022-01-08. — libmodbus commit b4ef4c1
  • 3.1.7 released 2022-01-09: "modbus_reply: fix copy & paste error in sanity check (fixes #614)". — libmodbus NEWS
  • openwrt-19.07 and openwrt-21.02 Makefiles PKG_VERSION 3.1.6; openwrt-22.03 3.1.7. — OpenWrt packages repository
  • Buildroot libmodbus 3.1.6 from 2019-08-01, bumped to 3.1.7 on 2022-02-10. — Buildroot repository
  • Fixed in buster 3.1.4-2+deb10u2 (DLA-3098-1) and bullseye 3.1.6-2+deb11u1 (DLA-4084-1). — Debian Security Tracker
  • Not in the CISA KEV catalog as of 2026-11-17 (catalog version 2026.11.13). — CISA KEV
  • EPSS 0.0046 (40th percentile), dataset 2026-11-16, read 2026-11-17. — FIRST EPSS

Related advisories

Sources

  1. NVD
  2. libmodbus issue #614: Heap-based Buffer Overflow in modbus_reply
  3. libmodbus fix commit b4ef4c1
  4. libmodbus NEWS
  5. OpenWrt packages openwrt-21.02: libmodbus Makefile
  6. OpenWrt packages openwrt-22.03: libmodbus Makefile
  7. Buildroot: package/libmodbus history
  8. Debian Security Tracker
  9. CISA KEV
  10. FIRST EPSS

Frequently asked questions

Which Modbus function triggers CVE-2022-0367?

Write and Read Multiple Registers, function code 0x17. The server checked the read address twice and never checked the write address against the lower bound (per libmodbus issue #614 and commit b4ef4c1).

Which libmodbus version fixes CVE-2022-0367?

libmodbus 3.1.7, released 9 January 2022. Debian backported the fix as 3.1.4-2+deb10u2 for buster and 3.1.6-2+deb11u1 for bullseye (per the libmodbus NEWS and the Debian Security Tracker).

Do OpenWrt builds carry an affected libmodbus?

The openwrt-19.07 and openwrt-21.02 packages branches build libmodbus 3.1.6, inside the range; openwrt-22.03 builds 3.1.7, checked 2026-11-17 (per the OpenWrt packages repository).

Is CVE-2022-0367 in the CISA KEV catalog?

No, not as of 2026-11-17 (catalog version 2026.11.13). FIRST EPSS gives it 0.0046, the 40th percentile, in the 2026-11-16 dataset (per CISA KEV and FIRST EPSS).