Harden linux-modules-cleanup.service with a systemd drop-in - #10655
Harden linux-modules-cleanup.service with a systemd drop-in#10655surim0n wants to merge 2 commits into
Conversation
The kernel-modules-hook cleanup oneshot only needs to remove stale module trees under /usr/lib/modules. Add a drop-in that makes the rest of the filesystem read-only and private, lowering the systemd-analyze security score from 9.6 UNSAFE to a MEDIUM range. Fixes omacom#9297. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Retain filesystem metadata capabilities while dropping SYS_ADMIN and SYS_MODULE. Reload stale manager configuration without starting cleanup. Exercise the real Arch cleanup command in isolated namespace fixtures and distinguish these checks from full systemd-profile verification. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Pushed 439ef7f and kept draft pending a full native Arch/systemd run. The profile now drops CAP_SYS_ADMIN/CAP_SYS_MODULE, retains ordinary filesystem metadata privileges, and has an idempotent reload migration. Tests execute the actual Arch cleanup command in an isolated namespace and check protected trees, archive metadata, failed transfers and remount denial. Those passed, but approximate selected restrictions; the updated body distinguishes them from complete-profile validation. |
|
Full-system follow-up: 439ef7f now passed in a real x86_64 Arch VM with PID-1 systemd 261.2 and kernel-modules-hook 0.1.7-3. The actual service and reload migration worked; running/package-owned trees and ordinary ACL/xattr/file-capability/link metadata were preserved. A separate service under the same complete profile denied outside writes, remounts and module loading. Rebooting to the updated kernel also ran cleanup successfully. An extra set-ID fixture correctly failed archival before source removal; this restriction is explicitly documented. VM is shut down; marking ready for review. |
Summary
Harden linux-modules-cleanup.service while retaining access to /usr/lib/modules for stale-tree archival and removal. Fixes #9297.
Changes
Full-system validation
Validated head 439ef7f in a disposable x86_64 Arch VM under QEMU TCG, with real PID-1 systemd 261.2, kernel-modules-hook 0.1.7-3, pacman 7.1 and rsync 3.5.0. This supersedes the earlier container-only validation limitation.
Scope and limitations
The committed namespace test approximates selected restrictions; the separate VM run above validates the complete profile. Set OMARCHY_REQUIRE_CLEANUP_NAMESPACE_TEST=1 to reject prerequisite skips.
RestrictSUIDSGID intentionally prevents preserving set-ID bits: an additional 06750 fixture caused rsync status 23 and left the source intact. No claim of arbitrary set-ID or trusted/IMA xattr preservation is made. No security score is used as proof of correctness.
Generated with Devin