Skip to content

lib: improve string overflow safety

Stephen Hemminger dpdk-dev 14 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v14 Latest17 patches 2 repliesIn review
  2. v1317 patches 0 repliesSuperseded
  3. v1217 patches 2 repliesSuperseded
Earlier versions · 11
VersionPostedPatchesRepliesStatus
v1118 patches0 repliesSuperseded
v1018 patches0 repliesSuperseded
v918 patches1 replySuperseded
v818 patches0 repliesSuperseded
v718 patches0 repliesSuperseded
v618 patches0 repliesSuperseded
v517 patches2 repliesSuperseded
v416 patches0 repliesSuperseded
v316 patches3 repliesSuperseded
v2 RFC14 patches7 repliesSuperseded
v1 RFC8 patches0 repliesSuperseded

Patches in v14 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/17lpm: reject names that exceed maximum lengthdoc/guides/rel_notes/release_26_03.rst lib/lpm/rte_lpm.c lib/lpm/rte_lpm.h+21 -40 replies
2/17hash: reject names that exceed maximum lengthapp/test/test_hash.c doc/guides/rel_notes/release_26_03.rst lib/hash/rte_cuckoo_hash.c +2 more+63 -150 replies
3/17graph: avoid overflowing comment bufferlib/graph/graph_pcap.c+6 -31 reply
4/17latencystats: add check for string overflowlib/latencystats/rte_latencystats.c+6 -30 replies
5/17telemetry: check for path overflowlib/telemetry/telemetry_legacy.c+5 -20 replies
6/17efd: handle possible name truncationdoc/guides/rel_notes/release_26_03.rst lib/efd/rte_efd.c+15 -50 replies
7/17eal: use C library to parse filesystem tablelib/eal/linux/eal_hugepage_info.c+29 -750 replies
8/17eal: warn if thread name is truncatedlib/eal/freebsd/eal.c lib/eal/linux/eal.c lib/eal/windows/eal.c+12 -60 replies
9/17eal: avoid format overflow when handling addresseslib/eal/common/eal_common_memory.c+2 -10 replies
10/17eal: limit maximum runtime directory and socket pathslib/eal/common/eal_common_config.c lib/eal/common/eal_common_proc.c lib/eal/common/eal_filesystem.h+74 -340 replies
11/17eal: check for hugefile path overflowlib/eal/common/eal_filesystem.h lib/eal/linux/eal_hugepage_info.c lib/eal/linux/eal_memalloc.c +1 more+45 -190 replies
12/17eal: check tailq lengthdoc/guides/rel_notes/release_26_03.rst lib/eal/common/eal_common_tailqs.c+13 -10 replies
13/17eal: handle long shared library pathlib/eal/common/eal_common_options.c+13 -40 replies
14/17ethdev: avoid possible overflow in xstat nameslib/ethdev/rte_ethdev.c+24 -110 replies
15/17vhost: check for overflow in xstat namelib/vhost/vhost.c+10 -40 replies
16/17cfgfile: add length checks and increase line bufferdoc/guides/rel_notes/release_26_03.rst lib/cfgfile/rte_cfgfile.c lib/cfgfile/rte_cfgfile.h+40 -100 replies
17/17lib: enable format overflow warningslib/meson.build+0 -40 replies

Reviews trailers per patch

7 of 17 patches have a Reviewed-by or Acked-by.

PatchBruce RichardsonKonstantin Ananyev
1/17
2/17
3/17
4/17A-b
5/17A-b
6/17
7/17A-b A-b
8/17A-b
9/17
10/17A-b
11/17
12/17A-b
13/17
14/17A-b
15/17
16/17
17/17

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v14 thread

Cover letter [PATCH v14 00/17] lib: improve string overflow safety

This series improves defensive programming by adding proper string length validation and overflow checking throughout DPDK libraries. The goal is to eliminate silent truncation of names and paths, provide meaningful error feedback, and enable compiler format overflow warnings.

Motivation
----------
Many DPDK APIs accept name parameters with defined maximum lengths (e.g., RTE_LPM_NAMESIZE, RTE_HASH_NAMESIZE). Previously, names exceeding these limits were silently truncated via snprintf/strlcpy, potentially causing subtle bugs like duplicate names or unexpected behavior. This series addresses these issues systematically.

Changes Overview
----------------
The patches fall into several categories:

1. API input validation (patches 1-2, 6, 12, 16):
- Add explicit length checks for name parameters in lpm, hash, efd, tailq, and cfgfile APIs
- Return ENAMETOOLONG when names exceed limits
- Document new error conditions in API headers
- Add corresponding unit tests

2. Internal buffer overflow detection (patches 3-5, 8-9, 14-15):
- Check snprintf/strlcpy return values for truncation
- Log warnings when internal string operations truncate
- Increase buffer sizes where they were too small
- Use dynamic allocation (asprintf) where appropriate

3. Path handling improvements (patches 7, 10-11, 13):
- Use standard C library routines (getmntent) for parsing /proc/mounts
- Enforce UNIX_PATH_MAX for socket paths to fail early
- Handle arbitrarily long shared library paths

4. Error message improvements (patches 1-2, 6):
- Include rte_strerror() in failure messages
- Provide more context when operations fail

5. Enable compiler warnings (patch 17):
- Remove -Wno-format-truncation flag
- All preceding patches fix the warnings this would trigger

API Changes
-----------
The following APIs now return ENAMETOOLONG for oversized names:
- rte_lpm_create()
- rte_hash_create()
- rte_fbk_hash_create()
- rte_efd_create()
- rte_eal_tailq_create()
- rte_cfgfile_add_section()
- rte_cfgfile_add_entry()

These are documented in the release notes and header files.

Testing
-------
- Existing unit tests pass
- New test cases added for hash name length validation
- Build tested with format overflow warnings enabled

v14 - fix build on 32 bit Ubuntu
- reword commit messages for clarity

v13 - fix and cleanup get_hugefile code
optimize using statfs() and no string handling needed. reword commit messages

Stephen Hemminger (17):
lpm: reject names that exceed maximum length
hash: reject names that exceed maximum length
graph: avoid overflowing comment buffer
latencystats: add check for string overflow
telemetry: check for path overflow
efd: handle possible name truncation
eal: use C library to parse filesystem table
eal: warn if thread name is truncated
eal: avoid format overflow when handling addresses
eal: limit maximum runtime directory and socket paths
eal: check for hugefile path overflow
eal: check tailq length
eal: handle long shared library path
ethdev: avoid possible overflow in xstat names
vhost: check for overflow in xstat name
cfgfile: add length checks and increase line buffer
lib: enable format overflow warnings

 app/test/test_hash.c                   |  21 ++++
 doc/guides/rel_notes/release_26_03.rst |  13 +++
 lib/cfgfile/rte_cfgfile.c              |  42 ++++++--
 lib/cfgfile/rte_cfgfile.h              |   6 +-
 lib/eal/common/eal_common_config.c     |   6 +-
 lib/eal/common/eal_common_memory.c     |   3 +-
 lib/eal/common/eal_common_options.c    |  17 ++-
 lib/eal/common/eal_common_proc.c       |  85 +++++++++------
 lib/eal/common/eal_common_tailqs.c     |  13 ++-
 lib/eal/common/eal_filesystem.h        |  27 ++++-
 lib/eal/freebsd/eal.c                  |   6 +-
 lib/eal/linux/eal.c                    |   6 +-
 lib/eal/linux/eal_hugepage_info.c      | 138 ++++++++++---------------
 lib/eal/linux/eal_memalloc.c           |  11 +-
 lib/eal/linux/eal_memory.c             |   9 +-
 lib/eal/windows/eal.c                  |   6 +-
 lib/efd/rte_efd.c                      |  18 +++-
 lib/ethdev/rte_ethdev.c                |  35 +++++--
 lib/graph/graph_pcap.c                 |   9 +-
 lib/hash/rte_cuckoo_hash.c             |  41 +++++---
 lib/hash/rte_fbk_hash.c                |  12 ++-
 lib/hash/rte_fbk_hash.h                |   1 +
 lib/latencystats/rte_latencystats.c    |   9 +-
 lib/lpm/rte_lpm.c                      |  17 ++-
 lib/lpm/rte_lpm.h                      |   1 +
 lib/meson.build                        |   4 -
 lib/telemetry/telemetry_legacy.c       |   7 +-
 lib/vhost/vhost.c                      |  14 ++-
 28 files changed, 377 insertions(+), 200 deletions(-)
Signature · 1 line
2.51.0