Skip to content

wdc, sandisk: read ext SMART cloud log counters unaligned - #4482

Merged
igaw merged 3 commits into
linux-nvme:masterfrom
sagaragas:fix/wdc-ext-smart-unaligned
Dec 2, 2026
Merged

igaw merged 3 commits into
linux-nvme:masterfrom
sagaragas:fix/wdc-ext-smart-unaligned

Conversation

@sagaragas

@sagaragas sagaragas commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Under UBSan, wdc vs-nand-stats, wdc vs-cloud-log, and sndk vs-smart-add-log abort on misaligned uint64_t loads in the extended SMART cloud log printers. Both plugins/wdc/wdc-nvme.c and its copy in plugins/sandisk/sandisk-utils.c hit this in normal and JSON output. Three of the four 8-byte counters (ext_smart_pfc, ext_smart_efc, ext_smart_bsnbc) sit at offsets 132, 140, and 218 in the packed struct.

This switches all four counters in both plugins to shr_get_unaligned_le16() and shr_get_unaligned_le64(), keeping the existing 0xFFFFFFFFFFFF0000 mask on the decoded value. I also added a sndk vs-smart-add-log mock test in tests/cli/sandisk/sandisk_mock_test.py so the mock suite covers both plugins.

I tested plain and -Db_sanitize=undefined builds on Linux x86_64. Under UBSan, master fails 4 wdc - commands subtests and both sandisk - commands tests, and this branch passes both. Normal and JSON output matches master byte-for-byte on zeroed and non-zero logs.

The extended SMART cloud log printers in plugins/wdc/wdc-nvme.c and
their copies in plugins/sandisk/sandisk-utils.c read four 8-byte
counters (ext_smart_bunbc, ext_smart_pfc, ext_smart_efc, and
ext_smart_bsnbc) by casting the byte arrays to uint16_t * and
uint64_t *. Three of those fields sit at offsets 132, 140, and 218 in
the packed log struct, which are not 8-byte aligned and trigger UBSan
misaligned-load aborts in wdc vs-nand-stats, wdc vs-cloud-log, and
sndk vs-smart-add-log:

  wdc-nvme.c:7107:16: runtime error: load of misaligned address
  0x60d2eca62dd4 for type 'uint64_t', which requires 8 byte alignment

Read all four counters with shr_get_unaligned_le16() and
shr_get_unaligned_le64() before applying the 0xFFFFFFFFFFFF0000 mask,
and add sndk vs-smart-add-log to SN820CLTest so both plugins are
covered by the mock suite.

Fixes: d2350f3 ("wdc: Updated field descriptions in vs-cloud-log command")
Fixes: 01eb367 ("plugins/sandisk: port vs-smart-add-log from wdc")
Signed-off-by: Sagar Narayan <113566055+sagaragas@users.noreply.github.com>
@jeff-lien-sndk

Copy link
Copy Markdown
Contributor

@sagaragas Your changes look fine to me. Could you also update the SANDISK_PLUGIN_VERSION in sandisk-nvme.c? The current value is 3.1.7 and I'd recommend updating it to 3.3.0 to match the current main version.

Bump SANDISK_PLUGIN_VERSION from 3.1.7 to 3.3.0 to match the current
nvme-cli 3.3 version.

Signed-off-by: Sagar Narayan <113566055+sagaragas@users.noreply.github.com>

@brandon-paupore-sndk brandon-paupore-sndk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had one additional comment beyond Jeff's, otherwise the fixes for LE ordering seem good to me!

Comment thread tests/cli/wdc/wdc_mock_test.py Outdated
'wdc vs-cloud-log',
'wdc vs-hw-rev-log',
'wdc vs-device-waf',
'sndk vs-smart-add-log',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably go under a separate (new) test file for the sndk plugin, rather than being tucked away in this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to its own sndk test file in tests/cli/sandisk/sandisk_mock_test.py.

Move the SN820CL sndk vs-smart-add-log test out of
tests/cli/wdc/wdc_mock_test.py into a dedicated sandisk plugin mock
test under tests/cli/sandisk/, guarded by 'sandisk' in selected_plugins.

Signed-off-by: Sagar Narayan <113566055+sagaragas@users.noreply.github.com>
@sagaragas

Copy link
Copy Markdown
Contributor Author

Updated SANDISK_PLUGIN_VERSION to 3.3.0.

@igaw
igaw merged commit 07e09e8 into linux-nvme:master Dec 2, 2026
39 checks passed
@igaw

igaw commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks everyone!

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.

4 participants