Skip to content

Commit aa43457

Browse files
nmtadamAl Viro
authored andcommitted
block: add ioprio_check_cap function
Aio per command iopriority support introduces a second interface between userland and the kernel capable of passing iopriority. The aio interface also needs the ability to verify that the submitting context has sufficient privileges to submit IOPRIO_RT commands. This patch creates the ioprio_check_cap function to be used by the ioprio_set system call and also by the aio interface. Signed-off-by: Adam Manzanares <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Jeff Moyer <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 1da9277 commit aa43457

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

block/ioprio.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,10 @@ int set_task_ioprio(struct task_struct *task, int ioprio)
6161
}
6262
EXPORT_SYMBOL_GPL(set_task_ioprio);
6363

64-
SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
64+
int ioprio_check_cap(int ioprio)
6565
{
6666
int class = IOPRIO_PRIO_CLASS(ioprio);
6767
int data = IOPRIO_PRIO_DATA(ioprio);
68-
struct task_struct *p, *g;
69-
struct user_struct *user;
70-
struct pid *pgrp;
71-
kuid_t uid;
72-
int ret;
7368

7469
switch (class) {
7570
case IOPRIO_CLASS_RT:
@@ -92,6 +87,21 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
9287
return -EINVAL;
9388
}
9489

90+
return 0;
91+
}
92+
93+
SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
94+
{
95+
struct task_struct *p, *g;
96+
struct user_struct *user;
97+
struct pid *pgrp;
98+
kuid_t uid;
99+
int ret;
100+
101+
ret = ioprio_check_cap(ioprio);
102+
if (ret)
103+
return ret;
104+
95105
ret = -ESRCH;
96106
rcu_read_lock();
97107
switch (which) {

include/linux/ioprio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,6 @@ extern int ioprio_best(unsigned short aprio, unsigned short bprio);
7777

7878
extern int set_task_ioprio(struct task_struct *task, int ioprio);
7979

80+
extern int ioprio_check_cap(int ioprio);
81+
8082
#endif

0 commit comments

Comments
 (0)