From nobody Wed Aug 24 19:25:11 2022 X-Original-To: dev-commits-src-main@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 4MCbf00MW3z4ZffW; Wed, 24 Aug 2022 19:25:12 +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 4MCbdz6cQ1z3PKv; Wed, 24 Aug 2022 19:25:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661369112; 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=SbUIarVoDU97WyZaVVXtPU8a7Vb87VdQ8Z7wRoK1r8A=; b=CCn2fFgalu2xPcn16iCZHSZRJ3HfONzbPOjX3HmLDwh6Tqw0SQBGQ1rqymP+0kXJUHyj9J gjZCoK3l0cwgyHNd81DHpuLTuZLPP6sUgrgxTcbCuHwyIv9NqDlOKlgcs52gsUHXCAzH1n fUDH/xKpyFU+LMAzkVS2j99COz7Jgu6hTz2/kL4c99Ln8CpqQRsOZs533yS+pOw5PGpFcP X+lNocQhzb6k1Lnc76zP7JDXTqAXRHlTCvMIayaNK7mwepu7EePqtrsniaPf/bSKRUHyTe NyNSZjrNbj24KvNSNJX/btR3btVIc1ezBwuh0mI1bQJHF9PBpspXbsxgBerlAw== 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 4MCbdz5XBDzKgV; Wed, 24 Aug 2022 19:25:11 +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 27OJPBGD069149; Wed, 24 Aug 2022 19:25:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27OJPBkO069148; Wed, 24 Aug 2022 19:25:11 GMT (envelope-from git) Date: Wed, 24 Aug 2022 19:25:11 GMT Message-Id: <202208241925.27OJPBkO069148@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: dc4a2d1d0e83 - main - i386: do not allow userspace to set tf_trapno on sigreturn(2) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: dc4a2d1d0e838579f21d9d1fef8655f902f06ab2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661369112; 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=SbUIarVoDU97WyZaVVXtPU8a7Vb87VdQ8Z7wRoK1r8A=; b=Cn5ZTZoMqvyQFmawMwuF+eosTqtF+XzBEkj+UaiPuZizLLqzNhXyNeAKsPPKyuLr4PnYpP XWhQ21fqU6HMCT27ky3U0R3EWaBxuYF2AmZBShXZyzrJa4pI4lrx67QXc4Zddy1l3YrQB8 zUXRxf6SNMFLHdzvyizQToW4VRZMfWVrevOGD1So287N876+6oHAREGc8Tyf5eeN9tNk18 8ItJ1LhCwCqbbgQOzsJXGm9c+kyxEZUCWQOOxtrXC8S0eIMm8W5JQNmznwpAq7cdkpZ3UN QIJCMy/yjm6p1uyt6eIQObRUnjEKQjYiXCdzvUH67VwhypvRX4qbBJfNmrq8dg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661369112; a=rsa-sha256; cv=none; b=FX1eupgN4vjAz/hJ9lr2TFXwM//okoLF5wVgMYyQGK9/Y7Z3Cgt9yQAALpgVU94Khv2OHu 2CfwlsZI5rHM8qRtR3TtopIs8l1C/odaZ6Jc6abvWJO0Ox+YlGW9nPt9/pR6bwfnlWF/tI crtk9kXwBKwU3EqNJmxBXZX7cAfosYZ4q20Sh0lwpwbOyz42C2+FEoMMqveVZymgimy017 ZYyZMMavc8e/0QMSF70omP1/udg6X1EgWZuRbM03NUZ6oq1CNnPODMVwRU9A8TZEGWHPw3 KJBYNKlwcbFB+5CIgBvwAnFS0Lc69+8z8kCYp8xCDDZZQBEDkJiSPAWHQjwodw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=dc4a2d1d0e838579f21d9d1fef8655f902f06ab2 commit dc4a2d1d0e838579f21d9d1fef8655f902f06ab2 Author: Konstantin Belousov AuthorDate: 2022-08-19 01:26:37 +0000 Commit: Konstantin Belousov CommitDate: 2022-08-24 19:11:57 +0000 i386: do not allow userspace to set tf_trapno on sigreturn(2) tf_trapno is checked on return from interrupt/exception to determine if special handling is needed for switching address space. This is due to the possibility of NMI/MCHK/DBG to occur at arbitrary place in kernel, where both address space and stack used could be transient. Kernel saves current %cr3 in tf_err for such events, to restore on return. If user is able to set tf_trapno, it can trigger that special handling, and since tf_err is also user-controlled by sigreturn(2), the result is undefined. PR: 265889 Reported by: lwhsu Reviewed by: jhb Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36302 --- sys/i386/i386/exec_machdep.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/i386/i386/exec_machdep.c b/sys/i386/i386/exec_machdep.c index 29c06ff86ca8..45921193ec94 100644 --- a/sys/i386/i386/exec_machdep.c +++ b/sys/i386/i386/exec_machdep.c @@ -640,6 +640,7 @@ osigreturn(struct thread *td, struct osigreturn_args *uap) regs->tf_esp = scp->sc_sp; regs->tf_eip = scp->sc_pc; regs->tf_eflags = eflags; + regs->tf_trapno = T_RESERVED; #if defined(COMPAT_43) if (scp->sc_onstack & 1) @@ -739,6 +740,7 @@ freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap) bcopy(&ucp->uc_mcontext.mc_fs, regs, sizeof(*regs)); } + regs->tf_trapno = T_RESERVED; #if defined(COMPAT_43) if (ucp->uc_mcontext.mc_onstack & 1) @@ -873,6 +875,7 @@ sys_sigreturn(struct thread *td, struct sigreturn_args *uap) return (ret); bcopy(&ucp->uc_mcontext.mc_fs, regs, sizeof(*regs)); } + regs->tf_trapno = T_RESERVED; #if defined(COMPAT_43) if (ucp->uc_mcontext.mc_onstack & 1)