diff mbox series

[v2] clone302: Fix short size test

Message ID 20230902074726.9837-1-wegao@suse.com
State Superseded
Headers show
Series [v2] clone302: Fix short size test | expand

Commit Message

Wei Gao Sept. 2, 2023, 7:47 a.m. UTC
Signed-off-by: Wei Gao <wegao@suse.com>
---
 include/lapi/sched.h                        | 4 ++++
 testcases/kernel/syscalls/clone3/clone302.c | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

Comments

Richard Palethorpe Sept. 4, 2023, 7:48 a.m. UTC | #1
Hello,

Wei Gao via ltp <ltp@lists.linux.it> writes:

> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
>  include/lapi/sched.h                        | 4 ++++
>  testcases/kernel/syscalls/clone3/clone302.c | 3 ++-
>  2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/include/lapi/sched.h b/include/lapi/sched.h
> index ac766efc5..f1133ca12 100644
> --- a/include/lapi/sched.h
> +++ b/include/lapi/sched.h
> @@ -46,6 +46,10 @@ static inline int sched_getattr(pid_t pid, struct sched_attr *attr,
>  }
>  
>  #ifndef HAVE_CLONE3
> +
> +#define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */

I think what Martin meant was to define a minimal struct, which I prefer
for a few reasons.

You can find the original def in commit:
7f192e3cd316ba58c88dfa26796cf77789dd9872

(I found that using Git blame on fork.c)

Then you can assert our struct is == 64 during the test. This is
paranoid, but it checks that the test is compiled correctly and we
defined the structure correctly.

> +#define CLONE_ARGS_SIZE_VER2 88 /* sizeof third published struct */
> +
>  struct clone_args {
>  	uint64_t __attribute__((aligned(8))) flags;
>  	uint64_t __attribute__((aligned(8))) pidfd;
> diff --git a/testcases/kernel/syscalls/clone3/clone302.c b/testcases/kernel/syscalls/clone3/clone302.c
> index b1b4ccebb..02ccb3c29 100644
> --- a/testcases/kernel/syscalls/clone3/clone302.c
> +++ b/testcases/kernel/syscalls/clone3/clone302.c
> @@ -34,7 +34,8 @@ static struct tcase {
>  } tcases[] = {
>  	{"invalid args", &invalid_args, sizeof(*valid_args), 0, NULL, SIGCHLD, 0, 0, 0, EFAULT},
>  	{"zero size", &valid_args, 0, 0, NULL, SIGCHLD, 0, 0, 0, EINVAL},
> -	{"short size", &valid_args, sizeof(*valid_args) - 1, 0, NULL, SIGCHLD, 0, 0, 0, EINVAL},
> +	{"short size", &valid_args, CLONE_ARGS_SIZE_VER0 - 1, 0, NULL, SIGCHLD, 0, 0, 0, EINVAL},
> +	{"short size for clone_into_group flag", &valid_args, CLONE_ARGS_SIZE_VER2 - 1, CLONE_INTO_CGROUP, NULL, SIGCHLD, 0, 0, 0, EINVAL},
>  	{"extra size", &valid_args, sizeof(*valid_args) + 1, 0, NULL, SIGCHLD, 0, 0, 0, EFAULT},
>  	{"sighand-no-VM", &valid_args, sizeof(*valid_args), CLONE_SIGHAND, NULL, SIGCHLD, 0, 0, 0, EINVAL},
>  	{"thread-no-sighand", &valid_args, sizeof(*valid_args), CLONE_THREAD, NULL, SIGCHLD, 0, 0, 0, EINVAL},
> -- 
> 2.35.3
diff mbox series

Patch

diff --git a/include/lapi/sched.h b/include/lapi/sched.h
index ac766efc5..f1133ca12 100644
--- a/include/lapi/sched.h
+++ b/include/lapi/sched.h
@@ -46,6 +46,10 @@  static inline int sched_getattr(pid_t pid, struct sched_attr *attr,
 }
 
 #ifndef HAVE_CLONE3
+
+#define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */
+#define CLONE_ARGS_SIZE_VER2 88 /* sizeof third published struct */
+
 struct clone_args {
 	uint64_t __attribute__((aligned(8))) flags;
 	uint64_t __attribute__((aligned(8))) pidfd;
diff --git a/testcases/kernel/syscalls/clone3/clone302.c b/testcases/kernel/syscalls/clone3/clone302.c
index b1b4ccebb..02ccb3c29 100644
--- a/testcases/kernel/syscalls/clone3/clone302.c
+++ b/testcases/kernel/syscalls/clone3/clone302.c
@@ -34,7 +34,8 @@  static struct tcase {
 } tcases[] = {
 	{"invalid args", &invalid_args, sizeof(*valid_args), 0, NULL, SIGCHLD, 0, 0, 0, EFAULT},
 	{"zero size", &valid_args, 0, 0, NULL, SIGCHLD, 0, 0, 0, EINVAL},
-	{"short size", &valid_args, sizeof(*valid_args) - 1, 0, NULL, SIGCHLD, 0, 0, 0, EINVAL},
+	{"short size", &valid_args, CLONE_ARGS_SIZE_VER0 - 1, 0, NULL, SIGCHLD, 0, 0, 0, EINVAL},
+	{"short size for clone_into_group flag", &valid_args, CLONE_ARGS_SIZE_VER2 - 1, CLONE_INTO_CGROUP, NULL, SIGCHLD, 0, 0, 0, EINVAL},
 	{"extra size", &valid_args, sizeof(*valid_args) + 1, 0, NULL, SIGCHLD, 0, 0, 0, EFAULT},
 	{"sighand-no-VM", &valid_args, sizeof(*valid_args), CLONE_SIGHAND, NULL, SIGCHLD, 0, 0, 0, EINVAL},
 	{"thread-no-sighand", &valid_args, sizeof(*valid_args), CLONE_THREAD, NULL, SIGCHLD, 0, 0, 0, EINVAL},