Skip to content

Commit

Permalink
clone3: fix cgroup argument sanity check
Browse files Browse the repository at this point in the history
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: ef2c41c ("clone3: allow spawning processes into cgroups")
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Link: https://lore.kernel.org/r/20200412202533.GA29554@asgard.redhat.com
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Eugene Syromiatnikov authored and Christian Brauner committed Apr 15, 2020
1 parent 3075afd commit e82a118
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit e82a118

Please sign in to comment.