diff options
author | James Morris <jmorris@namei.org> | 2006-06-23 05:03:58 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-23 10:42:53 -0400 |
commit | 03e68060636e05989ea94bcb671ab633948f328c (patch) | |
tree | aee5e7b55f31998536dd3a4f54f38caeee6105d6 | |
parent | 9216dfad4fc97ab639ef0885efc713f3d7a20d5b (diff) |
[PATCH] lsm: add task_setioprio hook
Implement an LSM hook for setting a task's IO priority, similar to the hook
for setting a tasks's nice value.
A previous version of this LSM hook was included in an older version of
multiadm by Jan Engelhardt, although I don't recall it being submitted
upstream.
Also included is the corresponding SELinux hook, which re-uses the setsched
permission in the proccess class.
Signed-off-by: James Morris <jmorris@namei.org>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Jan Engelhardt <jengelh@linux01.gwdg.de>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Jens Axboe <axboe@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | fs/ioprio.c | 6 | ||||
-rw-r--r-- | include/linux/security.h | 16 | ||||
-rw-r--r-- | security/dummy.c | 6 | ||||
-rw-r--r-- | security/selinux/hooks.c | 6 |
4 files changed, 34 insertions, 0 deletions
diff --git a/fs/ioprio.c b/fs/ioprio.c index ca77008146c0..7fa76ed53c10 100644 --- a/fs/ioprio.c +++ b/fs/ioprio.c | |||
@@ -24,15 +24,21 @@ | |||
24 | #include <linux/blkdev.h> | 24 | #include <linux/blkdev.h> |
25 | #include <linux/capability.h> | 25 | #include <linux/capability.h> |
26 | #include <linux/syscalls.h> | 26 | #include <linux/syscalls.h> |
27 | #include <linux/security.h> | ||
27 | 28 | ||
28 | static int set_task_ioprio(struct task_struct *task, int ioprio) | 29 | static int set_task_ioprio(struct task_struct *task, int ioprio) |
29 | { | 30 | { |
31 | int err; | ||
30 | struct io_context *ioc; | 32 | struct io_context *ioc; |
31 | 33 | ||
32 | if (task->uid != current->euid && | 34 | if (task->uid != current->euid && |
33 | task->uid != current->uid && !capable(CAP_SYS_NICE)) | 35 | task->uid != current->uid && !capable(CAP_SYS_NICE)) |
34 | return -EPERM; | 36 | return -EPERM; |
35 | 37 | ||
38 | err = security_task_setioprio(task, ioprio); | ||
39 | if (err) | ||
40 | return err; | ||
41 | |||
36 | task_lock(task); | 42 | task_lock(task); |
37 | 43 | ||
38 | task->ioprio = ioprio; | 44 | task->ioprio = ioprio; |
diff --git a/include/linux/security.h b/include/linux/security.h index 383c320fc834..65b32a0c6207 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
@@ -577,6 +577,11 @@ struct swap_info_struct; | |||
577 | * @p contains the task_struct of process. | 577 | * @p contains the task_struct of process. |
578 | * @nice contains the new nice value. | 578 | * @nice contains the new nice value. |
579 | * Return 0 if permission is granted. | 579 | * Return 0 if permission is granted. |
580 | * @task_setioprio | ||
581 | * Check permission before setting the ioprio value of @p to @ioprio. | ||
582 | * @p contains the task_struct of process. | ||
583 | * @ioprio contains the new ioprio value | ||
584 | * Return 0 if permission is granted. | ||
580 | * @task_setrlimit: | 585 | * @task_setrlimit: |
581 | * Check permission before setting the resource limits of the current | 586 | * Check permission before setting the resource limits of the current |
582 | * process for @resource to @new_rlim. The old resource limit values can | 587 | * process for @resource to @new_rlim. The old resource limit values can |
@@ -1210,6 +1215,7 @@ struct security_operations { | |||
1210 | int (*task_getsid) (struct task_struct * p); | 1215 | int (*task_getsid) (struct task_struct * p); |
1211 | int (*task_setgroups) (struct group_info *group_info); | 1216 | int (*task_setgroups) (struct group_info *group_info); |
1212 | int (*task_setnice) (struct task_struct * p, int nice); | 1217 | int (*task_setnice) (struct task_struct * p, int nice); |
1218 | int (*task_setioprio) (struct task_struct * p, int ioprio); | ||
1213 | int (*task_setrlimit) (unsigned int resource, struct rlimit * new_rlim); | 1219 | int (*task_setrlimit) (unsigned int resource, struct rlimit * new_rlim); |
1214 | int (*task_setscheduler) (struct task_struct * p, int policy, | 1220 | int (*task_setscheduler) (struct task_struct * p, int policy, |
1215 | struct sched_param * lp); | 1221 | struct sched_param * lp); |
@@ -1836,6 +1842,11 @@ static inline int security_task_setnice (struct task_struct *p, int nice) | |||
1836 | return security_ops->task_setnice (p, nice); | 1842 | return security_ops->task_setnice (p, nice); |
1837 | } | 1843 | } |
1838 | 1844 | ||
1845 | static inline int security_task_setioprio (struct task_struct *p, int ioprio) | ||
1846 | { | ||
1847 | return security_ops->task_setioprio (p, ioprio); | ||
1848 | } | ||
1849 | |||
1839 | static inline int security_task_setrlimit (unsigned int resource, | 1850 | static inline int security_task_setrlimit (unsigned int resource, |
1840 | struct rlimit *new_rlim) | 1851 | struct rlimit *new_rlim) |
1841 | { | 1852 | { |
@@ -2478,6 +2489,11 @@ static inline int security_task_setnice (struct task_struct *p, int nice) | |||
2478 | return 0; | 2489 | return 0; |
2479 | } | 2490 | } |
2480 | 2491 | ||
2492 | static inline int security_task_setioprio (struct task_struct *p, int ioprio) | ||
2493 | { | ||
2494 | return 0; | ||
2495 | } | ||
2496 | |||
2481 | static inline int security_task_setrlimit (unsigned int resource, | 2497 | static inline int security_task_setrlimit (unsigned int resource, |
2482 | struct rlimit *new_rlim) | 2498 | struct rlimit *new_rlim) |
2483 | { | 2499 | { |
diff --git a/security/dummy.c b/security/dummy.c index c98d553984ec..879a98523b1b 100644 --- a/security/dummy.c +++ b/security/dummy.c | |||
@@ -516,6 +516,11 @@ static int dummy_task_setnice (struct task_struct *p, int nice) | |||
516 | return 0; | 516 | return 0; |
517 | } | 517 | } |
518 | 518 | ||
519 | static int dummy_task_setioprio (struct task_struct *p, int ioprio) | ||
520 | { | ||
521 | return 0; | ||
522 | } | ||
523 | |||
519 | static int dummy_task_setrlimit (unsigned int resource, struct rlimit *new_rlim) | 524 | static int dummy_task_setrlimit (unsigned int resource, struct rlimit *new_rlim) |
520 | { | 525 | { |
521 | return 0; | 526 | return 0; |
@@ -972,6 +977,7 @@ void security_fixup_ops (struct security_operations *ops) | |||
972 | set_to_dummy_if_null(ops, task_getsid); | 977 | set_to_dummy_if_null(ops, task_getsid); |
973 | set_to_dummy_if_null(ops, task_setgroups); | 978 | set_to_dummy_if_null(ops, task_setgroups); |
974 | set_to_dummy_if_null(ops, task_setnice); | 979 | set_to_dummy_if_null(ops, task_setnice); |
980 | set_to_dummy_if_null(ops, task_setioprio); | ||
975 | set_to_dummy_if_null(ops, task_setrlimit); | 981 | set_to_dummy_if_null(ops, task_setrlimit); |
976 | set_to_dummy_if_null(ops, task_setscheduler); | 982 | set_to_dummy_if_null(ops, task_setscheduler); |
977 | set_to_dummy_if_null(ops, task_getscheduler); | 983 | set_to_dummy_if_null(ops, task_getscheduler); |
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 093efba4d9b6..9dcf298921d4 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -2645,6 +2645,11 @@ static int selinux_task_setnice(struct task_struct *p, int nice) | |||
2645 | return task_has_perm(current,p, PROCESS__SETSCHED); | 2645 | return task_has_perm(current,p, PROCESS__SETSCHED); |
2646 | } | 2646 | } |
2647 | 2647 | ||
2648 | static int selinux_task_setioprio(struct task_struct *p, int ioprio) | ||
2649 | { | ||
2650 | return task_has_perm(current, p, PROCESS__SETSCHED); | ||
2651 | } | ||
2652 | |||
2648 | static int selinux_task_setrlimit(unsigned int resource, struct rlimit *new_rlim) | 2653 | static int selinux_task_setrlimit(unsigned int resource, struct rlimit *new_rlim) |
2649 | { | 2654 | { |
2650 | struct rlimit *old_rlim = current->signal->rlim + resource; | 2655 | struct rlimit *old_rlim = current->signal->rlim + resource; |
@@ -4383,6 +4388,7 @@ static struct security_operations selinux_ops = { | |||
4383 | .task_getsid = selinux_task_getsid, | 4388 | .task_getsid = selinux_task_getsid, |
4384 | .task_setgroups = selinux_task_setgroups, | 4389 | .task_setgroups = selinux_task_setgroups, |
4385 | .task_setnice = selinux_task_setnice, | 4390 | .task_setnice = selinux_task_setnice, |
4391 | .task_setioprio = selinux_task_setioprio, | ||
4386 | .task_setrlimit = selinux_task_setrlimit, | 4392 | .task_setrlimit = selinux_task_setrlimit, |
4387 | .task_setscheduler = selinux_task_setscheduler, | 4393 | .task_setscheduler = selinux_task_setscheduler, |
4388 | .task_getscheduler = selinux_task_getscheduler, | 4394 | .task_getscheduler = selinux_task_getscheduler, |