8000 fix(minimald): raise guest inotify limits and restrict the kernel log at boot by norrietaylor · Pull Request #1940 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

fix(minimald): raise guest inotify limits and restrict the kernel log at boot - #1940

Merged
norrietaylor merged 1 commit into
mainfrom
fix/guest-boot-sysctls
Oct 5, 2026
Merged

norrietaylor merged 1 commit into
mainfrom
fix/guest-boot-sysctls

Conversation

@norrietaylor
@norrietaylor norrietaylor commented Oct 4, 2026 •
Copy link
Copy Markdown
Member

Summary

Every box on a microVM maps onto the guest daemon's single kernel uid. Two VM-wide kernel defaults therefore weaken isolation and fairness between the sessions that share a VM:

  • inotify. All boxes charge one set of per-uid counters: 128 instances, and a watch ceiling scaled to 1% of guest RAM (about 31k on a 4 GiB guest). File watchers in one session (dev servers, tsc --watch, language servers) can use the whole allowance, and then watchers in every other session on the VM fail with EMFILE/ENOSPC.
  • kernel log. With kernel.dmesg_restrict at 0, any box can read the VM's kernel log, and that log includes records about other sessions' processes.

At boot, the microVM's init (and only it, never a host-native daemon) now writes:

sysctl value
fs.inotify.max_user_instances 8192
fs.inotify.max_user_watches 524288
kernel.dmesg_restrict 1

The inotify values are the common dev-machine settings. They are ceilings, not reservations. A watch costs about 1 KiB of kernel memory on 64-bit, but only while it exists, and the memory is charged to the memory cgroup of the box that holds it. The full 524288 (about 512 MiB) is reached only if boxes actually watch that many files. With dmesg_restrict set, reading the kernel log needs CAP_SYSLOG, and no box holds it.

The writes are best effort. A setting the kernel refuses is logged as a warning and boot carries on, because the kernel default is the previous behaviour. The settings live in a table, guest::MICROVM_SYSCTLS, and the write helper takes the /proc/sys root as a parameter, so both are unit-tested against a temp dir.

Refs gominimal/inbox#824

Test plan

  • just ci (macOS scope): local PR gates green
  • cross test -p minimald --lib --target aarch64-unknown-linux-musl --locked -- guest::: test result: ok. 16 passed; 0 failed, including the two new tests
  • cross clippy -p minimald --all-targets --target aarch64-unknown-linux-musl --locked -- -D warnings: clean
  • Booted this branch's microVM stack and attached to a box. It reads 8192, 524288, and 1 from /proc/sys, dmesg fails as the box user with read kernel buffer failed: Operation not permitted, and the guest log has no sysctl warnings.

Summary by CodeRabbit

  • New Features
    • MicroVMs now use higher inotify limits and restrict access to kernel logs. These settings are applied during startup; native daemons are unaffected.

… at boot

Every box on a microVM maps onto the daemon's one kernel uid, so the
per-uid inotify counters and the kernel log are shared by every session
on the VM. Raise the inotify ceilings to the common dev-machine values
and set kernel.dmesg_restrict, best effort, from the microVM init only.

Refs gominimal/inbox#824
@norrietaylor
norrietaylor requested a review from a team as a code owner October 4, 2026 05:34
@coderabbitai
coderabbitai Bot commented Oct 4, 2026 •
Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: fdc59688-9c15-4989-805f-b2975054958f
📥 Commits

Reviewing files that changed from the base of the PR and between 6be1a8c and 069798c.

📒 Files selected for processing (2)
  • crates/minimald/src/guest.rs
  • crates/minimald/src/main.rs

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The guest module defines three kernel sysctl settings and writes them under /proc/sys, continuing after individual write failures. On Linux, the daemon applies these settings when running as the microVM init; native daemons skip this step.

Changes

MicroVM sysctl setup

Layer / File(s) Summary
Define and write sysctl settings
crates/minimald/src/guest.rs
The guest module defines inotify limits and restricts kernel-log access. Its writer reports failed paths and errors while continuing with other settings. Tests check the configured values, relative paths, and failure handling.
Apply settings during startup
crates/minimald/src/main.rs
The daemon calls guest::apply_microvm_sysctls() when running as the microVM init. Native daemons skip the call.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: evanspearman, twitchyliquid64

Merge Risk: ⚪ Minimal · up to 06979

MicroVM startup attempts to apply the inotify limits and restrict kernel-log access before serving boxes; individual write failures are warned and do not stop startup. No concrete merge-blocking risk was found.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change and uses a concise Conventional Commit format.
Description check ✅ Passed The description explains the changes, rationale, and test results. It uses “Test plan” instead of “Testing” and omits the checklist, but it is otherwise complete.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the kernel’s list
Three settings hop into place
The guest writes each path in turn
One missed file will not stop the rest
Native daemons skip the run
Then quiet paws depart the scene

Comment @coderabbitai help to get the list of available commands.

@minimal-foundry
minimal-foundry Bot commented Oct 4, 2026 •
Copy link
Copy Markdown
Contributor

Approved: no findings at 069798cb4953.

Nothing to do.

Clobber: none: git log on both files shows the head is this PR and no recent fix to anything sysctl-related is overwritten.

@minimal-foundry minimal-foundry Bot 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.

minimal-review — approved

Verdict APPROVE — No findings.

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Oct 4, 2026
@norrietaylor
norrietaylor added this pull request to the merge queue Oct 5, 2026
Merged via the queue into main with commit 8c47366 Oct 5, 2026
34 checks passed
@norrietaylor
norrietaylor deleted the fix/guest-boot-sysctls branch October 5, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3881

2 participants

0