-
Notifications
You must be signed in to change notification settings - Fork 11
fix: mask /proc info and selective /dev mounting #719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -167,6 +167,26 @@ if [ "${AWF_CHROOT_ENABLED}" = "true" ]; then | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # SECURITY: Mask sensitive /proc entries to prevent kernel info disclosure (#223) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # /proc/kallsyms exposes kernel symbol addresses (aids ASLR bypass / exploit development) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # /proc/modules lists loaded kernel modules (aids kernel exploit targeting) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount --bind /dev/null /host/proc/kallsyms 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount --bind /dev/null /host/proc/modules 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "[entrypoint] Masked /proc/kallsyms and /proc/modules" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Set up additional /dev entries in chroot (#223) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Since /dev is selectively mounted (only null, zero, random, urandom, tty), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # we need to create pts, shm, and standard symlinks for proper operation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p /host/dev/pts /host/dev/shm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount -t devpts devpts /host/dev/pts 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount -t tmpfs tmpfs /host/dev/shm -o mode=1777 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Standard /dev symlinks needed by many programs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ln -sf /proc/self/fd /host/dev/fd 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ln -sf /proc/self/fd/0 /host/dev/stdin 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ln -sf /proc/self/fd/1 /host/dev/stdout 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ln -sf /proc/self/fd/2 /host/dev/stderr 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "[entrypoint] Set up /dev/pts, /dev/shm, and standard symlinks in chroot" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+173
to
+189
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount --bind /dev/null /host/proc/kallsyms 2>/dev/null || true | |
| mount --bind /dev/null /host/proc/modules 2>/dev/null || true | |
| echo "[entrypoint] Masked /proc/kallsyms and /proc/modules" | |
| # Set up additional /dev entries in chroot (#223) | |
| # Since /dev is selectively mounted (only null, zero, random, urandom, tty), | |
| # we need to create pts, shm, and standard symlinks for proper operation | |
| mkdir -p /host/dev/pts /host/dev/shm | |
| mount -t devpts devpts /host/dev/pts 2>/dev/null || true | |
| mount -t tmpfs tmpfs /host/dev/shm -o mode=1777 2>/dev/null || true | |
| # Standard /dev symlinks needed by many programs | |
| ln -sf /proc/self/fd /host/dev/fd 2>/dev/null || true | |
| ln -sf /proc/self/fd/0 /host/dev/stdin 2>/dev/null || true | |
| ln -sf /proc/self/fd/1 /host/dev/stdout 2>/dev/null || true | |
| ln -sf /proc/self/fd/2 /host/dev/stderr 2>/dev/null || true | |
| echo "[entrypoint] Set up /dev/pts, /dev/shm, and standard symlinks in chroot" | |
| masked_kallsyms=0 | |
| masked_modules=0 | |
| if mount --bind /dev/null /host/proc/kallsyms 2>/dev/null; then | |
| # Optionally remount read-only to enforce ro semantics | |
| if ! mount -o remount,ro,bind /host/proc/kallsyms 2>/dev/null; then | |
| echo "[entrypoint][WARN] Masked /proc/kallsyms but failed to remount read-only; continuing with writable bind mount" | |
| fi | |
| masked_kallsyms=1 | |
| else | |
| echo "[entrypoint][WARN] Failed to mask /proc/kallsyms; kernel symbol information may be exposed in chroot" | |
| fi | |
| if mount --bind /dev/null /host/proc/modules 2>/dev/null; then | |
| # Optionally remount read-only to enforce ro semantics | |
| if ! mount -o remount,ro,bind /host/proc/modules 2>/dev/null; then | |
| echo "[entrypoint][WARN] Masked /proc/modules but failed to remount read-only; continuing with writable bind mount" | |
| fi | |
| masked_modules=1 | |
| else | |
| echo "[entrypoint][WARN] Failed to mask /proc/modules; kernel module list may be exposed in chroot" | |
| fi | |
| if [ "$masked_kallsyms" -eq 1 ] && [ "$masked_modules" -eq 1 ]; then | |
| echo "[entrypoint] Masked /proc/kallsyms and /proc/modules" | |
| else | |
| echo "[entrypoint][WARN] One or more sensitive /proc entries could not be masked (kallsyms=$masked_kallsyms, modules=$masked_modules)" | |
| fi | |
| # Set up additional /dev entries in chroot (#223) | |
| # Since /dev is selectively mounted (only null, zero, random, urandom, tty), | |
| # we need to create pts, shm, and standard symlinks for proper operation | |
| mkdir -p /host/dev/pts /host/dev/shm | |
| devpts_ok=0 | |
| shm_ok=0 | |
| if mount -t devpts devpts /host/dev/pts 2>/dev/null; then | |
| devpts_ok=1 | |
| else | |
| echo "[entrypoint][WARN] Failed to mount devpts at /host/dev/pts; pseudo-terminal support in chroot may be limited" | |
| fi | |
| if mount -t tmpfs tmpfs /host/dev/shm -o mode=1777 2>/dev/null; then | |
| shm_ok=1 | |
| else | |
| echo "[entrypoint][WARN] Failed to mount tmpfs at /host/dev/shm; shared memory in chroot may be unavailable" | |
| fi | |
| # Standard /dev symlinks needed by many programs | |
| ln -sf /proc/self/fd /host/dev/fd 2>/dev/null || true | |
| ln -sf /proc/self/fd/0 /host/dev/stdin 2>/dev/null || true | |
| ln -sf /proc/self/fd/1 /host/dev/stdout 2>/dev/null || true | |
| ln -sf /proc/self/fd/2 /host/dev/stderr 2>/dev/null || true | |
| if [ "$devpts_ok" -eq 1 ] && [ "$shm_ok" -eq 1 ]; then | |
| echo "[entrypoint] Set up /dev/pts, /dev/shm, and standard symlinks in chroot" | |
| else | |
| echo "[entrypoint][WARN] /dev/pts or /dev/shm could not be fully set up in chroot (devpts_ok=$devpts_ok, shm_ok=$shm_ok)" | |
| fi |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -439,6 +439,14 @@ export function generateDockerCompose( | |||||||
| `${config.workDir}/agent-logs:${effectiveHome}/.copilot/logs:rw`, | ||||||||
| ]; | ||||||||
|
|
||||||||
| // SECURITY: Mask sensitive /proc entries to prevent kernel info disclosure (#223) | ||||||||
| // /proc/kallsyms exposes kernel symbol addresses (aids ASLR bypass and exploit development) | ||||||||
| // /proc/modules lists loaded kernel modules (aids kernel exploit targeting) | ||||||||
| agentVolumes.push( | ||||||||
| '/dev/null:/proc/kallsyms:ro', | ||||||||
| '/dev/null:/proc/modules:ro', | ||||||||
| ); | ||||||||
|
|
||||||||
| // Add chroot-related volume mounts when --enable-chroot is specified | ||||||||
| // These mounts enable chroot /host to work properly for running host binaries | ||||||||
| if (config.enableChroot) { | ||||||||
|
|
@@ -460,16 +468,29 @@ export function generateDockerCompose( | |||||||
| // /opt/hostedtoolcache contains Python, Node, Ruby, Go, Java, etc. | ||||||||
| agentVolumes.push('/opt:/host/opt:ro'); | ||||||||
|
|
||||||||
| // Special filesystem mounts for chroot (needed for devices and runtime introspection) | ||||||||
| // Special filesystem mounts for chroot (needed for runtime introspection) | ||||||||
| // NOTE: /proc is NOT bind-mounted here. Instead, a fresh container-scoped procfs is | ||||||||
| // mounted at /host/proc in entrypoint.sh via 'mount -t proc'. This provides: | ||||||||
| // - Dynamic /proc/self/exe (required by .NET CLR and other runtimes) | ||||||||
| // - /proc/cpuinfo, /proc/meminfo (required by JVM, .NET GC) | ||||||||
| // - Container-scoped only (does not expose host process info) | ||||||||
| // The mount requires SYS_ADMIN capability, which is dropped before user code runs. | ||||||||
| // Additionally, /proc/kallsyms and /proc/modules are masked in entrypoint.sh. | ||||||||
| agentVolumes.push( | ||||||||
| '/sys:/host/sys:ro', // Read-only sysfs | ||||||||
| '/dev:/host/dev:ro', // Read-only device nodes (needed by some runtimes) | ||||||||
| ); | ||||||||
|
|
||||||||
| // SECURITY: Selective /dev mounting to prevent host block device access (#223) | ||||||||
| // A blanket /dev:/host/dev:ro mount exposes ALL host device nodes including | ||||||||
| // /dev/sda*, /dev/nvme* etc. which aids disk forensics and potential data exfiltration. | ||||||||
| // Instead, mount only the specific device nodes that runtimes need. | ||||||||
| // Additional /dev entries (pts, shm, symlinks) are set up in entrypoint.sh. | ||||||||
| agentVolumes.push( | ||||||||
| '/dev/null:/host/dev/null:rw', | ||||||||
| '/dev/zero:/host/dev/zero:rw', | ||||||||
| '/dev/random:/host/dev/random:ro', | ||||||||
| '/dev/urandom:/host/dev/urandom:ro', | ||||||||
| '/dev/tty:/host/dev/tty:rw', | ||||||||
|
||||||||
| '/dev/tty:/host/dev/tty:rw', | |
| '/dev/tty:/host/dev/tty:rw', | |
| '/dev/ptmx:/host/dev/ptmx:rw', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chroot mode mounts devpts at
/host/dev/pts, but/host/dev/ptmxisn’t created/mounted here. Many programs expect/dev/ptmx(often a symlink topts/ptmx) for pseudo-terminal allocation; without it, PTY-using commands can fail inside the chroot. Consider creating/host/dev/ptmx -> pts/ptmxalongside these standard /dev symlinks, or allowlist-bind-mount/dev/ptmxinto/host/dev/ptmx.