* [PATCH] blk-ioprio: check capabilities before promoting a cgroup to RT
@ 2026-11-16 9:05 Hungyu Lin
2026-11-16 12:43 ` Tao Cui
0 siblings, 1 reply; 2+ messages in thread
From: Hungyu Lin @ 2026-11-16 9:05 UTC (permalink / raw)
To: axboe
Cc: tj, josef, bvanassche, cgroups, linux-block, linux-kernel, dennylin0707
ioprio_set() and the per-request I/O priority of aio and io_uring only
hand out IOPRIO_CLASS_RT to tasks that have CAP_SYS_ADMIN or
CAP_SYS_NICE. The io.prio.class cgroup attribute has no such check.
Writing "promote-to-rt", or its alias "none-to-rt", to it changes the
requests of the cgroup to the RT class.
The attribute exists in every cgroup that has the io controller enabled
and it is not hierarchical. A user that got a cgroup delegated owns the
files of the child cgroups it creates there, so it can create a child
cgroup, move into it and write "promote-to-rt" to its io.prio.class.
Its requests are then issued with IOPRIO_CLASS_RT although ioprio_set()
fails with -EPERM for the same task, and mq-deadline dispatches them
before the best-effort requests of everybody else.
The delegation model in Documentation/admin-guide/cgroup-v2.rst expects
the settings of all resource controllers to be hierarchical, so that a
delegatee can only distribute further what it received from its parent.
This attribute lets it raise the priority class of its own requests
instead.
Require CAP_SYS_ADMIN or CAP_SYS_NICE for the two policies that raise
the priority class, like ioprio_check_cap() does. The other policies are
left alone.
Fixes: 556910e39249 ("block: Introduce the ioprio rq-qos policy")
Cc: stable@vger.kernel.org
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
block/blk-ioprio.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/block/blk-ioprio.c b/block/blk-ioprio.c
index 8fa8bca35062..ea32db727b16 100644
--- a/block/blk-ioprio.c
+++ b/block/blk-ioprio.c
@@ -14,6 +14,7 @@
#include <linux/blk-mq.h>
#include <linux/blk_types.h>
+#include <linux/capability.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include "blk-cgroup.h"
@@ -91,6 +92,9 @@ static ssize_t ioprio_set_prio_policy(struct kernfs_open_file *of, char *buf,
ret = sysfs_match_string(policy_name, buf);
if (ret < 0)
return ret;
+ if ((ret == POLICY_PROMOTE_TO_RT || ret == POLICY_NONE_TO_RT) &&
+ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_NICE))
+ return -EPERM;
blkcg->prio_policy = ret;
return nbytes;
}
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] blk-ioprio: check capabilities before promoting a cgroup to RT
2026-11-16 9:05 [PATCH] blk-ioprio: check capabilities before promoting a cgroup to RT Hungyu Lin
@ 2026-11-16 12:43 ` Tao Cui
0 siblings, 0 replies; 2+ messages in thread
From: Tao Cui @ 2026-11-16 12:43 UTC (permalink / raw)
To: Hungyu Lin, axboe
Cc: cui.tao, tj, josef, bvanassche, cgroups, linux-block, linux-kernel
在 2026/11/16 17:05, Hungyu Lin 写道:
> ioprio_set() and the per-request I/O priority of aio and io_uring only
> hand out IOPRIO_CLASS_RT to tasks that have CAP_SYS_ADMIN or
> CAP_SYS_NICE. The io.prio.class cgroup attribute has no such check.
> Writing "promote-to-rt", or its alias "none-to-rt", to it changes the
> requests of the cgroup to the RT class.
>
> The attribute exists in every cgroup that has the io controller enabled
> and it is not hierarchical. A user that got a cgroup delegated owns the
> files of the child cgroups it creates there, so it can create a child
> cgroup, move into it and write "promote-to-rt" to its io.prio.class.
> Its requests are then issued with IOPRIO_CLASS_RT although ioprio_set()
> fails with -EPERM for the same task, and mq-deadline dispatches them
> before the best-effort requests of everybody else.
>
> The delegation model in Documentation/admin-guide/cgroup-v2.rst expects
> the settings of all resource controllers to be hierarchical, so that a
> delegatee can only distribute further what it received from its parent.
> This attribute lets it raise the priority class of its own requests
> instead.
>
> Require CAP_SYS_ADMIN or CAP_SYS_NICE for the two policies that raise
> the priority class, like ioprio_check_cap() does. The other policies are
> left alone.
>
> Fixes: 556910e39249 ("block: Introduce the ioprio rq-qos policy")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
Reviewed-by: Tao Cui <cuitao@kylinos.cn>
> ---
> block/blk-ioprio.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/block/blk-ioprio.c b/block/blk-ioprio.c
> index 8fa8bca35062..ea32db727b16 100644
> --- a/block/blk-ioprio.c
> +++ b/block/blk-ioprio.c
> @@ -14,6 +14,7 @@
>
> #include <linux/blk-mq.h>
> #include <linux/blk_types.h>
> +#include <linux/capability.h>
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include "blk-cgroup.h"
> @@ -91,6 +92,9 @@ static ssize_t ioprio_set_prio_policy(struct kernfs_open_file *of, char *buf,
> ret = sysfs_match_string(policy_name, buf);
> if (ret < 0)
> return ret;
> + if ((ret == POLICY_PROMOTE_TO_RT || ret == POLICY_NONE_TO_RT) &&
> + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_NICE))
> + return -EPERM;
> blkcg->prio_policy = ret;
> return nbytes;
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 12:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 9:05 [PATCH] blk-ioprio: check capabilities before promoting a cgroup to RT Hungyu Lin
2026-11-16 12:43 ` Tao Cui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®