From nobody Mon Oct 02 22:31:18 2023 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 4RzwfH0j5rz4wYy7; Mon, 2 Oct 2023 22:31: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 4RzwfG75btz3Vdb; Mon, 2 Oct 2023 22:31:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696285879; 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=LwT7gABVdN8aT4oyJEVnaqHOz1ZzBi6lZuSViiSTBGo=; b=fsHirPz+B+ZtuYaSxqm/m991H0AuuX1u2Jk7BQHxbs9cWnr+OSI6/rTpeixtESgi6YfPlT u/RjzZdXXQuzxCx4HYcf2iWcovgkAmoEZuukfzOt9Yb4A0voSIhXSbJBVMCN0P8SzN8Po9 gI2pwVHftEiM1RBnBzYISnCw8auTE9v7rW5/02IbDtcLMTXjAVVDndG8LVr2vRguulsEtn uw+XW9W5V6WgG/HIUJt1jW5rvhN/PTPVWVOnW34g+IZaC1qcRfK+QyLLyEbm4+sEQkwoHr /QYwjqDj76yxIhS6Fcvk2cyi7noeRpYXUQNFHTacxyafy7e9QPH+Wu7qsTsMwQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696285879; a=rsa-sha256; cv=none; b=sKf3bwb6q1EIKx+7C1qZFBUTrTRkcJgd9XArXBHtWfN+0jm0yPyDfM9vJOfuRo5lobSRjR fiSTfIrP5LeVHI84Xf30pQ9aNoNUsp6x4tn7sgKNc1rPI183bQq8T0py6dpWXMHC3o9fAz tyo0134pCehDBVP64ucSjUEcDlKvE+TEvoZAjSdtNEFj0JMRflxUt1aUJryuLDB/Vn6E4c ieQuw+mNOYa7bMKumODpJdEJnjQAAlo7BG1VXHTjJodIdTf1dVrBj+Wdu1EDL1DoPEO/ox vaCOytCTNJh/6mWQJsl3FRPxqX3hR2ZK9H7kD7NrPwKIn+/PuBk8UDOzcS6uIQ== 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=1696285879; 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=LwT7gABVdN8aT4oyJEVnaqHOz1ZzBi6lZuSViiSTBGo=; b=MjGbBu/Z0OkJ2gkByvrUERpguypMUldQDIpnKlJemaagu9582J+kShEFRUQ7LcGIcxQqV9 YnCrCzzp7UwH0njHHMq7rp9v4aM82iPPMkRvx4d3JI2M/3sSqsBjFOTtWftgk+HWI/81PN AmwiyMfkxbibljx+7RdLvduTOi5tCoGys/QGld4GExIIiXCZqjODHhVDmajN2Q6eolsR/y nBLMIj6aCqIomvT6fGhDESUAmvqk4AmjQYXxKWLvXeIq/0lrT4Ln+TY73X3lIJxiWVHyhm yHWy/5iDjpexv3KpInkKCqvFEanvgcGC2+rCwW9XnlNL6Rb2JrxPg3teLoPeQw== 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 4RzwfG5zqVzVm5; Mon, 2 Oct 2023 22:31:18 +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 392MVIS7098966; Mon, 2 Oct 2023 22:31:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 392MVIap098963; Mon, 2 Oct 2023 22:31:18 GMT (envelope-from git) Date: Mon, 2 Oct 2023 22:31:18 GMT Message-Id: <202310022231.392MVIap098963@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 39024a891469 - main - syscalls: fix missing SIGSYS for several ENOSYS errors 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 39024a89146902ca9aba250130b828ad9aced99d Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=39024a89146902ca9aba250130b828ad9aced99d commit 39024a89146902ca9aba250130b828ad9aced99d Author: Konstantin Belousov AuthorDate: 2023-09-25 16:32:52 +0000 Commit: Konstantin Belousov CommitDate: 2023-10-02 22:30:52 +0000 syscalls: fix missing SIGSYS for several ENOSYS errors In particular, when the syscall number is too large, or when syscall is dynamic. For that, add nosys_sysent structure to pass fake sysent to syscall top code. Reviewed by: dchagin, markj Discussed with: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41976 --- sys/amd64/amd64/trap.c | 2 +- sys/amd64/ia32/ia32_syscall.c | 2 +- sys/arm/arm/syscall.c | 2 +- sys/arm64/arm64/elf32_machdep.c | 2 +- sys/arm64/arm64/trap.c | 2 +- sys/arm64/linux/linux_sysvec.c | 2 +- sys/i386/i386/trap.c | 2 +- sys/i386/linux/linux_sysvec.c | 2 +- sys/kern/kern_sig.c | 3 ++- sys/kern/kern_syscalls.c | 25 +++++++++++++++++++------ sys/kern/subr_syscall.c | 3 ++- sys/powerpc/powerpc/trap.c | 2 +- sys/riscv/riscv/trap.c | 2 +- sys/sys/sysent.h | 3 ++- 14 files changed, 35 insertions(+), 19 deletions(-) diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c index ef38c0789636..8114105655f8 100644 --- a/sys/amd64/amd64/trap.c +++ b/sys/amd64/amd64/trap.c @@ -1033,7 +1033,7 @@ cpu_fetch_syscall_args_fallback(struct thread *td, struct syscall_args *sa) } if (sa->code >= p->p_sysent->sv_size) - sa->callp = &p->p_sysent->sv_table[0]; + sa->callp = &nosys_sysent; else sa->callp = &p->p_sysent->sv_table[sa->code]; diff --git a/sys/amd64/ia32/ia32_syscall.c b/sys/amd64/ia32/ia32_syscall.c index 3fb905ab9e0a..c61587a93d1f 100644 --- a/sys/amd64/ia32/ia32_syscall.c +++ b/sys/amd64/ia32/ia32_syscall.c @@ -183,7 +183,7 @@ ia32_fetch_syscall_args(struct thread *td) params += sizeof(quad_t); } if (sa->code >= p->p_sysent->sv_size) - sa->callp = &p->p_sysent->sv_table[0]; + sa->callp = &nosys_sysent; else sa->callp = &p->p_sysent->sv_table[sa->code]; diff --git a/sys/arm/arm/syscall.c b/sys/arm/arm/syscall.c index 57644c023646..c440f501e834 100644 --- a/sys/arm/arm/syscall.c +++ b/sys/arm/arm/syscall.c @@ -118,7 +118,7 @@ cpu_fetch_syscall_args(struct thread *td) } p = td->td_proc; if (sa->code >= p->p_sysent->sv_size) - sa->callp = &p->p_sysent->sv_table[0]; + sa->callp = &nosys_sysent; else sa->callp = &p->p_sysent->sv_table[sa->code]; error = 0; diff --git a/sys/arm64/arm64/elf32_machdep.c b/sys/arm64/arm64/elf32_machdep.c index e1fcb533a8cc..9cf1b2e11f8b 100644 --- a/sys/arm64/arm64/elf32_machdep.c +++ b/sys/arm64/arm64/elf32_machdep.c @@ -191,7 +191,7 @@ freebsd32_fetch_syscall_args(struct thread *td) } if (sa->code >= p->p_sysent->sv_size) - sa->callp = &p->p_sysent->sv_table[0]; + sa->callp = &nosys_sysent; else sa->callp = &p->p_sysent->sv_table[sa->code]; diff --git a/sys/arm64/arm64/trap.c b/sys/arm64/arm64/trap.c index c3221e9faf9f..2dda8cfc4c20 100644 --- a/sys/arm64/arm64/trap.c +++ b/sys/arm64/arm64/trap.c @@ -151,7 +151,7 @@ cpu_fetch_syscall_args(struct thread *td) } if (__predict_false(sa->code >= p->p_sysent->sv_size)) - sa->callp = &p->p_sysent->sv_table[0]; + sa->callp = &nosys_sysent; else sa->callp = &p->p_sysent->sv_table[sa->code]; diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c index 5f9252accb5f..19dd5866ba50 100644 --- a/sys/arm64/linux/linux_sysvec.c +++ b/sys/arm64/linux/linux_sysvec.c @@ -123,7 +123,7 @@ linux_fetch_syscall_args(struct thread *td) sa->original_code = sa->code; /* LINUXTODO: generic syscall? */ if (sa->code >= p->p_sysent->sv_size) - sa->callp = &p->p_sysent->sv_table[0]; + sa->callp = &nosys_sysent; else sa->callp = &p->p_sysent->sv_table[sa->code]; diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index 172317aead29..d0ee2b30a3ce 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -1113,7 +1113,7 @@ cpu_fetch_syscall_args(struct thread *td) } if (sa->code >= p->p_sysent->sv_size) - sa->callp = &p->p_sysent->sv_table[0]; + sa->callp = &nosys_sysent; else sa->callp = &p->p_sysent->sv_table[sa->code]; diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index fe3e3f743620..a3d445951cce 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -522,7 +522,7 @@ linux_fetch_syscall_args(struct thread *td) if (sa->code >= p->p_sysent->sv_size) /* nosys */ - sa->callp = &p->p_sysent->sv_table[p->p_sysent->sv_size - 1]; + sa->callp = &nosys_sysent; else sa->callp = &p->p_sysent->sv_table[sa->code]; diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 964ad2398bd9..8d0d2903bac0 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -2686,7 +2686,8 @@ ptrace_syscallreq(struct thread *td, struct proc *p, audited = AUDIT_SYSCALL_ENTER(sc, td) != 0; if (!sy_thr_static) { - error = syscall_thread_enter(td, se); + error = syscall_thread_enter(td, &se); + sy_thr_static = (se->sy_thrcnt & SY_THR_STATIC) != 0; if (error != 0) { tsr->ts_ret.sr_error = error; return; diff --git a/sys/kern/kern_syscalls.c b/sys/kern/kern_syscalls.c index 78014a36b34b..f923211cb6c8 100644 --- a/sys/kern/kern_syscalls.c +++ b/sys/kern/kern_syscalls.c @@ -61,6 +61,17 @@ lkmressys(struct thread *td, struct nosys_args *args) return (nosys(td, args)); } +struct sysent nosys_sysent = { + .sy_call = (sy_call_t *)nosys, + .sy_systrace_args_func = NULL, + .sy_narg = 0, + .sy_flags = SYF_CAPENABLED, + .sy_auevent = AUE_NULL, + .sy_entry = 0, /* DTRACE_IDNONE */ + .sy_return = 0, + .sy_thrcnt = SY_THR_STATIC, +}; + static void syscall_thread_drain(struct sysent *se) { @@ -78,19 +89,21 @@ syscall_thread_drain(struct sysent *se) } int -syscall_thread_enter(struct thread *td, struct sysent *se) +syscall_thread_enter(struct thread *td, struct sysent **se) { uint32_t cnt, oldcnt; - KASSERT((se->sy_thrcnt & SY_THR_STATIC) == 0, + KASSERT(((*se)->sy_thrcnt & SY_THR_STATIC) == 0, ("%s: not a static syscall", __func__)); do { - oldcnt = se->sy_thrcnt; - if ((oldcnt & (SY_THR_DRAINING | SY_THR_ABSENT)) != 0) - return (ENOSYS); + oldcnt = (*se)->sy_thrcnt; + if ((oldcnt & (SY_THR_DRAINING | SY_THR_ABSENT)) != 0) { + *se = &nosys_sysent; + return (0); + } cnt = oldcnt + SY_THR_INCR; - } while (atomic_cmpset_acq_32(&se->sy_thrcnt, oldcnt, cnt) == 0); + } while (atomic_cmpset_acq_32(&(*se)->sy_thrcnt, oldcnt, cnt) == 0); return (0); } diff --git a/sys/kern/subr_syscall.c b/sys/kern/subr_syscall.c index c0262a1b1010..ff13672501b2 100644 --- a/sys/kern/subr_syscall.c +++ b/sys/kern/subr_syscall.c @@ -144,7 +144,8 @@ syscallenter(struct thread *td) AUDIT_SYSCALL_ENTER(sa->code, td) || !sy_thr_static)) { if (!sy_thr_static) { - error = syscall_thread_enter(td, se); + error = syscall_thread_enter(td, &se); + sy_thr_static = (se->sy_thrcnt & SY_THR_STATIC) != 0; if (error != 0) { td->td_errno = error; goto retval; diff --git a/sys/powerpc/powerpc/trap.c b/sys/powerpc/powerpc/trap.c index 1527e813647d..7f1a267f5cf2 100644 --- a/sys/powerpc/powerpc/trap.c +++ b/sys/powerpc/powerpc/trap.c @@ -694,7 +694,7 @@ cpu_fetch_syscall_args(struct thread *td) } if (sa->code >= p->p_sysent->sv_size) - sa->callp = &p->p_sysent->sv_table[0]; + sa->callp = &nosys_sysent; else sa->callp = &p->p_sysent->sv_table[sa->code]; diff --git a/sys/riscv/riscv/trap.c b/sys/riscv/riscv/trap.c index b855fcc4163a..ea48b02ba29b 100644 --- a/sys/riscv/riscv/trap.c +++ b/sys/riscv/riscv/trap.c @@ -115,7 +115,7 @@ cpu_fetch_syscall_args(struct thread *td) } if (__predict_false(sa->code >= p->p_sysent->sv_size)) - sa->callp = &p->p_sysent->sv_table[0]; + sa->callp = &nosys_sysent; else sa->callp = &p->p_sysent->sv_table[sa->code]; diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h index 3f52848af982..3ef6b06c5545 100644 --- a/sys/sys/sysent.h +++ b/sys/sys/sysent.h @@ -191,6 +191,7 @@ struct sysentvec { extern struct sysentvec aout_sysvec; extern struct sysent sysent[]; extern const char *syscallnames[]; +extern struct sysent nosys_sysent; struct nosys_args { register_t dummy; @@ -319,7 +320,7 @@ struct nosys_args; int lkmnosys(struct thread *, struct nosys_args *); int lkmressys(struct thread *, struct nosys_args *); -int syscall_thread_enter(struct thread *td, struct sysent *se); +int syscall_thread_enter(struct thread *td, struct sysent **se); void syscall_thread_exit(struct thread *td, struct sysent *se); int shared_page_alloc(int size, int align);