Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2891475rwb; Mon, 15 Aug 2022 13:26:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ZSEDnGrMvf/es40fTLiPtFTjceSqKmBM4CAtXGqfM0C8RaTpZeFznP0lPkmFUY9tiixhY X-Received: by 2002:a05:6402:1bc9:b0:43d:3903:11ee with SMTP id ch9-20020a0564021bc900b0043d390311eemr16126784edb.113.1660595161769; Mon, 15 Aug 2022 13:26:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660595161; cv=none; d=google.com; s=arc-20160816; b=WZEvI43IV3g45uyRdjWTPNt01GTCadNfdMAWauoZFaxf+cakDIuH2jIQKMpsR7wFBG P87B6/0TzqPHWAi9epvz5XNniQG/0E5XA2Ia70y0pXU0tLokYT/y9WfQiWAXNqiSKU3d h7aG6SXHJBI5EQ91DsGwTEFImHanaraPoxrZG9p+N5n75+0InrvbNNYRsXCs3b/EMpd7 mG+zNybB8eOAI3W+RypYMf28RlNALrxbWqLd/x4PqKtAjO2iC6PPUWB+Bjbvoytz2vGz ve9XVnJBfznywN5t4njfNMrWTHk1KxKKk+1AB7ygNg4S+r5++tlYkXmUFCV41tmJ3Kw4 Dwkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oqjPnVIhn0Oz+jgsOyqZCu+qHpSjZrL/FtCwr50ZRz4=; b=pQ4vpX4sfV0fiu24epUxrhZExlMod4O8D9tv6k8dUAmnWyWGrDGMaklXascfXWjEi5 +ShgLpQPrrABXC6ZsYhuLljrMQ/6iD3vNpbW4ZlQx8jwJDk2Fp14p6Hx+4i2RQTfdhjU umkA5pTs2Bm+lxvCqN8Ugf/Dp85AHOKYGEaRFl+SkW1CzeRICD+GbVw3B4jH2N2Fif0T 8lvQ6EHA7UVlZhwl/AFLrcKSSW44bKpmM9NEfbfIAmpmNuJJRobIeYR/3xJNbN9Y/4dq iHAX6YPJZis/WkEk5nijNkI7aJ8lORh84n5CAgDr65qczlY37eze3ojm1TATNM2Uqzth aS0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2hiM3OAw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs9-20020a170906dc8900b00730c36d50b3si9269768ejc.355.2022.08.15.13.25.33; Mon, 15 Aug 2022 13:26:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2hiM3OAw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346750AbiHOUXB (ORCPT + 99 others); Mon, 15 Aug 2022 16:23:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243704AbiHOUNR (ORCPT ); Mon, 15 Aug 2022 16:13:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18B628E440; Mon, 15 Aug 2022 11:59:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 665F4B8110A; Mon, 15 Aug 2022 18:59:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEE98C433D7; Mon, 15 Aug 2022 18:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589950; bh=PnK96AcJoNH02OrlMKcpheKhKI/ZKO5ifjdCqo9v2nI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2hiM3OAwNFzaHj3URPxpAl979YhbT3BBIibv3TiLBd00VyZSAE7+TgndvMnrtecKn bZ5jyGYzC/Rbn8UJe6/8oHdwq3r0aPTwwZP/9gnqZEUCCSgRetQZ8sUCPytF9xdZp5 /ZIW4L+cpedi+kCKegb0/e2adYXgf+XTE1NCPFWM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chen Lifu , Ben Dooks , Palmer Dabbelt Subject: [PATCH 5.18 0061/1095] riscv: lib: uaccess: fix CSR_STATUS SR_SUM bit Date: Mon, 15 Aug 2022 19:51:00 +0200 Message-Id: <20220815180432.031795086@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chen Lifu commit c08b4848f596fd95543197463b5162bd7bab2442 upstream. Since commit 5d8544e2d007 ("RISC-V: Generic library routines and assembly") and commit ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code"), if __clear_user and __copy_user return from an fixup branch, CSR_STATUS SR_SUM bit will be set, it is a vulnerability, so that S-mode memory accesses to pages that are accessible by U-mode will success. Disable S-mode access to U-mode memory should clear SR_SUM bit. Fixes: 5d8544e2d007 ("RISC-V: Generic library routines and assembly") Fixes: ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code") Signed-off-by: Chen Lifu Reviewed-by: Ben Dooks Link: https://lore.kernel.org/r/20220615014714.1650349-1-chenlifu@huawei.com Cc: stable@vger.kernel.org Signed-off-by: Palmer Dabbelt Signed-off-by: Greg Kroah-Hartman --- arch/riscv/lib/uaccess.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/riscv/lib/uaccess.S +++ b/arch/riscv/lib/uaccess.S @@ -175,7 +175,7 @@ ENTRY(__asm_copy_from_user) /* Exception fixup code */ 10: /* Disable access to user memory */ - csrs CSR_STATUS, t6 + csrc CSR_STATUS, t6 mv a0, t5 ret ENDPROC(__asm_copy_to_user) @@ -227,7 +227,7 @@ ENTRY(__clear_user) /* Exception fixup code */ 11: /* Disable access to user memory */ - csrs CSR_STATUS, t6 + csrc CSR_STATUS, t6 mv a0, a1 ret ENDPROC(__clear_user)