Skip to contentSkip to conversation

clone3: fix cgroup argument sanity check

PATCH Applied Eugene Syromiatnikov 2 participants 3 messages Apr 12, 2020 – Apr 15, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clone3: fix cgroup argument sanity check

Checking that cgroup field value of struct clone_args is less than 0 is useless, as it is defined as unsigned 64-bit integer. Moreover, it doesn't catch the situations where its higher bits are lost during the assignment to the cgroup field of the cgroup field of the internal struct kernel_clone_args (where it is declared as signed 32-bit integer), so it is still possible to pass garbage there. A check against INT_MAX solves both these issues.

Fixes ef2c41cf38a7559b ("clone3: allow spawning processes into cgroups")
---
 kernel/fork.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/fork.c +1 -1
index 4385f3d..b4f7775 100644
@@ -2631,7 +2631,7 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,
 		     !valid_signal(args.exit_signal)))
 		return -EINVAL;
 
-	if ((args.flags & CLONE_INTO_CGROUP) && args.cgroup < 0)
+	if ((args.flags & CLONE_INTO_CGROUP) && args.cgroup > INT_MAX)
 		return -EINVAL;
 
 	*kargs = (struct kernel_clone_args){
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Eugene Syromiatnikov

Checking that cgroup field value of struct clone_args is less than 0 is useless, as it is defined as unsigned 64-bit integer. Moreover, it doesn't catch the situations where its higher bits are lost during the assignment to the cgroup field of the cgroup field of the internal struct kernel_clone_args (where it is declared as signed 32-bit integer), so it is still possible to pass garbage there. A check against INT_MAX solves both these issues.

Fixes ef2c41cf38a7559b ("clone3: allow spawning processes into cgroups")

Thanks, will queue for rc2 unless I hear objections.

#2 lore raw
In reply to Eugene Syromiatnikov
Quoted 11 lines · Eugene Syromiatnikov

Checking that cgroup field value of struct clone_args is less than 0 is useless, as it is defined as unsigned 64-bit integer. Moreover, it doesn't catch the situations where its higher bits are lost during the assignment to the cgroup field of the cgroup field of the internal struct kernel_clone_args (where it is declared as signed 32-bit integer), so it is still possible to pass garbage there. A check against INT_MAX solves both these issues.

Fixes ef2c41cf38a7559b ("clone3: allow spawning processes into cgroups")

Applied, thanks!
Christian