Skip to content

libnvme: reject oversized discovery log record counts - #3911

Merged
igaw merged 1 commit into
linux-nvme:masterfrom
prabhakarpujeri:fix-numrec-disc-log
Aug 26, 2026
Merged

libnvme: reject oversized discovery log record counts#3911
igaw merged 1 commit into
linux-nvme:masterfrom
prabhakarpujeri:fix-numrec-disc-log

Conversation

@prabhakarpujeri

Copy link
Copy Markdown

Problem

libnvme3 keeps the local libnvme 1.x issue (fixed upstream in linux-nvme/libnvme#1121): nvme_discovery_log() trusts the device-supplied numrec:

entries_size = sizeof(*log->entries) * numrec;
log = libnvme_alloc(sizeof(*log) + entries_size);

A controller returning large numrec makes entries_size (or the sizeof(*log) + addition) wrap, producing a small allocation while log->entries gets filled with attacker-controlled length — heap overflow.

Fix

Reject numrec values that can't fit in size_t before allocating (same shape as the 1.x fix).

Testing

  • Full meson suite green (the one crypto-util skip is env-related: OpenSSL absent on this host, also on pristine master).
  • Arithmetic verified against the 1.x regression test (fabrics: reject oversized discovery log record counts libnvme#1121 includes a unit test on the shared logic semantics; the 3.x structure differs in that there is no standalone mock-IOCTL harness wired for fabrics, so the check here is review-verified against the same boundary condition).

discovery log fetch trusts the device-supplied numrec field and
computes the buffer size as

    entries_size = sizeof(*log->entries) * numrec;
    log = libnvme_alloc(sizeof(*log) + entries_size);

A malicious or malfunctioning discovery controller can answer with
a numrec large enough to wrap entries_size (or the subsequent
addition), yielding a tiny allocation while the copy into
log->entries proceeds with attacker-controlled length - heap
overflow.

Guard the multiply by rejecting numrec values that cannot fit in
size_t, before allocating.

Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
@igaw
igaw force-pushed the fix-numrec-disc-log branch from eb46329 to 13f8933 Compare August 26, 2026 13:05
@igaw

igaw commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

removed libnvme reference in commit message

@igaw
igaw merged commit 51bb432 into linux-nvme:master Aug 26, 2026
29 of 30 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