Skip to content

Commit a966dcf

Browse files
esyr-rhChristian Brauner
authored andcommitted
clone3: add build-time CLONE_ARGS_SIZE_VER* validity checks
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 <[email protected]> Acked-by: Christian Brauner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 6217387 commit a966dcf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

kernel/fork.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,14 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,
26052605
struct clone_args args;
26062606
pid_t *kset_tid = kargs->set_tid;
26072607

2608+
BUILD_BUG_ON(offsetofend(struct clone_args, tls) !=
2609+
CLONE_ARGS_SIZE_VER0);
2610+
BUILD_BUG_ON(offsetofend(struct clone_args, set_tid_size) !=
2611+
CLONE_ARGS_SIZE_VER1);
2612+
BUILD_BUG_ON(offsetofend(struct clone_args, cgroup) !=
2613+
CLONE_ARGS_SIZE_VER2);
2614+
BUILD_BUG_ON(sizeof(struct clone_args) != CLONE_ARGS_SIZE_VER2);
2615+
26082616
if (unlikely(usize > PAGE_SIZE))
26092617
return -E2BIG;
26102618
if (unlikely(usize < CLONE_ARGS_SIZE_VER0))

0 commit comments

Comments
 (0)