Skip to content

plugins/wdc: clamp unsupported-count in OCP C5 log and bound printed/JSON strings - #4024

Open
prabhakarpujeri wants to merge 1 commit into
linux-nvme:masterfrom
prabhakarpujeri:wdc-c5-count-clamp
Open

prabhakarpujeri wants to merge 1 commit into
linux-nvme:masterfrom
prabhakarpujeri:wdc-c5-count-clamp

Conversation

@prabhakarpujeri

Copy link
Copy Markdown

Summary

The OCP C5 unsupported-requirements log page is device-supplied. Both
printers used the device-reported unsupported_count (__le16) as the loop bound
against the fixed WDC_NUM_UNSUPPORTED_REQ_ENTRIES (253)-entry
unsupported_req_list table, which lives inside the 4096-byte log page:

for (j = 0; j < le16_to_cpu(log_data->unsupported_count); j++)
    printf("  Unsupported Requirement List %d	: %s
", j,
           log_data->unsupported_req_list[j]);

A device reporting a count above 253 (up to 0xFFFF) walks the
16-byte list entries past the buffer — leaking heap content into
stdout in the plain view and into json_object_add_value_string()
in the JSON view.

This is the same "device-supplied count vs fixed-size on-disk table"
pattern as #3993 (seagate fw-activate-history).

Fix

  • Clamp log_data->unsupported_count to
    WDC_NUM_UNSUPPORTED_REQ_ENTRIES in wdc_print_unsupported_reqs_log(),
    right when the log page is dispatched — both views see the bounded value.
  • Bound the embedded 16-byte ID string so unterminated device data cannot run
    past a list entry: plain view uses %.16s precision; JSON view now uses
    json_object_new_string_len() (matches ocp/solidigm style in-tree).

Testing

  • meson setup build-main && ninja -C build-main: clean.
  • Hostile-input harness (ASan+UBSan) driving the walk loop with
    unsupported_count = 0xFFFF:
    • pre-fix: heap-buffer-overflow — read of size 1 at 0 bytes past a
      4096-byte region;
    • post-fix: loop walks exactly 253 entries, exit 0.

The C5 unsupported-requirements log page is device-supplied.  Both
printers used the device-reported unsupported_count (__le16) as the
loop bound against the fixed 253-entry unsupported_req_list table in
the 4096-byte page: a device reporting a count above 253 walks past
the buffer and leaks heap content into stdout or the JSON envelope.

Clamp the count to WDC_NUM_UNSUPPORTED_REQ_ENTRIES when the page is
dispatched so both views see the bounded value, and limit the
embedded 16-byte ID strings (printf precision in the plain view,
json_object_new_string_len in the JSON view) so unterminated device
data cannot run past a list entry.

Hostile-input ASan/UBSan harness: heap-buffer-overflow on the pre-fix
walk, clean exit with the clamp in place.

Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
@igaw

igaw commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

looks like when json-c is disabled there is a problem:

FAILED: nvme.p/plugins_wdc_wdc-nvme.c.o 
gcc -Invme.p -I. -I.. -Isrc -I../src -Iccan -I../ccan -Ilibnvme/src -I../libnvme/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=gnu11 -O3 -fomit-frame-pointer -D_GNU_SOURCE -include /__w/nvme-cli/nvme-cli/.build-ci/nvme-config.h -MD -MQ nvme.p/plugins_wdc_wdc-nvme.c.o -MF nvme.p/plugins_wdc_wdc-nvme.c.o.d -o nvme.p/plugins_wdc_wdc-nvme.c.o -c ../plugins/wdc/wdc-nvme.c
In file included from ../src/nvme-print.h:10,
                 from ../plugins/wdc/wdc-nvme.c:48:
../plugins/wdc/wdc-nvme.c: In function ‘wdc_print_unsupported_reqs_log_json’:
../plugins/wdc/wdc-nvme.c:5422:25: error: implicit declaration of function ‘json_object_new_string_len’; did you mean ‘json_object_add_string’? [-Wimplicit-function-declaration]
 5422 |                         json_object_new_string_len(
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~
../src/nvme-json.h:68:49: note: in definition of macro ‘json_object_object_add’
   68 | #define json_object_object_add(o, k, v) ((void)(v))
      |                                                 ^

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