Skip to content

libnvme: nbft: reject heap objects too small for the structures they decode - #3913

Merged
igaw merged 1 commit into
linux-nvme:masterfrom
prabhakarpujeri:fix-nbft-heap-obj-length
Aug 26, 2026
Merged

libnvme: nbft: reject heap objects too small for the structures they decode#3913
igaw merged 1 commit into
linux-nvme:masterfrom
prabhakarpujeri:fix-nbft-heap-obj-length

Conversation

@prabhakarpujeri

Copy link
Copy Markdown

Problem

Port of linux-nvme/libnvme#1125 to libnvme3.

The SSNS extended-info descriptor now validates its disclosed length (good), but three heap-object reads can still overrun:

  1. read_hfi_info_tcp() dereferences the trinfo heap object as a full struct nbft_hfi_info_tcp (flags, mac, addresses, …) without verifying the object's declared length covers even the fields read unconditionally.
  2. the SSNS subsys_traddr_obj is handed to format_ip_addr(), which always memcpy()s a 16-byte struct in6_addr regardless of the declared object length.
  3. the newer HFI trinfo_version >= 2 ext-info object is dereferenced/read via read_hfi_info_dhcp() with the same under-declared trap.

get_heap_obj() validates only heap containment (in_heap) plus string NUL-termination; a file can point a struct-typed heap object at heap_end - 2 and later reads walk past the heap.

Fix

  • __get_heap_obj() gains a min_len parameter rejecting non-string heap objects shorter than the structure the caller dereferences.
  • get_heap_obj() derives the minimum from the output pointer type via _Generic (strings, byte arrays, and the SSNS ext-info reader keep min 0 — the latter does its own spec-length check); call sites lose their (char **) casts.
  • Explicit >= sizeof(struct in6_addr) check for the SSNS transport address before format_ip_addr().

Testing

  • Full meson suite green (99 pass; crypto-util skip is env-related: no OpenSSL on this host, also on pristine master).
  • Checked the NBFT fixture dumps are unchanged by the patch semantics (valid tables remain accepted; only under-sized heap objects — never correctly decodable — are rejected).

@igaw
igaw force-pushed the fix-nbft-heap-obj-length branch 2 times, most recently from 59ba026 to b86f217 Compare August 26, 2026 13:23
…decode

The SSNS extended info descriptor already discloses and validates its
length, but the HFI trinfo object is still decoded into a fixed-size
struct nbft_hfi_info_tcp without any minimum-length check, and the SSNS
transport address heap object is fed unguarded to format_ip_addr(),
which always reads 16 bytes regardless of the declared object length.
The newer HFI ext-info object has the same under-declared length trap.

Give __get_heap_obj() a min_len parameter rejecting non-string objects
shorter than the structure the caller dereferences. The minimum is
derived from the output pointer type via _Generic in the get_heap_obj()
macro (strings and byte arrays keep min 0); call sites drop
their (char **) casts.

_Generic is a C11 feature thus update the project settings. C11 is 15
years old, so should be fair to ask for such a compiler.

Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
[wagi: added C11 dependency]
Signed-off-by: Daniel Wagner <wagi@kernel.org>
@igaw
igaw force-pushed the fix-nbft-heap-obj-length branch from b86f217 to b80d8fa Compare August 26, 2026 13:28
@prabhakarpujeri
prabhakarpujeri force-pushed the fix-nbft-heap-obj-length branch from b80d8fa to b0241af Compare August 26, 2026 13:34
@igaw

igaw commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

droped the reference to libnvme 1.

Didn't know about _Generic, nice C11 feature BUT we only require gnu99 as min version.

@igaw

igaw commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

I am taking care of the patch, please don't update it.

I don't have a problem to update the min requirement for the compiler. As far I can tell all major distro ship compilers which are able to deal with C11. And if not, it's about time to update.

@igaw
igaw force-pushed the fix-nbft-heap-obj-length branch from b0241af to b80d8fa Compare August 26, 2026 13:37
@igaw
igaw merged commit fa3f090 into linux-nvme:master Aug 26, 2026
58 of 60 checks passed
@igaw

igaw commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants