Skip to content

Commit 2d51448

Browse files
keesxjamesmorris
authored andcommitted
security: Yama LSM
This adds the Yama Linux Security Module to collect DAC security improvements (specifically just ptrace restrictions for now) that have existed in various forms over the years and have been carried outside the mainline kernel by other Linux distributions like Openwall and grsecurity. Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: John Johansen <john.johansen@canonical.com> Signed-off-by: James Morris <jmorris@namei.org>
1 parent 1a2a4d0 commit 2d51448

8 files changed

Lines changed: 411 additions & 0 deletions

File tree

‎Documentation/security/00-INDEX‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ SELinux.txt
66
- how to get started with the SELinux security enhancement.
77
Smack.txt
88
- documentation on the Smack Linux Security Module.
9+
Yama.txt
10+
- documentation on the Yama Linux Security Module.
911
apparmor.txt
1012
- documentation on the AppArmor security extension.
1113
credentials.txt

‎Documentation/security/Yama.txt‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Yama is a Linux Security Module that collects a number of system-wide DAC
2+
security protections that are not handled by the core kernel itself. To
3+
select it at boot time, specify "security=yama" (though this will disable
4+
any other LSM).
5+
6+
Yama is controlled through sysctl in /proc/sys/kernel/yama:
7+
8+
- ptrace_scope
9+
10+
==============================================================
11+
12+
ptrace_scope:
13+
14+
As Linux grows in popularity, it will become a larger target for
15+
malware. One particularly troubling weakness of the Linux process
16+
interfaces is that a single user is able to examine the memory and
17+
running state of any of their processes. For example, if one application
18+
(e.g. Pidgin) was compromised, it would be possible for an attacker to
19+
attach to other running processes (e.g. Firefox, SSH sessions, GPG agent,
20+
etc) to extract additional credentials and continue to expand the scope
21+
of their attack without resorting to user-assisted phishing.
22+
23+
This is not a theoretical problem. SSH session hijacking
24+
(http://www.storm.net.nz/projects/7) and arbitrary code injection
25+
(http://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+
For 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 descendents) 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.
45+
46+
0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
47+
process running under the same uid, as long as it is dumpable (i.e.
48+
did not transition uids, start privileged, or have called
49+
prctl(PR_SET_DUMPABLE...) already).
50+
51+
1 - restricted ptrace: a process must have a predefined relationship
52+
with the inferior it wants to call PTRACE_ATTACH on. By default,
53+
this relationship is that of only its descendants when the above
54+
classic criteria is also met. To change the relationship, an
55+
inferior can call prctl(PR_SET_PTRACER, debugger, ...) to declare
56+
an allowed debugger PID to call PTRACE_ATTACH on the inferior.
57+
58+
The original children-only logic was based on the restrictions in grsecurity.
59+
60+
==============================================================

‎include/linux/prctl.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,10 @@
114114
# define PR_SET_MM_START_BRK 6
115115
# define PR_SET_MM_BRK 7
116116

117+
/*
118+
* Set specific pid that is allowed to ptrace the current task.
119+
* A value of 0 mean "no process".
120+
*/
121+
#define PR_SET_PTRACER 0x59616d61
122+
117123
#endif /* _LINUX_PRCTL_H */

‎security/Kconfig‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ source security/selinux/Kconfig
187187
source security/smack/Kconfig
188188
source security/tomoyo/Kconfig
189189
source security/apparmor/Kconfig
190+
source security/yama/Kconfig
190191

191192
source security/integrity/Kconfig
192193

@@ -196,6 +197,7 @@ choice
196197
default DEFAULT_SECURITY_SMACK if SECURITY_SMACK
197198
default DEFAULT_SECURITY_TOMOYO if SECURITY_TOMOYO
198199
default DEFAULT_SECURITY_APPARMOR if SECURITY_APPARMOR
200+
default DEFAULT_SECURITY_YAMA if SECURITY_YAMA
199201
default DEFAULT_SECURITY_DAC
200202

201203
help
@@ -214,6 +216,9 @@ choice
214216
config DEFAULT_SECURITY_APPARMOR
215217
bool "AppArmor" if SECURITY_APPARMOR=y
216218

219+
config DEFAULT_SECURITY_YAMA
220+
bool "Yama" if SECURITY_YAMA=y
221+
217222
config DEFAULT_SECURITY_DAC
218223
bool "Unix Discretionary Access Controls"
219224

@@ -225,6 +230,7 @@ config DEFAULT_SECURITY
225230
default "smack" if DEFAULT_SECURITY_SMACK
226231
default "tomoyo" if DEFAULT_SECURITY_TOMOYO
227232
default "apparmor" if DEFAULT_SECURITY_APPARMOR
233+
default "yama" if DEFAULT_SECURITY_YAMA
228234
default "" if DEFAULT_SECURITY_DAC
229235

230236
endmenu

‎security/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ subdir-$(CONFIG_SECURITY_SELINUX) += selinux
77
subdir-$(CONFIG_SECURITY_SMACK) += smack
88
subdir-$(CONFIG_SECURITY_TOMOYO) += tomoyo
99
subdir-$(CONFIG_SECURITY_APPARMOR) += apparmor
10+
subdir-$(CONFIG_SECURITY_YAMA) += yama
1011

1112
# always enable default capabilities
1213
obj-y += commoncap.o
@@ -21,6 +22,7 @@ obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o
2122
obj-$(CONFIG_AUDIT) += lsm_audit.o
2223
obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/built-in.o
2324
obj-$(CONFIG_SECURITY_APPARMOR) += apparmor/built-in.o
25+
obj-$(CONFIG_SECURITY_YAMA) += yama/built-in.o
2426
obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o
2527

2628
# Object integrity file lists

‎security/yama/Kconfig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
config SECURITY_YAMA
2+
bool "Yama support"
3+
depends on SECURITY
4+
select SECURITYFS
5+
select SECURITY_PATH
6+
default n
7+
help
8+
This selects Yama, which extends DAC support with additional
9+
system-wide security settings beyond regular Linux discretionary
10+
access controls. Currently available is ptrace scope restriction.
11+
Further information can be found in Documentation/security/Yama.txt.
12+
13+
If you are unsure how to answer this question, answer N.

‎security/yama/Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
obj-$(CONFIG_SECURITY_YAMA) := yama.o
2+
3+
yama-y := yama_lsm.o

0 commit comments

Comments
 (0)