]> www.infradead.org Git - users/sagi/nvme-cli.git/commit
nvme: telemetry: report the correct error if the ioctl() fails.
authorMaurizio Lombardi <mlombard@redhat.com>
Wed, 22 May 2024 13:06:18 +0000 (15:06 +0200)
committerDaniel Wagner <wagi@monom.org>
Fri, 14 Jun 2024 11:20:19 +0000 (13:20 +0200)
commit42f788edccb954fe8b54c43809523e603c99f63c
treef41fc26b7e57ea3712241d4b20ca06a5625704fb
parentf62f9ad92c55628d2312aab57ed4f5f143d979a2
nvme: telemetry: report the correct error if the ioctl() fails.

It's wrong to assume that if the ioctl() returns a non-zero number
then the errno variable is set.
The ioctl() might return an NVMe Status error to inform the caller
that the requested log page is not supported, in that case errno is left
untouched.

The original code didn't handle this case and returned "-errno" even when
the latter was zero. The caller interpreted this as a successful operation
and this might lead to improperly dereferencing the log page pointer.

$ nvme telemetry-log /dev/nvme0 --output-file=telemetry_log.bin
ERROR: get_telemetry_log: : write failed with error : Bad address

Fix this bug by returning the NVMe status if errno is zero:

$ nvme telemetry-log /dev/nvme0 --output-file=telemetry_log.bin
NVMe status: Invalid Log Page: The log page indicated is invalid(0x109)
Failed to acquire telemetry log 265!

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
nvme.c