Skip to content

fix(native): support sandboxed apps on Linux - #2347

Open
jpnurmi wants to merge 6 commits into
v1from
jpnurmi/fix/native-sandbox
Open

jpnurmi wants to merge 6 commits into
v1from
jpnurmi/fix/native-sandbox

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fix the native backend to operate in Linux sandboxes that restrict /dev/shm or ptrace. This came up with Flutter, where Linux apps are commonly distributed as strictly confined snaps or Flatpaks.

  • sentry_init failed with "failed to create IPC semaphore: Read-only file system" when /dev/shm was not writable. The named semaphore /sentry-init-<pid> only serialized backend startups within the process, so Linux now uses the same sentry_mutex_t as macOS and Android. This also stops every process from leaving a /dev/shm/sem.sentry-init-<pid> file behind:
    $ ls -1 /dev/shm/sem.sentry-init-* | wc -l
    1517
    $ du -ch /dev/shm/sem.sentry-init-* | tail -1
    6,0M	total
    
  • With ptrace blocked by seccomp, minidumps had no stack or memory contents, because every read gave up when PTRACE_ATTACH failed. The minidump writer now reads with process_vm_readv first and attaches only for the PTRACE_PEEKDATA fallback.

Manually tested with a strictly confined Flutter snap:
image
https://sentry-sdks.sentry.io/issues/7870817365/

Ref: getsentry/sentry-dart#3585

Rename the macOS sandbox tests to test_integration_sandbox.py and add
Linux tests that simulate sandbox restrictions: a read-only /dev/shm in
a user and mount namespace, and a seccomp filter that blocks ptrace.

The read-only /dev/shm and semaphore leak tests are expected to fail
until the named init semaphore is gone.
sentry_init failed when /dev/shm was not writable, as in containers
and sandboxes that restrict /dev/shm:

  [sentry] WARN failed to create IPC semaphore: Read-only file system
  [sentry] WARN failed to initialize backend

Serialize backend startups with the process-local mutex that macOS and
Android already use instead of a named semaphore. This also stops every
process from leaving a /dev/shm/sem.sentry-init-<pid> file behind.

Ref: getsentry/sentry-dart#3585
With ptrace blocked by seccomp, the minidump had no stack or memory
contents, because every read gave up when the attach failed:

  WARN ptrace(PTRACE_ATTACH) failed for TID <tid>: Operation not permitted
  WARN Failed to read stack memory from process <pid> at 0x...: Operation not permitted

Read with process_vm_readv first, which needs no ptrace attach, and
attach only for the PEEKDATA fallback.

Ref: getsentry/sentry-dart#3585
@jpnurmi
jpnurmi force-pushed the jpnurmi/fix/native-sandbox branch from e71d09a to 8b71516 Compare November 26, 2026 12:38
The Wine job runs on a Linux host but builds Windows binaries, so the
Linux sandbox tests ran there and could not find the executable:

  FileNotFoundError: [Errno 2] No such file or directory: '.../sentry_test_integration'

Ref: https://github.com/getsentry/sentry-native/actions/runs/45821617724/job/139946658959

This branch has not been deployed

No deployments
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