← Documents Documentation/admin-guide/LSM/Yama.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / LSM

Yama

Yama가 ptrace 공격 범위를 줄이는 이유와 PR_SET_PTRACER 예외, ptrace_scope 0–3 mode를 설명합니다.

Source pathDocumentation/admin-guide/LSM/Yama.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

ptrace 위협과 제한

Yama.rst:1-36

동일 UID process를 통한 credential 탈취 위험과 parent-child 제한을 설명합니다.

PR_SET_PTRACER와 sysctl

Yama.rst:37-75

Application-specific debugger 관계와 ptrace_scope 네 mode를 정리합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ====
2 Yama
3 ====
4
5 Yama is a Linux Security Module that collects system-wide DAC security
6 protections that are not handled by the core kernel itself. This is
7 selectable at build-time with ``CONFIG_SECURITY_YAMA``, and can be controlled
8 at run-time through sysctls in ``/proc/sys/kernel/yama``:
9
10 ptrace_scope
11 ============
12
13 As Linux grows in popularity, it will become a larger target for
14 malware. One particularly troubling weakness of the Linux process
15 interfaces is that a single user is able to examine the memory and
16 running state of any of their processes. For example, if one application
17 (e.g. Pidgin) was compromised, it would be possible for an attacker to
18 attach to other running processes (e.g. Firefox, SSH sessions, GPG agent,
19 etc) to extract additional credentials and continue to expand the scope
20 of their attack without resorting to user-assisted phishing.
21
22 This is not a theoretical problem. `SSH session hijacking
23 <https://www.blackhat.com/presentations/bh-usa-05/bh-us-05-boileau.pdf>`_
24 and `arbitrary code injection
25 <https://c-skills.blogspot.com/2007/05/injectso.html>`_ attacks already
26 exist and remain possible if ptrace is allowed to operate as before.
27 Since ptrace is not commonly used by non-developers and non-admins, system
28 builders should be allowed the option to disable this debugging system.
29
30 For a solution, some applications use ``prctl(PR_SET_DUMPABLE, ...)`` to
31 specifically disallow such ptrace attachment (e.g. ssh-agent), but many
32 do not. A more general solution is to only allow ptrace directly from a
33 parent to a child process (i.e. direct "gdb EXE" and "strace EXE" still
34 work), or with ``CAP_SYS_PTRACE`` (i.e. "gdb --pid=PID", and "strace -p PID"
35 still work as root).
36
37 In mode 1, software that has defined application-specific relationships
38 between a debugging process and its inferior (crash handlers, etc),
39 ``prctl(PR_SET_PTRACER, pid, ...)`` can be used. An inferior can declare which
40 other process (and its descendants) are allowed to call ``PTRACE_ATTACH``
41 against it. Only one such declared debugging process can exists for
42 each inferior at a time. For example, this is used by KDE, Chromium, and
43 Firefox's crash handlers, and by Wine for allowing only Wine processes
44 to ptrace each other. If a process wishes to entirely disable these ptrace
45 restrictions, it can call ``prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, ...)``
46 so that any otherwise allowed process (even those in external pid namespaces)
47 may attach.
48
49 The sysctl settings (writable only with ``CAP_SYS_PTRACE``) are:
50
51 0 - classic ptrace permissions:
52 a process can ``PTRACE_ATTACH`` to any other
53 process running under the same uid, as long as it is dumpable (i.e.
54 did not transition uids, start privileged, or have called
55 ``prctl(PR_SET_DUMPABLE...)`` already). Similarly, ``PTRACE_TRACEME`` is
56 unchanged.
57
58 1 - restricted ptrace:
59 a process must have a predefined relationship
60 with the inferior it wants to call ``PTRACE_ATTACH`` on. By default,
61 this relationship is that of only its descendants when the above
62 classic criteria is also met. To change the relationship, an
63 inferior can call ``prctl(PR_SET_PTRACER, debugger, ...)`` to declare
64 an allowed debugger PID to call ``PTRACE_ATTACH`` on the inferior.
65 Using ``PTRACE_TRACEME`` is unchanged.
66
67 2 - admin-only attach:
68 only processes with ``CAP_SYS_PTRACE`` may use ptrace, either with
69 ``PTRACE_ATTACH`` or through children calling ``PTRACE_TRACEME``.
70
71 3 - no attach:
72 no processes may use ptrace with ``PTRACE_ATTACH`` nor via
73 ``PTRACE_TRACEME``. Once set, this sysctl value cannot be changed.
74
75 The original children-only logic was based on the restrictions in grsecurity.
76

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Yama

1-9

Yama는 core kernel 자체가 처리하지 않는 system-wide DAC 보안 보호를 모은 Linux Security Module입니다.

Build 시 `CONFIG_SECURITY_YAMA`로 선택하며 runtime에는 `/proc/sys/kernel/yama`의 sysctl로 제어합니다.

ptrace_scope의 위협 모델

10-29

Linux가 널리 쓰일수록 malware의 큰 표적이 됩니다. 특히 Linux process interface에서는 한 user가 자신의 어느 process든 memory와 실행 상태를 조사할 수 있습니다.

예를 들어 Pidgin 같은 application이 침해되면 공격자가 Firefox, SSH session, GPG agent 같은 다른 실행 process에 attach해 추가 credential을 추출하고 user-assisted phishing 없이 공격 범위를 넓힐 수 있습니다.

이는 이론적 문제가 아닙니다. SSH session hijacking과 arbitrary code injection 공격이 이미 존재하며 ptrace를 기존 방식으로 허용하면 계속 가능합니다.

Non-developer와 non-admin은 ptrace를 흔히 사용하지 않으므로 system builder가 이 debugging system을 비활성화할 수 있어야 합니다.

Parent-child 제한과 capability

30-36

일부 application은 `prctl(PR_SET_DUMPABLE, ...)`로 ptrace attach를 명시적으로 금지하지만, 예를 들어 `ssh-agent`와 달리 많은 application은 그렇게 하지 않습니다.

더 일반적인 해결책은 parent가 direct child를 ptrace하는 것만 허용해 `gdb EXE`와 `strace EXE`는 계속 동작하게 하는 것입니다. 또는 `CAP_SYS_PTRACE`를 가진 root가 `gdb --pid=PID`와 `strace -p PID`를 사용할 수 있습니다.

Mode 1의 PR_SET_PTRACER

37-48

Mode 1에서 crash handler처럼 debugger process와 inferior 사이의 application-specific 관계를 정의한 software는 `prctl(PR_SET_PTRACER, pid, ...)`를 사용할 수 있습니다.

Inferior는 자신에게 `PTRACE_ATTACH`를 호출할 수 있는 다른 process와 그 descendant를 선언할 수 있습니다. Inferior마다 한 번에 하나의 debugger process만 선언할 수 있습니다.

KDE, Chromium, Firefox crash handler가 이를 사용하며 Wine도 Wine process끼리만 ptrace하도록 사용합니다.

Process가 이 제한을 완전히 끄려면 `prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, ...)`를 호출합니다. 그러면 external PID namespace의 process를 포함해 원래 허용되는 어떤 process든 attach할 수 있습니다.

ptrace_scope mode

49-75

Sysctl 설정은 `CAP_SYS_PTRACE`가 있어야 쓸 수 있습니다.

Mode동작
0classic ptrace permissions같은 UID로 실행되고 dumpable인 다른 process에 `PTRACE_ATTACH`할 수 있습니다. UID가 바뀌었거나 privileged로 시작했거나 `prctl(PR_SET_DUMPABLE...)`을 호출한 process는 제외됩니다. `PTRACE_TRACEME`는 그대로입니다.
1restricted ptraceInferior와 사전 정의 관계가 있어야 합니다. 기본 관계는 classic 조건도 만족하는 descendant입니다. Inferior가 `prctl(PR_SET_PTRACER, debugger, ...)`로 허용할 debugger PID를 선언할 수 있고 `PTRACE_TRACEME`는 그대로입니다.
2admin-only attach`CAP_SYS_PTRACE`가 있는 process만 `PTRACE_ATTACH` 또는 child의 `PTRACE_TRACEME`를 통해 ptrace를 사용할 수 있습니다.
3no attach어떤 process도 `PTRACE_ATTACH`나 `PTRACE_TRACEME`로 ptrace를 사용할 수 없습니다. 이 값으로 설정하면 다시 바꿀 수 없습니다.

원래의 children-only logic은 grsecurity의 제한을 기반으로 했습니다.