* [PATCH] clone3: add build-time CLONE_ARGS_SIZE_VER* validity checks
@ 2020-04-12 20:26 Eugene Syromiatnikov
2020-04-12 21:24 ` Christian Brauner
2020-04-15 12:38 ` Christian Brauner
0 siblings, 2 replies; 3+ messages in thread
From: Eugene Syromiatnikov @ 2020-04-12 20:26 UTC (permalink / raw)
To: linux-kernel, Christian Brauner
Cc: Andrew Morton, Ingo Molnar, Tejun Heo, Peter Zijlstra, Dmitry V. Levin
CLONE_ARGS_SIZE_VER* macros are defined explicitly and not via
the offsets of the relevant struct clone_args fields, which makes
it rather error-prone, so it probably makes sense to add some
compile-time checks for them (including the one that breaks
on struct clone_args extension as a reminder to add a relevant
size macro and a similar check). Function copy_clone_args_from_user
seems to be a good place for such checks.
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
---
kernel/fork.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/kernel/fork.c b/kernel/fork.c
index b4f7775..11bcc7e 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2605,6 +2605,14 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,
struct clone_args args;
pid_t *kset_tid = kargs->set_tid;
+ BUILD_BUG_ON(offsetofend(struct clone_args, tls) !=
+ CLONE_ARGS_SIZE_VER0);
+ BUILD_BUG_ON(offsetofend(struct clone_args, set_tid_size) !=
+ CLONE_ARGS_SIZE_VER1);
+ BUILD_BUG_ON(offsetofend(struct clone_args, cgroup) !=
+ CLONE_ARGS_SIZE_VER2);
+ BUILD_BUG_ON(sizeof(struct clone_args) != CLONE_ARGS_SIZE_VER2);
+
if (unlikely(usize > PAGE_SIZE))
return -E2BIG;
if (unlikely(usize < CLONE_ARGS_SIZE_VER0))
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] clone3: add build-time CLONE_ARGS_SIZE_VER* validity checks
2020-04-12 20:26 [PATCH] clone3: add build-time CLONE_ARGS_SIZE_VER* validity checks Eugene Syromiatnikov
@ 2020-04-12 21:24 ` Christian Brauner
2020-04-15 12:38 ` Christian Brauner
1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2020-04-12 21:24 UTC (permalink / raw)
To: Eugene Syromiatnikov
Cc: linux-kernel, Christian Brauner, Andrew Morton, Ingo Molnar,
Tejun Heo, Peter Zijlstra, Dmitry V. Levin
On Sun, Apr 12, 2020 at 10:26:58PM +0200, Eugene Syromiatnikov wrote:
> CLONE_ARGS_SIZE_VER* macros are defined explicitly and not via
> the offsets of the relevant struct clone_args fields, which makes
> it rather error-prone, so it probably makes sense to add some
> compile-time checks for them (including the one that breaks
> on struct clone_args extension as a reminder to add a relevant
> size macro and a similar check). Function copy_clone_args_from_user
> seems to be a good place for such checks.
>
> Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
Yeah, that seems like a good idea to me.
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: add build-time CLONE_ARGS_SIZE_VER* validity checks
2020-04-12 20:26 [PATCH] clone3: add build-time CLONE_ARGS_SIZE_VER* validity checks Eugene Syromiatnikov
2020-04-12 21:24 ` 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, Peter Zijlstra, Dmitry V. Levin
On Sun, Apr 12, 2020 at 10:26:58PM +0200, Eugene Syromiatnikov wrote:
> CLONE_ARGS_SIZE_VER* macros are defined explicitly and not via
> the offsets of the relevant struct clone_args fields, which makes
> it rather error-prone, so it probably makes sense to add some
> compile-time checks for them (including the one that breaks
> on struct clone_args extension as a reminder to add a relevant
> size macro and a similar check). Function copy_clone_args_from_user
> seems to be a good place for such checks.
>
> 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:40 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:26 [PATCH] clone3: add build-time CLONE_ARGS_SIZE_VER* validity checks Eugene Syromiatnikov
2020-04-12 21:24 ` 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).