From owner-svn-src-head@freebsd.org Fri Jan 31 19:00:48 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D331B1E973E; Fri, 31 Jan 2020 19:00:48 +0000 (UTC) (envelope-from jhb@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 488RPr4zsCz45Pb; Fri, 31 Jan 2020 19:00:48 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A655C1A8D2; Fri, 31 Jan 2020 19:00:48 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00VJ0mFJ033166; Fri, 31 Jan 2020 19:00:48 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00VJ0mZ5033165; Fri, 31 Jan 2020 19:00:48 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <202001311900.00VJ0mZ5033165@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Fri, 31 Jan 2020 19:00:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357344 - head/sys/riscv/riscv X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: head/sys/riscv/riscv X-SVN-Commit-Revision: 357344 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Jan 2020 19:00:48 -0000 Author: jhb Date: Fri Jan 31 19:00:48 2020 New Revision: 357344 URL: https://svnweb.freebsd.org/changeset/base/357344 Log: Add stricter checks on user changes to SSTATUS. Rather than trying to blacklist which bits userland can't write to via sigreturn() or setcontext(), only permit changes to whitelisted bits. - Permit arbitrary writes to bits in the user-writable USTATUS register that shadows SSTATUS. - Ignore changes in write-only bits maintained by the CPU. - Ignore the user-supplied value of the FS field used to track floating point state and instead set it to a value matching the actions taken by set_fpcontext(). Discussed with: mhorne MFC after: 2 weeks Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D23338 Modified: head/sys/riscv/riscv/machdep.c Modified: head/sys/riscv/riscv/machdep.c ============================================================================== --- head/sys/riscv/riscv/machdep.c Fri Jan 31 18:55:21 2020 (r357343) +++ head/sys/riscv/riscv/machdep.c Fri Jan 31 19:00:48 2020 (r357344) @@ -368,11 +368,16 @@ set_mcontext(struct thread *td, mcontext_t *mcp) tf = td->td_frame; /* - * Make sure the processor mode has not been tampered with and - * interrupts have not been disabled. - * Supervisor interrupts in user mode are always enabled. + * Permit changes to the USTATUS bits of SSTATUS. + * + * Ignore writes to read-only bits (SD, XS). + * + * Ignore writes to the FS field as set_fpcontext() will set + * it explicitly. */ - if ((mcp->mc_gpregs.gp_sstatus & SSTATUS_SPP) != 0) + if (((mcp->mc_gpregs.gp_sstatus ^ tf->tf_sstatus) & + ~(SSTATUS_SD | SSTATUS_XS_MASK | SSTATUS_FS_MASK | SSTATUS_UPIE | + SSTATUS_UIE)) != 0) return (EINVAL); memcpy(tf->tf_t, mcp->mc_gpregs.gp_t, sizeof(tf->tf_t)); @@ -426,7 +431,12 @@ set_fpcontext(struct thread *td, mcontext_t *mcp) { #ifdef FPE struct pcb *curpcb; +#endif + td->td_frame->tf_sstatus &= ~SSTATUS_FS_MASK; + td->td_frame->tf_sstatus |= SSTATUS_FS_OFF; + +#ifdef FPE critical_enter(); if ((mcp->mc_flags & _MC_FP_VALID) != 0) { @@ -436,6 +446,7 @@ set_fpcontext(struct thread *td, mcontext_t *mcp) sizeof(mcp->mc_fpregs)); curpcb->pcb_fcsr = mcp->mc_fpregs.fp_fcsr; curpcb->pcb_fpflags = mcp->mc_fpregs.fp_flags & PCB_FP_USERMASK; + td->td_frame->tf_sstatus |= SSTATUS_FS_CLEAN; } critical_exit();