Keep set_task_ioprio with the other low-level code that accesses the io_context structure.
Unified · Split
| @@ -8,6 +8,7 @@ · 7 unmodified lines | |||
| 8 | #include <linux/bio.h> | 8 | #include <linux/bio.h> |
| 9 | #include <linux/blkdev.h> | 9 | #include <linux/blkdev.h> |
| 10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
| 11 | #include <linux/security.h> | ||
| 11 | #include <linux/sched/task.h> | 12 | #include <linux/sched/task.h> |
| 12 | 13 | ||
| 13 | #include "blk.h" | 14 | #include "blk.h" |
| @@ -280,8 +281,8 @@ static struct io_context *create_task_io_context(struct task_struct *task, · 266 unmodified lines | |||
| 280 | * This function always goes through task_lock() and it's better to use | 281 | * This function always goes through task_lock() and it's better to use |
| 281 | * %current->io_context + get_io_context() for %current. | 282 | * %current->io_context + get_io_context() for %current. |
| 282 | */ | 283 | */ |
| 283 | struct io_context *get_task_io_context(struct task_struct *task, | 284 | static struct io_context *get_task_io_context(struct task_struct *task, |
| 284 | gfp_t gfp_flags, int node) | 285 | gfp_t gfp_flags, int node) |
| 285 | { | 286 | { |
| 286 | struct io_context *ioc; | 287 | struct io_context *ioc; |
| 287 | 288 | ||
| @@ -298,6 +299,35 @@ struct io_context *get_task_io_context(struct task_struct *task, · 10 unmodified lines | |||
| 298 | return ioc; | 299 | return ioc; |
| 299 | } | 300 | } |
| 300 | 301 | ||
| 302 | int set_task_ioprio(struct task_struct *task, int ioprio) | ||
| 303 | { | ||
| 304 | int err; | ||
| 305 | struct io_context *ioc; | ||
| 306 | const struct cred *cred = current_cred(), *tcred; | ||
| 307 | |||
| 308 | rcu_read_lock(); | ||
| 309 | tcred = __task_cred(task); | ||
| 310 | if (!uid_eq(tcred->uid, cred->euid) && | ||
| 311 | !uid_eq(tcred->uid, cred->uid) && !capable(CAP_SYS_NICE)) { | ||
| 312 | rcu_read_unlock(); | ||
| 313 | return -EPERM; | ||
| 314 | } | ||
| 315 | rcu_read_unlock(); | ||
| 316 | |||
| 317 | err = security_task_setioprio(task, ioprio); | ||
| 318 | if (err) | ||
| 319 | return err; | ||
| 320 | |||
| 321 | ioc = get_task_io_context(task, GFP_ATOMIC, NUMA_NO_NODE); | ||
| 322 | if (ioc) { | ||
| 323 | ioc->ioprio = ioprio; | ||
| 324 | put_io_context(ioc); | ||
| 325 | } | ||
| 326 | |||
| 327 | return err; | ||
| 328 | } | ||
| 329 | EXPORT_SYMBOL_GPL(set_task_ioprio); | ||
| 330 | |||
| 301 | int __copy_io(unsigned long clone_flags, struct task_struct *tsk) | 331 | int __copy_io(unsigned long clone_flags, struct task_struct *tsk) |
| 302 | { | 332 | { |
| 303 | struct io_context *ioc = current->io_context; | 333 | struct io_context *ioc = current->io_context; |
| @@ -22,46 +22,14 @@ · 21 unmodified lines | |||
| 22 | */ | 22 | */ |
| 23 | #include <linux/gfp.h> | 23 | #include <linux/gfp.h> |
| 24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/export.h> | ||
| 26 | #include <linux/ioprio.h> | 25 | #include <linux/ioprio.h> |
| 27 | #include <linux/cred.h> | 26 | #include <linux/cred.h> |
| 28 | #include <linux/blkdev.h> | 27 | #include <linux/blkdev.h> |
| 29 | #include <linux/capability.h> | 28 | #include <linux/capability.h> |
| 30 | #include <linux/sched/user.h> | ||
| 31 | #include <linux/sched/task.h> | ||
| 32 | #include <linux/syscalls.h> | 29 | #include <linux/syscalls.h> |
| 33 | #include <linux/security.h> | 30 | #include <linux/security.h> |
| 34 | #include <linux/pid_namespace.h> | 31 | #include <linux/pid_namespace.h> |
| 35 | 32 | ||
| 36 | int set_task_ioprio(struct task_struct *task, int ioprio) | ||
| 37 | { | ||
| 38 | int err; | ||
| 39 | struct io_context *ioc; | ||
| 40 | const struct cred *cred = current_cred(), *tcred; | ||
| 41 | |||
| 42 | rcu_read_lock(); | ||
| 43 | tcred = __task_cred(task); | ||
| 44 | if (!uid_eq(tcred->uid, cred->euid) && | ||
| 45 | !uid_eq(tcred->uid, cred->uid) && !capable(CAP_SYS_NICE)) { | ||
| 46 | rcu_read_unlock(); | ||
| 47 | return -EPERM; | ||
| 48 | } | ||
| 49 | rcu_read_unlock(); | ||
| 50 | |||
| 51 | err = security_task_setioprio(task, ioprio); | ||
| 52 | if (err) | ||
| 53 | return err; | ||
| 54 | |||
| 55 | ioc = get_task_io_context(task, GFP_ATOMIC, NUMA_NO_NODE); | ||
| 56 | if (ioc) { | ||
| 57 | ioc->ioprio = ioprio; | ||
| 58 | put_io_context(ioc); | ||
| 59 | } | ||
| 60 | |||
| 61 | return err; | ||
| 62 | } | ||
| 63 | EXPORT_SYMBOL_GPL(set_task_ioprio); | ||
| 64 | |||
| 65 | int ioprio_check_cap(int ioprio) | 33 | int ioprio_check_cap(int ioprio) |
| 66 | { | 34 | { |
| 67 | int class = IOPRIO_PRIO_CLASS(ioprio); | 35 | int class = IOPRIO_PRIO_CLASS(ioprio); |
| @@ -116,8 +116,6 @@ struct task_struct; · 115 unmodified lines | |||
| 116 | #ifdef CONFIG_BLOCK | 116 | #ifdef CONFIG_BLOCK |
| 117 | void put_io_context(struct io_context *ioc); | 117 | void put_io_context(struct io_context *ioc); |
| 118 | void exit_io_context(struct task_struct *task); | 118 | void exit_io_context(struct task_struct *task); |
| 119 | struct io_context *get_task_io_context(struct task_struct *task, | ||
| 120 | gfp_t gfp_flags, int node); | ||
| 121 | int __copy_io(unsigned long clone_flags, struct task_struct *tsk); | 119 | int __copy_io(unsigned long clone_flags, struct task_struct *tsk); |
| 122 | static inline int copy_io(unsigned long clone_flags, struct task_struct *tsk) | 120 | static inline int copy_io(unsigned long clone_flags, struct task_struct *tsk) |
| 123 | { | 121 | { |