From patchwork Tue May 24 17:44:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1635126 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=vy4uKKtJ; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=Ik/QubS0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L71n93GHGz9sGS for ; Wed, 25 May 2022 03:45:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Pabnt5uJx3LQLG2eh1Abnl+FBolK7p+ezdzJ+YIZPog=; b=vy4uKKtJ4CznNQ 9XrpiUZE6HWXMQr4ySGk2CTyQM97LeFiqOkxpGX9AfbL0G472Li3Q2n7ocMeoE3lNxQpp3pZ/6ctU a4lpvSZR3S0sVXVPnYEL+L5NtJLIw5d6aMH3AFrxmeO4BXQx0Hd9cg+4CLn/6K1ik/oeEfoPb6d7Y GK3/X0+BPVeRwPW1/fKJ2brCLLvbTEQ7Mz4UW3s4hFTF8zORUXvmVkyHrblsLo5KH3g0aG6ZaHPtp rkAo9xppOS0OmJFxgwKP7Ydjh5R/O+gQHSaI/jK781rWoBiR0aYu1/xbK/yfTUctbtxu1EWAUDi7K D0gNct040071pJJsJM8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntYaT-008noF-2F; Tue, 24 May 2022 17:44:53 +0000 Received: from mail-m963.mail.126.com ([123.126.96.3]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntYaQ-008nn2-3N for opensbi@lists.infradead.org; Tue, 24 May 2022 17:44:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=DgXZq IYA63OkOgDFF8S/wAkky0OwA85Eowcf4K2w2XE=; b=Ik/QubS0fae4DTlT2Nl0l E67P6CYktcGyoRD+Zu8ziJXIAIk2v+ybuXU+AXJxMo/hAyYN2ZkM+ERnGDkf3B8F 6rSjEZWKf0gHWU8biRqFYkuMp2LGYeVfe5LMEojZcWsXoFoA06LH7hbQjk8OtxaZ GmG7evyYsc7E51lGqSKBLU= Received: from x390.lan (unknown [210.22.74.70]) by smtp8 (Coremail) with SMTP id NORpCgDHz3OJGY1i4V3fDQ--.39112S2; Wed, 25 May 2022 01:44:43 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: anup@brainfault.org, Xiang W Subject: [PATCH] lib: sbi: fix system_opcode_insn Date: Wed, 25 May 2022 01:44:32 +0800 Message-Id: <20220524174432.58212-1-wxjstz@126.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CM-TRANSID: NORpCgDHz3OJGY1i4V3fDQ--.39112S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xr4UKr1kur1kAF4kJF13Arb_yoWkWrX_uw 1xZF4UWrs5J3yS9ay5J3WfJrWUKr40gr4xZF47Wa9rGFy8X3yxZrWDGr1DXa48JF18Krsx CrnrXr4YqFy3WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sR_fM3tUUUUU== X-Originating-IP: [210.22.74.70] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5BQLOlpEDnqG1QABs5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220524_104450_568978_6247DB89 X-CRM114-Status: UNSURE ( 8.23 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: If the csr's operation comes from M mode, it should not be forwarded to low-privilege processing, this patch fixes this problem. Signed-off-by: Xiang W --- lib/sbi/sbi_illegal_insn.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [123.126.96.3 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If the csr's operation comes from M mode, it should not be forwarded to low-privilege processing, this patch fixes this problem. Signed-off-by: Xiang W --- lib/sbi/sbi_illegal_insn.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c index bfe7d61..deb77e6 100644 --- a/lib/sbi/sbi_illegal_insn.c +++ b/lib/sbi/sbi_illegal_insn.c @@ -37,12 +37,16 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs) int do_write, rs1_num = (insn >> 15) & 0x1f; ulong rs1_val = GET_RS1(insn, regs); int csr_num = (u32)insn >> 20; + ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; ulong csr_val, new_csr_val; /* TODO: Ensure that we got CSR read/write instruction */ - if (sbi_emulate_csr_read(csr_num, regs, &csr_val)) + if (sbi_emulate_csr_read(csr_num, regs, &csr_val)) { + if (prev_mode == PRV_M) + sbi_panic("%s: Unknown CSR %#x", __func__, csr_num); return truly_illegal_insn(insn, regs); + } do_write = rs1_num; switch (GET_RM(insn)) {