Skip to content

log: fix overflow for very large telemetry logs - #4002

Open
kpmckay wants to merge 1 commit into
linux-nvme:masterfrom
kpmckay:telemetry-log-overflow-fix
Open

log: fix overflow for very large telemetry logs#4002
kpmckay wants to merge 1 commit into
linux-nvme:masterfrom
kpmckay:telemetry-log-overflow-fix

Conversation

@kpmckay

@kpmckay kpmckay commented Sep 9, 2026

Copy link
Copy Markdown

The data_written and data_remaining variables in get_telemetry_log() are defined as ints. The data_remaining variable is assigned from a size_t representing the total log size. If this is greater than 2 GiB, the log cannot be extracted as data_remaining goes negative. The data_written variable takes an ssize_t from write().

Change data_remaining to size_t to prevent the overflow, and data_written to ssize_t to match write(). Modify the format specifiers in nvme_show_error() accordingly.

@igaw
igaw requested a lite review from Copilot September 10, 2026 08:05
Comment thread plugins/log/log-plugin.c Outdated
__func__, libnvme_strerror(errno));
break;
} else if (data_written <= data_remaining) {
} else if ((size_t)data_written <= data_remaining) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

casting types is a code smell, is there no other way to get this sorted out properly?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

shr_write_all

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah ok, replaced the write loop with shr_write_alI(). No casts and removes duplicated functionality.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The core type changes correctly address the reported overflow, with only a minor maintainability suggestion around explicit casting remaining.

Pull request overview

This PR fixes telemetry log extraction failures for very large logs by correcting signed/unsigned type usage in get_telemetry_log() and updating related formatting to match the new types.

Changes:

  • Change data_remaining from int to size_t to prevent overflow/negative values for logs >2GiB.
  • Change data_written from int to ssize_t to match write()’s return type.
  • Update the overwrite diagnostic format specifiers to use %zx and cast accordingly.
File summaries
File Description
plugins/log/log-plugin.c Adjusts telemetry log write-loop variable types and error formatting to handle very large log sizes safely.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread plugins/log/log-plugin.c Outdated
Comment on lines 598 to 600
} else if ((size_t)data_written <= data_remaining) {
data_remaining -= data_written;
data_ptr += data_written;
@kpmckay
kpmckay force-pushed the telemetry-log-overflow-fix branch from c20b7c9 to 4d4334e Compare September 10, 2026 19:05
The data_written and data_remaining variables in get_telemetry_log() are
defined as ints. The data_remaining variable is assigned from a size_t
representing the total log size. If this is greater than 2 GiB, the log
cannot be extracted as data_remaining goes negative.

Replace telemetry log write loop with shr_write_all() helper which
already uses a size_t for log length.

Signed-off-by: Keith McKay <kpmckay@gmail.com>
@kpmckay
kpmckay force-pushed the telemetry-log-overflow-fix branch from 4d4334e to 8fdc4fc Compare September 10, 2026 19:17
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.

3 participants