plugins/wdc: clamp unsupported-count in OCP C5 log and bound printed/JSON strings - #4024
Open
prabhakarpujeri wants to merge 1 commit into
Open
prabhakarpujeri wants to merge 1 commit into
prabhakarpujeri wants to merge 1 commit into
Conversation
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>
prabhakarpujeri
force-pushed
the
wdc-c5-count-clamp
branch
from
September 15, 2026 14:55
5cdf224 to
deaca58
Compare
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))
| ^ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The OCP C5 unsupported-requirements log page is device-supplied. Both
printers used the device-reported
unsupported_count(__le16) as the loop boundagainst the fixed
WDC_NUM_UNSUPPORTED_REQ_ENTRIES(253)-entryunsupported_req_listtable, which lives inside the 4096-byte log page: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
log_data->unsupported_counttoWDC_NUM_UNSUPPORTED_REQ_ENTRIESinwdc_print_unsupported_reqs_log(),right when the log page is dispatched — both views see the bounded value.
past a list entry: plain view uses
%.16sprecision; JSON view now usesjson_object_new_string_len()(matches ocp/solidigm style in-tree).Testing
meson setup build-main && ninja -C build-main: clean.unsupported_count = 0xFFFF:heap-buffer-overflow— read of size 1 at 0 bytes past a4096-byte region;