Skip to content

timestamp: add macOS (Darwin) support#136

Open
asaflavi-baysecurity wants to merge 1 commit into
Duncaen:masterfrom
asaflavi-baysecurity:feat/macos-timestamp-support
Open

timestamp: add macOS (Darwin) support#136
asaflavi-baysecurity wants to merge 1 commit into
Duncaen:masterfrom
asaflavi-baysecurity:feat/macos-timestamp-support

Conversation

@asaflavi-baysecurity
Copy link
Copy Markdown

Summary

Adds macOS support to the timestamp-based persist mechanism, which was previously Linux-only.

The --with-timestamp configure flag now works on macOS (Darwin), enabling permit persist in doas.conf.

Changes

  • proc_info: use sysctl(KERN_PROC) to obtain tty number and process start time instead of parsing /proc/$pid/stat
  • CLOCK_BOOTTIME: map to CLOCK_MONOTONIC_RAW on macOS — not user-settable, ticks during sleep on Apple Silicon
  • sys/vfs.h → sys/mount.h: Darwin equivalent
  • st_atim/st_mtim → st_atimespec/st_mtimespec: Darwin timespec field names
  • timespec macros: define directly on macOS — the bundled sys-time.h fallback uses _SYS_TIME_H_ as its include guard, which collides with the system <sys/time.h> guard, causing the fallback to be silently skipped
  • TIMESTAMP_DIR: default to /var/run/doas on macOS (/run does not exist on Darwin)
  • fchown after file creation: on BSD, new files inherit gid from the parent directory (not the creator's effective gid). Without an explicit fchown(fd, 0, getgid()), the timestamp file gets the wrong gid and timestamp_check rejects it with "timestamp uid, gid or mode wrong"

Testing

  • Built and tested on macOS 26 (Darwin 25.2.0, arm64, Apple clang 16.0.0)
  • ./configure --prefix=/opt/local --sysconfdir=/opt/local/etc --with-timestamp succeeds
  • permit persist <user> as root works: first invocation prompts for password, subsequent invocations within 5 minutes skip auth
  • Timestamp files in /var/run/doas/ created with correct ownership (root:, mode 0000)
  • Verified timestamps expire correctly after 5 minutes
  • Verified timestamps are rejected after reboot (/var/run is cleared on macOS boot)

The timestamp-based persist mechanism was Linux-only due to
dependencies on /proc, CLOCK_BOOTTIME, sys/vfs.h, and the
assumption that new files inherit the creator's gid.

This patch adds macOS support:

- proc_info: use sysctl(KERN_PROC) to obtain tty number and
  process start time instead of parsing /proc/$pid/stat
- CLOCK_BOOTTIME: map to CLOCK_MONOTONIC_RAW, which is not
  user-settable and ticks during sleep on Apple Silicon
- sys/vfs.h: use sys/mount.h on Darwin
- st_atim/st_mtim: map to st_atimespec/st_mtimespec
- timespec macros: define directly on macOS since the bundled
  sys-time.h fallback header collides with the system header
  include guard
- TIMESTAMP_DIR: default to /var/run/doas on macOS (/run does
  not exist on Darwin)
- fchown after file creation: BSD inherits gid from the parent
  directory, so the timestamp file gets the wrong gid without
  an explicit fchown(fd, 0, getgid())

Tested on macOS 26 (Darwin 25.2.0, arm64).
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.

1 participant