[1/2] fork: allow CLONE_NEWTIME in clone3 flags

Message ID 20230308105126.10107-1-tklauser@distanz.ch
State New
Headers
Series [1/2] fork: allow CLONE_NEWTIME in clone3 flags |

Commit Message

Tobias Klauser March 8, 2023, 10:51 a.m. UTC
  Currently, calling clone3() with CLONE_NEWTIME in clone_args->flags
fails with -EINVAL. This is because CLONE_NEWTIME intersects with
CSIGNAL. However, CSIGNAL was deprecated when clone3 was introduced in
commit 7f192e3cd316 ("fork: add clone3"), allowing re-use of that part
of clone flags.

Fix this by explicitly allowing CLONE_NEWTIME in clone3_args_valid. This
is also in line with the respective check in check_unshare_flags which
allow CLONE_NEWTIME for unshare().

Fixes: 769071ac9f20 ("ns: Introduce Time Namespace")
Cc: Andrey Vagin <avagin@openvz.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
 kernel/fork.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Christian Brauner March 8, 2023, 11:16 a.m. UTC | #1
On Wed, Mar 08, 2023 at 11:51:26AM +0100, Tobias Klauser wrote:
> Currently, calling clone3() with CLONE_NEWTIME in clone_args->flags
> fails with -EINVAL. This is because CLONE_NEWTIME intersects with
> CSIGNAL. However, CSIGNAL was deprecated when clone3 was introduced in
> commit 7f192e3cd316 ("fork: add clone3"), allowing re-use of that part
> of clone flags.
> 
> Fix this by explicitly allowing CLONE_NEWTIME in clone3_args_valid. This
> is also in line with the respective check in check_unshare_flags which
> allow CLONE_NEWTIME for unshare().
> 
> Fixes: 769071ac9f20 ("ns: Introduce Time Namespace")
> Cc: Andrey Vagin <avagin@openvz.org>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> ---

Oh I either forgot or missed that we use a CSIGNAL bit for
CLONE_NEWTIME. Looks good,

Reviewed-by: Christian Brauner <brauner@kernel.org>
  
Tobias Klauser March 8, 2023, 11:34 a.m. UTC | #2
On 2023-03-08 at 11:53:20 +0100, Tobias Klauser <tklauser@distanz.ch> wrote:
> Verify that clone3 can be called successfully with CLONE_NEWTIME in
> flags.

Appologies, I somehow messed up the recepient list in this patch leading
to it not being sent to LKML. Please let me know in case you want me to
send it again.

> Cc: Andrey Vagin <avagin@openvz.org>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: Shuah Khan <shuah@kernel.org>
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> ---
>  tools/testing/selftests/clone3/clone3.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tools/testing/selftests/clone3/clone3.c b/tools/testing/selftests/clone3/clone3.c
> index cd4582129c7d..4fce46afe6db 100644
> --- a/tools/testing/selftests/clone3/clone3.c
> +++ b/tools/testing/selftests/clone3/clone3.c
> @@ -195,5 +195,8 @@ int main(int argc, char *argv[])
>  	test_clone3(CLONE_NEWPID, getpagesize() + 8, -E2BIG,
>  			CLONE3_ARGS_NO_TEST);
>  
> +	/* Do a clone3() in a new time namespace */
> +	test_clone3(CLONE_NEWTIME, 0, 0, CLONE3_ARGS_NO_TEST);
> +
>  	return !ksft_get_fail_cnt() ? ksft_exit_pass() : ksft_exit_fail();
>  }
> -- 
> 2.39.1
>
  
Christian Brauner March 8, 2023, 11:40 a.m. UTC | #3
From: Christian Brauner (Microsoft) <brauner@kernel.org>


On Wed, 08 Mar 2023 11:51:26 +0100, Tobias Klauser wrote:
> Currently, calling clone3() with CLONE_NEWTIME in clone_args->flags
> fails with -EINVAL. This is because CLONE_NEWTIME intersects with
> CSIGNAL. However, CSIGNAL was deprecated when clone3 was introduced in
> commit 7f192e3cd316 ("fork: add clone3"), allowing re-use of that part
> of clone flags.
> 
> Fix this by explicitly allowing CLONE_NEWTIME in clone3_args_valid. This
> is also in line with the respective check in check_unshare_flags which
> allow CLONE_NEWTIME for unshare().
> 
> [...]

Thanks for fixing this. Applied, thanks! If someone has already picked this
up/prefers to carry it just let me know and I'll happily drop it,

[1/2] fork: allow CLONE_NEWTIME in clone3 flags
      commit: a402f1e35313fc7ce2ca60f543c4402c2c7c3544
[2/2] selftests/clone3: test clone3 with CLONE_NEWTIME
      commit: 515bddf0ec4155cbd666d72daf5bd68c8b7cd987

Thanks!
Christian
  

Patch

diff --git a/kernel/fork.c b/kernel/fork.c
index f68954d05e89..d8cda4c6de6c 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2936,7 +2936,7 @@  static bool clone3_args_valid(struct kernel_clone_args *kargs)
 	 * - make the CLONE_DETACHED bit reusable for clone3
 	 * - make the CSIGNAL bits reusable for clone3
 	 */
-	if (kargs->flags & (CLONE_DETACHED | CSIGNAL))
+	if (kargs->flags & (CLONE_DETACHED | (CSIGNAL & (~CLONE_NEWTIME))))
 		return false;
 
 	if ((kargs->flags & (CLONE_SIGHAND | CLONE_CLEAR_SIGHAND)) ==