From nobody Tue Jan 02 00:37:19 2024 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 4T3v7g3gTSz55yjG; Tue, 2 Jan 2024 00:37:19 +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 4T3v7g1q21z3Hf8; Tue, 2 Jan 2024 00:37:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704155839; 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=qFQ9yubEKQLwZNlD5wvYzdJ9hTmznopCwanzmqmVMbg=; b=lBneQ6tvGa1k87Sqf+c5MDT/J88tHSBh62f9ib3Q2+At/9Z8ucSARR24tCJzmHDNefdPlr zsFCKrMzsUw3939Bspo09XFBhN+lmSbSy4id5kHCjuLY3pVMLBTczHdKywmWead5Z6Yjr8 l/HZKa6KtsV7n/Mvl3TsfFX7Eah0Jtx21ZPr28qw2+Mh85UsdGU89CPaK6Qu7DPJfnWHMF NcbjHWct8ZDv5itLgZCtUjJamCj6P7oox5y/iQW06G9/XgUN7/M2Uv8FyrHWNSapx2+OOb BuYKUdqtQauU7M9HcexpwITvHjQhWXnMenHx03WiMafDUehXeKaFkjWynSNIkg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704155839; a=rsa-sha256; cv=none; b=n5doLFV8lbYOK+RpEJ1WL+59DPqUU8UT9dOhY7aFkx/bth9myyIwreu7e5C88DEJvDEGrP ius39ZAVju81HESd2Enr1i70sFgYzMYSvQsQwlBI69rpteMq53c6t0b50Kn8dmInwXNj7U 3RD5RoPBVnczrAmR3qkiJIfhaMKr6dn2h1F/ELf4AeXsLph/PJbrEt7H2jhraxwqHOAAwp Iv010zRZ0MQR1yLZ2sr8zbUSqYED14+1ELvNLvLLpwAdzDRoxdSiWFLR/V53h/VcUnLyU/ iAQ2fgP3xQQhCjMtZJvOIjs4qIoRbSZ1YFuRWUnz4NUe4sanzXA4WYq6OxUTgQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704155839; 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=qFQ9yubEKQLwZNlD5wvYzdJ9hTmznopCwanzmqmVMbg=; b=MJMf4q3O/YcWn0irXzrPM8VI4riou2eGUZK9gmMIR4/XGuxd0lHbzXng8pgvCqqmSJ3oYh CHWQqHZp6gX0Q4iOUBqvh39N/ZA5xR1WUwKAPBHUrwq9H9Q6AfGtuOEcmMS0lS+suhpeXw 6FXpLUOI657IIdK3/5Dr+YfxYmMDSvpQGOnDXO478oeua/i6pqsZtgBjgR1ywTYgXh5bkI Xcfg/PljPHBe40HbR3zFcBQev/FRG69pEIh0AeqaMghVfCBnfyNqYNTww9RjG4lnS1Omvr rtX5sC3MDwzZM21sHrHSMX70w7U54iU5/E2SXbpVVY+/JGt+TUkihT+4xcPSCA== 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 4T3v7g0wYHzfQF; Tue, 2 Jan 2024 00:37:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4020bJWT085232; Tue, 2 Jan 2024 00:37:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4020bJdr085229; Tue, 2 Jan 2024 00:37:19 GMT (envelope-from git) Date: Tue, 2 Jan 2024 00:37:19 GMT Message-Id: <202401020037.4020bJdr085229@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: f9c3b1be3677 - stable/14 - thread: Add a return value to cpu_set_upcall() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f9c3b1be3677e9bf770fc037a35b7df56f1bb032 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f9c3b1be3677e9bf770fc037a35b7df56f1bb032 commit f9c3b1be3677e9bf770fc037a35b7df56f1bb032 Author: Mark Johnston AuthorDate: 2023-12-26 01:39:39 +0000 Commit: Mark Johnston CommitDate: 2024-01-02 00:29:48 +0000 thread: Add a return value to cpu_set_upcall() Some implementations copy data to userspace, an operation which can in principle fail. In preparation for adding a __result_use_check annotation to copyin() and related functions, let implementations of cpu_set_upcall() return an error, and check for errors when copying data to user memory. Reviewed by: kib, jhb MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D43100 (cherry picked from commit 7b68fb5ab2a276ccd081cc1a43cebf0fb315e952) --- sys/amd64/amd64/vm_machdep.c | 19 ++++++++++++------- sys/arm/arm/vm_machdep.c | 3 ++- sys/arm64/arm64/vm_machdep.c | 3 ++- sys/i386/i386/vm_machdep.c | 11 +++++++---- sys/kern/kern_thr.c | 5 ++++- sys/powerpc/powerpc/exec_machdep.c | 3 ++- sys/riscv/riscv/vm_machdep.c | 3 ++- sys/sys/proc.h | 2 +- 8 files changed, 32 insertions(+), 17 deletions(-) diff --git a/sys/amd64/amd64/vm_machdep.c b/sys/amd64/amd64/vm_machdep.c index 27bf3f67ca25..9e77ac7af2d7 100644 --- a/sys/amd64/amd64/vm_machdep.c +++ b/sys/amd64/amd64/vm_machdep.c @@ -613,7 +613,7 @@ cpu_copy_thread(struct thread *td, struct thread *td0) * Set that machine state for performing an upcall that starts * the entry function with the given argument. */ -void +int cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, stack_t *stack) { @@ -639,13 +639,15 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, td->td_frame->tf_rip = (uintptr_t)entry; /* Return address sentinel value to stop stack unwinding. */ - suword32((void *)td->td_frame->tf_rsp, 0); + if (suword32((void *)td->td_frame->tf_rsp, 0) != 0) + return (EFAULT); /* Pass the argument to the entry point. */ - suword32((void *)(td->td_frame->tf_rsp + sizeof(int32_t)), - (uint32_t)(uintptr_t)arg); - - return; + if (suword32( + (void *)(td->td_frame->tf_rsp + sizeof(int32_t)), + (uint32_t)(uintptr_t)arg) != 0) + return (EFAULT); + return (0); } #endif @@ -665,10 +667,13 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, td->td_frame->tf_flags = TF_HASSEGS; /* Return address sentinel value to stop stack unwinding. */ - suword((void *)td->td_frame->tf_rsp, 0); + if (suword((void *)td->td_frame->tf_rsp, 0) != 0) + return (EFAULT); /* Pass the argument to the entry point. */ td->td_frame->tf_rdi = (register_t)arg; + + return (0); } int diff --git a/sys/arm/arm/vm_machdep.c b/sys/arm/arm/vm_machdep.c index b7c08cd4e97f..3fd39d3f7a97 100644 --- a/sys/arm/arm/vm_machdep.c +++ b/sys/arm/arm/vm_machdep.c @@ -227,7 +227,7 @@ cpu_copy_thread(struct thread *td, struct thread *td0) * Set that machine state for performing an upcall that starts * the entry function with the given argument. */ -void +int cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, stack_t *stack) { @@ -239,6 +239,7 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, tf->tf_spsr = PSR_USR32_MODE; if ((register_t)entry & 1) tf->tf_spsr |= PSR_T; + return (0); } int diff --git a/sys/arm64/arm64/vm_machdep.c b/sys/arm64/arm64/vm_machdep.c index 5e45b45dc320..66528b8487e0 100644 --- a/sys/arm64/arm64/vm_machdep.c +++ b/sys/arm64/arm64/vm_machdep.c @@ -206,7 +206,7 @@ cpu_copy_thread(struct thread *td, struct thread *td0) * Set that machine state for performing an upcall that starts * the entry function with the given argument. */ -void +int cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, stack_t *stack) { @@ -223,6 +223,7 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, tf->tf_x[0] = (register_t)arg; tf->tf_x[29] = 0; tf->tf_lr = 0; + return (0); } int diff --git a/sys/i386/i386/vm_machdep.c b/sys/i386/i386/vm_machdep.c index 8e0917eed1c2..e05791967fba 100644 --- a/sys/i386/i386/vm_machdep.c +++ b/sys/i386/i386/vm_machdep.c @@ -488,7 +488,7 @@ cpu_copy_thread(struct thread *td, struct thread *td0) * Set that machine state for performing an upcall that starts * the entry function with the given argument. */ -void +int cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, stack_t *stack) { @@ -512,11 +512,14 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, td->td_frame->tf_eip = (int)entry; /* Return address sentinel value to stop stack unwinding. */ - suword((void *)td->td_frame->tf_esp, 0); + if (suword((void *)td->td_frame->tf_esp, 0) != 0) + return (EFAULT); /* Pass the argument to the entry point. */ - suword((void *)(td->td_frame->tf_esp + sizeof(void *)), - (int)arg); + if (suword((void *)(td->td_frame->tf_esp + sizeof(void *)), + (int)arg) != 0) + return (EFAULT); + return (0); } int diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c index d75305ea5020..544479fc9f13 100644 --- a/sys/kern/kern_thr.c +++ b/sys/kern/kern_thr.c @@ -146,6 +146,7 @@ thr_new_initthr(struct thread *td, void *thunk) { stack_t stack; struct thr_param *param; + int error; /* * Here we copy out tid to two places, one for child and one @@ -165,7 +166,9 @@ thr_new_initthr(struct thread *td, void *thunk) stack.ss_sp = param->stack_base; stack.ss_size = param->stack_size; /* Set upcall address to user thread entry function. */ - cpu_set_upcall(td, param->start_func, param->arg, &stack); + error = cpu_set_upcall(td, param->start_func, param->arg, &stack); + if (error != 0) + return (error); /* Setup user TLS address and TLS pointer register. */ return (cpu_set_user_tls(td, param->tls_base)); } diff --git a/sys/powerpc/powerpc/exec_machdep.c b/sys/powerpc/powerpc/exec_machdep.c index 0b1751a76454..0c10115c4e25 100644 --- a/sys/powerpc/powerpc/exec_machdep.c +++ b/sys/powerpc/powerpc/exec_machdep.c @@ -1149,7 +1149,7 @@ cpu_copy_thread(struct thread *td, struct thread *td0) td->td_md.md_saved_msr = psl_kernset; } -void +int cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, stack_t *stack) { @@ -1201,6 +1201,7 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, td->td_retval[0] = (register_t)entry; td->td_retval[1] = 0; + return (0); } static int diff --git a/sys/riscv/riscv/vm_machdep.c b/sys/riscv/riscv/vm_machdep.c index 58acf5df9e14..043093960edf 100644 --- a/sys/riscv/riscv/vm_machdep.c +++ b/sys/riscv/riscv/vm_machdep.c @@ -179,7 +179,7 @@ cpu_copy_thread(struct thread *td, struct thread *td0) * Set that machine state for performing an upcall that starts * the entry function with the given argument. */ -void +int cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, stack_t *stack) { @@ -190,6 +190,7 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, tf->tf_sp = STACKALIGN((uintptr_t)stack->ss_sp + stack->ss_size); tf->tf_sepc = (register_t)entry; tf->tf_a[0] = (register_t)arg; + return (0); } int diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 0b91b2a1a0b5..6d6a4e8624c5 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1248,7 +1248,7 @@ void cpu_fork_kthread_handler(struct thread *, void (*)(void *), void *); int cpu_procctl(struct thread *td, int idtype, id_t id, int com, void *data); void cpu_set_syscall_retval(struct thread *, int); -void cpu_set_upcall(struct thread *, void (*)(void *), void *, +int cpu_set_upcall(struct thread *, void (*)(void *), void *, stack_t *); int cpu_set_user_tls(struct thread *, void *tls_base); void cpu_thread_alloc(struct thread *);