linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clone3: fix cgroup argument sanity check
@ 2020-04-12 20:25 Eugene Syromiatnikov
  2020-04-12 21:10 ` Christian Brauner
  2020-04-15 12:38 ` Christian Brauner
  0 siblings, 2 replies; 3+ messages in thread
From: Eugene Syromiatnikov @ 2020-04-12 20:25 UTC (permalink / raw)
  To: linux-kernel, Christian Brauner
  Cc: Andrew Morton, Ingo Molnar, Tejun Heo, Oleg Nesterov,
	Johannes Weiner, Li Zefan, Peter Zijlstra, cgroups,
	Dmitry V. Levin

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")
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
---
 kernel/fork.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index 4385f3d..b4f7775 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -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){
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] clone3: fix cgroup argument sanity check
  2020-04-12 20:25 [PATCH] clone3: fix cgroup argument sanity check Eugene Syromiatnikov
@ 2020-04-12 21:10 ` Christian Brauner
  2020-04-15 12:38 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2020-04-12 21:10 UTC (permalink / raw)
  To: Eugene Syromiatnikov
  Cc: linux-kernel, Christian Brauner, Andrew Morton, Ingo Molnar,
	Tejun Heo, Oleg Nesterov, Johannes Weiner, Li Zefan,
	Peter Zijlstra, cgroups, Dmitry V. Levin

On Sun, Apr 12, 2020 at 10:25:33PM +0200, Eugene Syromiatnikov wrote:
> 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")
> Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>

Thanks, will queue for rc2 unless I hear objections.
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] clone3: fix cgroup argument sanity check
  2020-04-12 20:25 [PATCH] clone3: fix cgroup argument sanity check Eugene Syromiatnikov
  2020-04-12 21:10 ` Christian Brauner
@ 2020-04-15 12:38 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2020-04-15 12:38 UTC (permalink / raw)
  To: Eugene Syromiatnikov
  Cc: linux-kernel, Christian Brauner, Andrew Morton, Ingo Molnar,
	Tejun Heo, Oleg Nesterov, Johannes Weiner, Li Zefan,
	Peter Zijlstra, cgroups, Dmitry V. Levin

On Sun, Apr 12, 2020 at 10:25:33PM +0200, Eugene Syromiatnikov wrote:
> 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")
> Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
> Acked-by: Christian Brauner <christian.brauner@ubuntu.com>

Applied, thanks!
Christian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-15 12:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-12 20:25 [PATCH] clone3: fix cgroup argument sanity check Eugene Syromiatnikov
2020-04-12 21:10 ` Christian Brauner
2020-04-15 12:38 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).