Skip to content

Commit c6993e4

Browse files
keesJames Morris
authored andcommitted
security: allow Yama to be unconditionally stacked
Unconditionally call Yama when CONFIG_SECURITY_YAMA_STACKED is selected, no matter what LSM module is primary. Ubuntu and Chrome OS already carry patches to do this, and Fedora has voiced interest in doing this as well. Instead of having multiple distributions (or LSM authors) carrying these patches, just allow Yama to be called unconditionally when selected by the new CONFIG. Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Serge E. Hallyn <serge.hallyn@canonical.com> Acked-by: Eric Paris <eparis@redhat.com> Acked-by: John Johansen <john.johansen@canonical.com> Signed-off-by: James Morris <james.l.morris@oracle.com>
1 parent 8119807 commit c6993e4

4 files changed

Lines changed: 70 additions & 4 deletions

File tree

‎include/linux/security.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,5 +3021,36 @@ static inline void free_secdata(void *secdata)
30213021
{ }
30223022
#endif /* CONFIG_SECURITY */
30233023

3024+
#ifdef CONFIG_SECURITY_YAMA
3025+
extern int yama_ptrace_access_check(struct task_struct *child,
3026+
unsigned int mode);
3027+
extern int yama_ptrace_traceme(struct task_struct *parent);
3028+
extern void yama_task_free(struct task_struct *task);
3029+
extern int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
3030+
unsigned long arg4, unsigned long arg5);
3031+
#else
3032+
static inline int yama_ptrace_access_check(struct task_struct *child,
3033+
unsigned int mode)
3034+
{
3035+
return 0;
3036+
}
3037+
3038+
static inline int yama_ptrace_traceme(struct task_struct *parent)
3039+
{
3040+
return 0;
3041+
}
3042+
3043+
static inline void yama_task_free(struct task_struct *task)
3044+
{
3045+
}
3046+
3047+
static inline int yama_task_prctl(int option, unsigned long arg2,
3048+
unsigned long arg3, unsigned long arg4,
3049+
unsigned long arg5)
3050+
{
3051+
return -ENOSYS;
3052+
}
3053+
#endif /* CONFIG_SECURITY_YAMA */
3054+
30243055
#endif /* ! __LINUX_SECURITY_H */
30253056

‎security/security.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,23 @@ int __init register_security(struct security_operations *ops)
136136

137137
int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
138138
{
139+
#ifdef CONFIG_SECURITY_YAMA_STACKED
140+
int rc;
141+
rc = yama_ptrace_access_check(child, mode);
142+
if (rc)
143+
return rc;
144+
#endif
139145
return security_ops->ptrace_access_check(child, mode);
140146
}
141147

142148
int security_ptrace_traceme(struct task_struct *parent)
143149
{
150+
#ifdef CONFIG_SECURITY_YAMA_STACKED
151+
int rc;
152+
rc = yama_ptrace_traceme(parent);
153+
if (rc)
154+
return rc;
155+
#endif
144156
return security_ops->ptrace_traceme(parent);
145157
}
146158

@@ -761,6 +773,9 @@ int security_task_create(unsigned long clone_flags)
761773

762774
void security_task_free(struct task_struct *task)
763775
{
776+
#ifdef CONFIG_SECURITY_YAMA_STACKED
777+
yama_task_free(task);
778+
#endif
764779
security_ops->task_free(task);
765780
}
766781

@@ -876,6 +891,12 @@ int security_task_wait(struct task_struct *p)
876891
int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
877892
unsigned long arg4, unsigned long arg5)
878893
{
894+
#ifdef CONFIG_SECURITY_YAMA_STACKED
895+
int rc;
896+
rc = yama_task_prctl(option, arg2, arg3, arg4, arg5);
897+
if (rc != -ENOSYS)
898+
return rc;
899+
#endif
879900
return security_ops->task_prctl(option, arg2, arg3, arg4, arg5);
880901
}
881902

‎security/yama/Kconfig‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ config SECURITY_YAMA
1111
Further information can be found in Documentation/security/Yama.txt.
1212

1313
If you are unsure how to answer this question, answer N.
14+
15+
config SECURITY_YAMA_STACKED
16+
bool "Yama stacked with other LSMs"
17+
depends on SECURITY_YAMA
18+
default n
19+
help
20+
When Yama is built into the kernel, force it to stack with the
21+
selected primary LSM.

‎security/yama/yama_lsm.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void yama_ptracer_del(struct task_struct *tracer,
100100
* yama_task_free - check for task_pid to remove from exception list
101101
* @task: task being removed
102102
*/
103-
static void yama_task_free(struct task_struct *task)
103+
void yama_task_free(struct task_struct *task)
104104
{
105105
yama_ptracer_del(task, task);
106106
}
@@ -116,7 +116,7 @@ static void yama_task_free(struct task_struct *task)
116116
* Return 0 on success, -ve on error. -ENOSYS is returned when Yama
117117
* does not handle the given option.
118118
*/
119-
static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
119+
int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
120120
unsigned long arg4, unsigned long arg5)
121121
{
122122
int rc;
@@ -243,7 +243,7 @@ static int ptracer_exception_found(struct task_struct *tracer,
243243
*
244244
* Returns 0 if following the ptrace is allowed, -ve on error.
245245
*/
246-
static int yama_ptrace_access_check(struct task_struct *child,
246+
int yama_ptrace_access_check(struct task_struct *child,
247247
unsigned int mode)
248248
{
249249
int rc;
@@ -296,7 +296,7 @@ static int yama_ptrace_access_check(struct task_struct *child,
296296
*
297297
* Returns 0 if following the ptrace is allowed, -ve on error.
298298
*/
299-
static int yama_ptrace_traceme(struct task_struct *parent)
299+
int yama_ptrace_traceme(struct task_struct *parent)
300300
{
301301
int rc;
302302

@@ -330,6 +330,7 @@ static int yama_ptrace_traceme(struct task_struct *parent)
330330
return rc;
331331
}
332332

333+
#ifndef CONFIG_SECURITY_YAMA_STACKED
333334
static struct security_operations yama_ops = {
334335
.name = "yama",
335336

@@ -338,6 +339,7 @@ static struct security_operations yama_ops = {
338339
.task_prctl = yama_task_prctl,
339340
.task_free = yama_task_free,
340341
};
342+
#endif
341343

342344
#ifdef CONFIG_SYSCTL
343345
static int yama_dointvec_minmax(struct ctl_table *table, int write,
@@ -384,13 +386,17 @@ static struct ctl_table yama_sysctl_table[] = {
384386

385387
static __init int yama_init(void)
386388
{
389+
#ifndef CONFIG_SECURITY_YAMA_STACKED
387390
if (!security_module_enable(&yama_ops))
388391
return 0;
392+
#endif
389393

390394
printk(KERN_INFO "Yama: becoming mindful.\n");
391395

396+
#ifndef CONFIG_SECURITY_YAMA_STACKED
392397
if (register_security(&yama_ops))
393398
panic("Yama: kernel registration failed.\n");
399+
#endif
394400

395401
#ifdef CONFIG_SYSCTL
396402
if (!register_sysctl_paths(yama_sysctl_path, yama_sysctl_table))

0 commit comments

Comments
 (0)