Skip to content

Report swapinfo#140

Open
ben-grande wants to merge 1 commit into
QubesOS:mainfrom
ben-grande:share-swap
Open

Report swapinfo#140
ben-grande wants to merge 1 commit into
QubesOS:mainfrom
ben-grande:share-swap

Conversation

@ben-grande

Copy link
Copy Markdown

Allows distinguishing how much memory the qube is using from what is assigned by using "meminfo - swapinfo".

For: QubesOS/qubes-core-admin#827


Tested briefly.

Allows distinguishing how much memory the qube is using from what is
assigned by using "meminfo - swapinfo".

For: QubesOS/qubes-core-admin#827
ben-grande added a commit to ben-grande/qubes-core-admin that referenced this pull request Jun 25, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.24%. Comparing base (0dc52ab) to head (49418ad).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #140   +/-   ##
=======================================
  Coverage   71.24%   71.24%           
=======================================
  Files           6        6           
  Lines         991      991           
=======================================
  Hits          706      706           
  Misses        285      285           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ben-grande added a commit to ben-grande/qubes-core-admin that referenced this pull request Jun 25, 2026
ben-grande added a commit to ben-grande/qubes-core-admin that referenced this pull request Jul 3, 2026
ben-grande added a commit to ben-grande/qubes-core-admin that referenced this pull request Jul 6, 2026
Comment thread qmemman/meminfo-writer.c
Comment on lines +89 to +90
sprintf(used_mem_buf, "%lld", used_mem);
sprintf(used_swap_buf, "%lld", used_swap);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Redundant calls.

Comment thread qmemman/meminfo-writer.c
syslog(LOG_DAEMON | LOG_ERR, "error writing meminfo to xenstore ?");
exit(1);
}
if (!xs_write(xs, XBT_NULL, "memory/swapinfo", swap, strlen(swap))) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note to self: this can be merged only after core-admin part, which sets necessary xenstore access.

Comment thread qmemman/meminfo-writer.c
char *swap;
} UsedMem;

UsedMem parse(const char *meminfo_buf, const char* dom_current_buf)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW the usual method in C for returning more results is to either return a pointer to a structure (usually dynamically allocated via malloc), or add output parameters (pointers to where function should write result). In case of a simple structure like this, compiler will do the latter for you here, so it can stay this way, but keep in mind it wont be efficient code in more complex cases.

orbisai0security added a commit to orbisai0security/qubes-linux-utils that referenced this pull request Jul 11, 2026
…hardening)

Both sprintf() calls write at most ~20 bytes into buffers of 32 and 4096 bytes
respectively, so no overflow is possible with valid input. Replacing with
snprintf() is still correct defensive practice per CWE-676 and mirrors the
change already made in QubesOS#140.

Add unit tests for parse() that verify the memory-usage calculation and
threshold/hysteresis logic. The tests pass with either sprintf() or snprintf(),
confirming this is hardening rather than a bug fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread qmemman/meminfo-writer.c
return (UsedMem){ .mem = used_mem_buf, .swap = used_swap_buf };
}
return NULL;
return (UsedMem){ .mem = NULL, .swap = NULL };

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.

Report swap change if above threshold despite memory being below its threshold.

Comment thread qmemman/meminfo-writer.c
if (meminfo_data)
send_to_qmemman(xs, meminfo_data);
UsedMem meminfo_data = parse(meminfo_buf, dom_current_buf);
if (meminfo_data.mem && meminfo_data.mem[0])

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.

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