From nobody Fri Jun 17 19:38:02 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E89E385AE5D; Fri, 17 Jun 2022 19:38:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LPq8C2bF9z3Q63; Fri, 17 Jun 2022 19:38:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494683; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LFNiwzW07zf0uXQ++PCoWpo3ZpbFs9I9fL8dKfmob1Q=; b=MQ1D8Rn4zYSBmznBeRmLx9e5K23X56nIokqqlv70frJ5MpTVeAC8GPe+ksQYyDnK69z7kY uPBVO9IBpujIavMfB3GzUJewIEJsyaY3LTM4vbnZ1O/WARX2pXgNv39cr3rrxpLwKZDMak /G9NYg4kM3O8XbKOjVxU0nF3FowdBOu11h62wnJuP4BPMleYRl08nPyWoiX8bxSdqtl+yM p9yVzFiCLmYzYH7FFk2zo+FxgyCOBepB14/lWty4KxHJBy7zQ8UX8x8e14DA01puQlJ+fN UgUCIN2DbSajbe8oJgXs1RKEQe/vXO/r0w4tdptE107Yn9Jqf7kQrlGogqpluA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3FB2B25AC2; Fri, 17 Jun 2022 19:38:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25HJc2Di014146; Fri, 17 Jun 2022 19:38:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJc2sL014145; Fri, 17 Jun 2022 19:38:02 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:38:02 GMT Message-Id: <202206171938.25HJc2sL014145@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: b27e30232927 - stable/13 - linux(4): Implement clone3 system call. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b27e30232927dffd86a4498aa418f798a19cc3b0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494683; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LFNiwzW07zf0uXQ++PCoWpo3ZpbFs9I9fL8dKfmob1Q=; b=LjtvSpxL5nBF6kW0deGvx18CQ7sFYmzvfuOBcPxBUrpfFuHa6xaeAIsvFGMcX0DDNQ7SuN Gtx3DZJ6f8ZotUGkS0T4KqfZxtMzgS02ZcrQ3Sm2CnRX4GGKnax9KuuaU4WayZ+sfj/5Ch TFlwA1jbJXNn+L+Sm9JPECZ3DZ1oSRBhtYer6guDZ1Lg53Ku7cB0/uYqevI7iUSoSJ2YqY syvYyGOBP5KRaFi4kSGjhuLfTMM8QbTfe00bljaHs3xtw3a0KJeKUxo+z2q5Yq9XhusqQK dFFCHyVbttwASCajNimyMeqyz4Niq3xjH2oBcSZP6tk65jI8oadZuBxk+0IOIw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494683; a=rsa-sha256; cv=none; b=e9UIK6vpX3tXMuIxuNA/vjFI4bpgj6ESgHNDVvmuOFG9x7c5nc2ghCssI+unVSdoMcmcQY VT1GthX33Hz+e0sQQOxrY52KmRQqVIacUxKRPa5adl8pEZ+DxpBMV5FxpPTJp5ssZSO/kq mDAesVBF0qWr/tyQx34qMXyv72SO6iTaCfh+qEMhwyte21QsyGISnSdlPVXl5Iqec+sroo XkGx6fH8xzx9JewUZhySJfxPp642gGTibUJItfxcZa5Uf3BqPasNHaPCUoWYO9KIEmFIG3 vFx1PiV8VwS92XNKEF2ns2Nxszwtng/vdiGyTWwr9FDp36c2e4tPQ5P9h5V67w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=b27e30232927dffd86a4498aa418f798a19cc3b0 commit b27e30232927dffd86a4498aa418f798a19cc3b0 Author: Dmitry Chagin AuthorDate: 2021-08-12 08:49:36 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:33:30 +0000 linux(4): Implement clone3 system call. clone3 system call is used by glibc-2.34. Differential revision: https://reviews.freebsd.org/D31475 MFC after: 2 weeks (cherry picked from commit 17913b0b6b707568d63559255820f3212cd31cdf) --- sys/amd64/linux/syscalls.master | 5 ++- sys/amd64/linux32/syscalls.master | 5 ++- sys/arm64/linux/syscalls.master | 5 ++- sys/compat/linux/linux_fork.c | 80 +++++++++++++++++++++++++++++++++++++++ sys/compat/linux/linux_fork.h | 9 +++++ sys/compat/linux/linux_misc.h | 2 + sys/i386/linux/syscalls.master | 5 ++- 7 files changed, 107 insertions(+), 4 deletions(-) diff --git a/sys/amd64/linux/syscalls.master b/sys/amd64/linux/syscalls.master index cdf663ce2e06..d3ebedbfed01 100644 --- a/sys/amd64/linux/syscalls.master +++ b/sys/amd64/linux/syscalls.master @@ -2082,7 +2082,10 @@ int linux_pidfd_open(void); } 435 AUE_NULL STD { - int linux_clone3(void); + int linux_clone3( + struct l_user_clone_args *uargs, + l_size_t usize + ); } 436 AUE_NULL STD { int linux_close_range(void); diff --git a/sys/amd64/linux32/syscalls.master b/sys/amd64/linux32/syscalls.master index ff7ab7f98ca8..9d55fb1ade48 100644 --- a/sys/amd64/linux32/syscalls.master +++ b/sys/amd64/linux32/syscalls.master @@ -2484,7 +2484,10 @@ int linux_pidfd_open(void); } 435 AUE_NULL STD { - int linux_clone3(void); + int linux_clone3( + struct l_user_clone_args *uargs, + l_size_t usize + ); } 436 AUE_NULL STD { int linux_close_range(void); diff --git a/sys/arm64/linux/syscalls.master b/sys/arm64/linux/syscalls.master index 6e163cc3360d..a6bb14a5ed63 100644 --- a/sys/arm64/linux/syscalls.master +++ b/sys/arm64/linux/syscalls.master @@ -1731,7 +1731,10 @@ int linux_pidfd_open(void); } 435 AUE_NULL STD { - int linux_clone3(void); + int linux_clone3( + struct l_user_clone_args *uargs, + l_size_t usize + ); } 436 AUE_NULL STD { int linux_close_range(void); diff --git a/sys/compat/linux/linux_fork.c b/sys/compat/linux/linux_fork.c index 97f5b7d89de4..db3e9e1ea27b 100644 --- a/sys/compat/linux/linux_fork.c +++ b/sys/compat/linux/linux_fork.c @@ -377,6 +377,86 @@ linux_clone(struct thread *td, struct linux_clone_args *args) return (linux_clone_proc(td, &ca)); } + +static int +linux_clone3_args_valid(struct l_user_clone_args *uca) +{ + + /* Verify that no unknown flags are passed along. */ + if ((uca->flags & ~(LINUX_CLONE_LEGACY_FLAGS | + LINUX_CLONE_CLEAR_SIGHAND | LINUX_CLONE_INTO_CGROUP)) != 0) + return (EINVAL); + if ((uca->flags & (LINUX_CLONE_DETACHED | LINUX_CSIGNAL)) != 0) + return (EINVAL); + + if ((uca->flags & (LINUX_CLONE_SIGHAND | LINUX_CLONE_CLEAR_SIGHAND)) == + (LINUX_CLONE_SIGHAND | LINUX_CLONE_CLEAR_SIGHAND)) + return (EINVAL); + if ((uca->flags & (LINUX_CLONE_THREAD | LINUX_CLONE_PARENT)) != 0 && + uca->exit_signal != 0) + return (EINVAL); + + /* We don't support set_tid, only validate input. */ + if (uca->set_tid_size > LINUX_MAX_PID_NS_LEVEL) + return (EINVAL); + if (uca->set_tid == 0 && uca->set_tid_size > 0) + return (EINVAL); + if (uca->set_tid != 0 && uca->set_tid_size == 0) + return (EINVAL); + + if (uca->stack == 0 && uca->stack_size > 0) + return (EINVAL); + if (uca->stack != 0 && uca->stack_size == 0) + return (EINVAL); + + return (0); +} + +int +linux_clone3(struct thread *td, struct linux_clone3_args *args) +{ + struct l_user_clone_args *uca; + struct l_clone_args *ca; + size_t size; + int error; + + if (args->usize > PAGE_SIZE) + return (E2BIG); + if (args->usize < LINUX_CLONE_ARGS_SIZE_VER0) + return (EINVAL); + + /* + * usize can be less than size of struct clone_args, to avoid using + * of uninitialized data of struct clone_args, allocate at least + * sizeof(struct clone_args) storage and zero it. + */ + size = max(args->usize, sizeof(*uca)); + uca = malloc(size, M_LINUX, M_WAITOK | M_ZERO); + error = copyin(args->uargs, uca, args->usize); + if (error != 0) + goto out; + error = linux_clone3_args_valid(uca); + if (error != 0) + goto out; + ca = malloc(sizeof(*ca), M_LINUX, M_WAITOK | M_ZERO); + ca->flags = uca->flags; + ca->child_tid = PTRIN(uca->child_tid); + ca->parent_tid = PTRIN(uca->parent_tid); + ca->exit_signal = uca->exit_signal; + ca->stack = uca->stack + uca->stack_size; + ca->stack_size = uca->stack_size; + ca->tls = uca->tls; + + if ((ca->flags & LINUX_CLONE_THREAD) != 0) + error = linux_clone_thread(td, ca); + else + error = linux_clone_proc(td, ca); + free(ca, M_LINUX); +out: + free(uca, M_LINUX); + return (error); +} + int linux_exit(struct thread *td, struct linux_exit_args *args) { diff --git a/sys/compat/linux/linux_fork.h b/sys/compat/linux/linux_fork.h index 04dfb8ac8a70..fa7b39544450 100644 --- a/sys/compat/linux/linux_fork.h +++ b/sys/compat/linux/linux_fork.h @@ -53,6 +53,13 @@ #define LINUX_CLONE_NEWNET 0x40000000 #define LINUX_CLONE_IO 0x80000000 +/* Flags for the clone3() syscall. */ +#define LINUX_CLONE_CLEAR_SIGHAND 0x100000000ULL +#define LINUX_CLONE_INTO_CGROUP 0x200000000ULL +#define LINUX_CLONE_NEWTIME 0x00000080 + +#define LINUX_CLONE_LEGACY_FLAGS 0xffffffffULL + #define LINUX_CSIGNAL 0x000000ff /* @@ -85,6 +92,8 @@ struct l_clone_args { l_ulong tls; }; +#define LINUX_CLONE_ARGS_SIZE_VER0 64 + int linux_set_upcall(struct thread *, register_t); int linux_set_cloned_tls(struct thread *, void *); void linux_thread_detach(struct thread *); diff --git a/sys/compat/linux/linux_misc.h b/sys/compat/linux/linux_misc.h index 80f6b8a58e81..ceb140d3da75 100644 --- a/sys/compat/linux/linux_misc.h +++ b/sys/compat/linux/linux_misc.h @@ -33,6 +33,8 @@ #include +#define LINUX_MAX_PID_NS_LEVEL 32 + /* bits per mask */ #define LINUX_NFDBITS sizeof(l_fd_mask) * 8 diff --git a/sys/i386/linux/syscalls.master b/sys/i386/linux/syscalls.master index aecb852e21c7..27bbca9e65e7 100644 --- a/sys/i386/linux/syscalls.master +++ b/sys/i386/linux/syscalls.master @@ -2502,7 +2502,10 @@ int linux_pidfd_open(void); } 435 AUE_NULL STD { - int linux_clone3(void); + int linux_clone3( + struct l_user_clone_args *uargs, + l_size_t usize + ); } 436 AUE_NULL STD { int linux_close_range(void);