Skip to content

Security hardening: fix buffer handling and input validation#356

Open
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai:claude/security-audit-kxcfa
Open

Security hardening: fix buffer handling and input validation#356
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai:claude/security-audit-kxcfa

Conversation

@assisted-by-ai
Copy link
Copy Markdown

This PR addresses multiple security issues and improves robustness across the security-misc codebase.

Summary

Multiple security vulnerabilities and edge cases have been fixed, including buffer handling issues, input validation problems, and unsafe string operations. Additionally, several defensive programming improvements have been made to prevent potential exploitation vectors.

Key Changes

Buffer and String Handling:

  • Fixed print() function to not include null terminator in write length calculation, preventing off-by-one errors
  • Added NUL-termination guarantee for netlink message buffers to prevent out-of-bounds reads in hw_monitor()
  • Replaced unsafe strlen() calls with strnlen() to prevent reading past buffer boundaries when processing truncated netlink messages
  • Fixed FIFO creation permissions from overly permissive 0777 to restrictive 0600

Input Validation:

  • Added null pointer check for timeout value in fifo_monitor() to prevent null dereference
  • Added PAM_USER validation in pam-info to reject control characters and option injection attempts
  • Fixed strtok() call to use correct separator variable instead of hardcoded comma

Regex Pattern Matching:

  • Anchored user/group lookups in permission-hardener to line boundaries to prevent substring matches (e.g., 'roo' matching 'root')
  • Anchored file path matches in dpkg-statoverride checks to prevent partial path matches

Build Process:

  • Implemented atomic compilation for fm-shim-backend by writing to temporary file first, then moving into place to prevent corrupted binaries on interrupted builds

Code Quality:

  • Added exit(0) after kill_system() call for clarity
  • Disabled debug output (set -x) in pam_faillock_not_if_x to prevent leaking authentication details to system logs
  • Added threat model documentation for root-owned configuration file sourcing
  • Improved postinst error handling documentation to clarify intentional non-fatal error behavior

Notable Implementation Details

  • The netlink buffer fix uses strnlen() with the remaining buffer length to safely determine entry length without reading past boundaries
  • Regex anchoring uses $'\n' syntax to match line boundaries and prevent substring matches in multi-line strings
  • Atomic file operations prevent leaving corrupted binaries if the build process is interrupted

https://claude.ai/code/session_01LvyeXrhG1t4pNmiHt7iAbi

## Comments for reviewers:
## Threat model: Local files that can only be edited by root are
## out-of-scope and considered trusted.

emerg-shutdown.c:
- Fix strtok separator mismatch in load_list(): continuation call
  hardcoded "," instead of using the caller's separator, breaking
  pipe-separated key alias parsing (e.g. KEY_A|KEY_B).
- Fix FIFO permissions: mkfifo() used 0777, changed to 0600 to
  prevent unprivileged users from triggering emergency shutdown.
- Fix out-of-bounds read in netlink parsing: use strnlen() bounded
  by remaining buffer length instead of unbounded strlen().
- Fix NULL dereference on empty --timeout= argument.
- Add missing exit(0) after kill_system() in paranoid mode.
- Fix print() writing NUL terminator to output.

permission-hardener:
- Anchor user/group existence checks to line boundaries to prevent
  substring matches (e.g. 'roo' matching 'root:').
- Anchor dpkg-statoverride path lookups to prevent substring path
  matches (e.g. '/usr/bin/su' matching '/usr/bin/sudo').

pam-info:
- Add PAM_USER sanity check: reject control characters and values
  starting with '-' to prevent option injection into faillock.

pam_faillock_not_if_x:
- Remove set -x debug tracing from production PAM module to avoid
  leaking authentication details into system logs.

build-fm-shim-backend:
- Use atomic write pattern (compile to temp file, then mv) to
  prevent leaving a corrupted binary on interrupted compilation.

postinst:
- Add comments explaining that silent error handling for
  permission-hardener and update-grub is by design to avoid
  breaking APT.

hide-hardware-info, emerg-shutdown (shell):
- Add threat model comments documenting that root-owned config
  directories are trusted.

https://claude.ai/code/session_01LvyeXrhG1t4pNmiHt7iAbi
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.

2 participants