From nobody Tue Nov 23 23:48:54 2021 X-Original-To: dev-commits-src-branches@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 38F9D189136F; Tue, 23 Nov 2021 23:48:55 +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 4HzLSk6QJRz4mxC; Tue, 23 Nov 2021 23:48:54 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 BC8491FC13; Tue, 23 Nov 2021 23:48:54 +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 1ANNmsk3077849; Tue, 23 Nov 2021 23:48:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ANNmsxr077848; Tue, 23 Nov 2021 23:48:54 GMT (envelope-from git) Date: Tue, 23 Nov 2021 23:48:54 GMT Message-Id: <202111232348.1ANNmsxr077848@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: e1d8f7fc1d94 - stable/13 - riscv: Clear SUM in SSTATUS for supervisor mode exceptions. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e1d8f7fc1d9457c5db18d1639f1fdfb244476106 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637711334; 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=tyrtDF/UAqvytzOj/qf7s7arHb62GHzE/wJEWhqtC4Y=; b=WCC7EyC17ZRZcokkdB709FERKRO30QvhorFOOcjbZ+sJE/KfQuIkR5wkJLzuGeMxXz1VHe ucDB3mQ00/Zrs7e1tUS0yvZLf/r7NLH0zyJ1tzXNgyMKL0/ybxP4zsI/NnL707X5na06dG c+lj2sJOrGBIALZfIPvcKYCiRRMGeBrZf8kDZxcrCaYV/PSaOIYtPRqG+hbHNeDlYINztg cCQNX6uox3MK5K8Hl6VTr0fymsZJL4M3IPEeTmgYFUFBRzQBetS/Lt5MAi2J6Rg2yf+SyP dLPj20c6A4Kd0qbwwingW7qb6RY0ZmSGidDmikdDpu0KAgEuI3fRDsTZ9ay5GA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637711334; a=rsa-sha256; cv=none; b=Qxvblscnp256n1OzaWVrkR8nyccUxLTWKYQi8U0CKzZU9To+Nm2VcaObljxmCblTa4r8W/ JvQ3CNsRHjN/2DhfJJ6G3Hsk05x9W9Y0OfUEgoud7a5IXJZOWdwqzCZ5ykWqYGpwSE1Vkm NuTspGDIccM+BWgbPyP1KrVIQVyB8o+AQEE2WX1aV+++Zlr0os4tEdDR7riGySw3VwY2wX JJNnyg+C9mIa2OuILPlArEisil8+BLMv6Ufh5b4bYEEbg1QY5SAvUOzRgATo0HdE9Wr3ev jhHieuMjswHjsWBT3d9Xv8f76um6aiSw0XM1HGZAqKZkt9mhpjXI+rLkmNUG3g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=e1d8f7fc1d9457c5db18d1639f1fdfb244476106 commit e1d8f7fc1d9457c5db18d1639f1fdfb244476106 Author: John Baldwin AuthorDate: 2021-04-21 20:57:04 +0000 Commit: John Baldwin CommitDate: 2021-11-23 23:47:52 +0000 riscv: Clear SUM in SSTATUS for supervisor mode exceptions. Previously, a page fault taken during copyin/out and related functions would run the entire fault handler while permitting direct access to user addresses. This could also leak across context switches (e.g. if the page fault handler was preempted by an interrupt or slept for disk I/O). To fix, clear SUM in assembly after saving the original version of SSTATUS in the supervisor mode trapframe. Reviewed by: mhorne, jrtc27 Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D29763 (cherry picked from commit 753bcca440a4d2c95f48536b586131b84c0bb87e) --- sys/riscv/riscv/exception.S | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sys/riscv/riscv/exception.S b/sys/riscv/riscv/exception.S index 50134980c7af..abd1307174f1 100644 --- a/sys/riscv/riscv/exception.S +++ b/sys/riscv/riscv/exception.S @@ -104,6 +104,11 @@ __FBSDID("$FreeBSD$"); sd t0, (TF_SEPC)(sp) csrr t0, sstatus sd t0, (TF_SSTATUS)(sp) +.if \mode == 1 + /* Disable user address access for supervisor mode exceptions. */ + li t0, SSTATUS_SUM + csrc sstatus, t0 +.endif csrr t0, stval sd t0, (TF_STVAL)(sp) csrr t0, scause