Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4482371ybx; Mon, 4 Nov 2019 14:09:59 -0800 (PST) X-Google-Smtp-Source: APXvYqx0RwNufrqAPCb2n+oEcGmEt3zP4ILCXrPJlPHFWc8sKc4nBI1cOwC8kCQOFbEK4Bxz9Toj X-Received: by 2002:a50:959a:: with SMTP id w26mr31969205eda.214.1572905399580; Mon, 04 Nov 2019 14:09:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905399; cv=none; d=google.com; s=arc-20160816; b=swdjlFU57G1uFOmIkhkkMVkrwGUkdWLVzrdPt1Yr6f6OZl0SacLcgTHTPw1BFSKw/x QjDrpq3IaQ/3LoG7MOEpCUtwuC/du8JEvumRDE7J/nrYYmv7j3RoonAADcDb6EgSdG23 8neg37bB3rPF9uHCx/zDHkunIYtvddQiFMJc5vbMKP3vmCbIoAvMKg0mQtZn47HP5dTp yCwheGq5RVmKWkrDipbeKerBYyOAAZWyp2pKa2G8EvrNwgndz+H/4q3LC3ODqKTkDBeb G16bQ/qHmtbkT+Jr99l1VSdoF1IH9Ff+rw2caxBos/xLKN7EmKYMY7s680JahOJhHqZl 56Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3q76C8eCJ4jDmEsS/s6kSQWK82efjjMtvwyaRcYkaEs=; b=KUVaNwA+FlV8vduNY0SKuxbN+dek9CHP61bqE8dW5x9I0Rek8bdUZxqGClvniZVcyr UB1akWKwu7c0aML6XtHBPhnuc56XU6IDm37KgGMmGi7CkDqJpZpTSsxFkxuG8MDMCs3a Cnbj+YmHl1S2ersaV6gQ9MP0KKHmqI27vlDb/Iwhj91WryrgSkftso9QVbfWwuurrkWx Uti5adgTepz/lzsc7jCGQD7Lh7WYhz9cHf5Qw+cNWAIvpWjJzTW9aj2DmIMq8H6sD+p6 sC2a1cqym26AJCGhrzS7kcLeW4keajw16fbqNginjpQEdLsap7crSIMWmEqZ5Cq/MbvY VREQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RwxgJ9TY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s39si8427756edm.338.2019.11.04.14.09.27; Mon, 04 Nov 2019 14:09:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RwxgJ9TY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389948AbfKDWGW (ORCPT + 99 others); Mon, 4 Nov 2019 17:06:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:38088 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389924AbfKDWGS (ORCPT ); Mon, 4 Nov 2019 17:06:18 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BC23620650; Mon, 4 Nov 2019 22:06:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905178; bh=rRwePNsI59KK4BLYIYjRoGLaieBH2kehmZF/8DC2UNM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RwxgJ9TYiEUwjCkkmNMcCSnUkGX9BMs0WZbsvkD23qvkZAzaos4PNd+t/KsGG2BIV NsgJLboC0G5AdxufLBzXXH4XpBvUm2cWXNs3/2RRhOZ7+9MF1QjzvDI87ncwQRMMPL mLmsAVGZU45vLgXONiT/DsaIvRgbtFYGgQ2BxSUQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Chen , Christoph Hellwig , Paul Walmsley , Sasha Levin Subject: [PATCH 5.3 056/163] riscv: Correct the handling of unexpected ebreak in do_trap_break() Date: Mon, 4 Nov 2019 22:44:06 +0100 Message-Id: <20191104212144.176069663@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincent Chen [ Upstream commit 8bb0daef64e5a92db63ad1d3bbf9e280a7b3612a ] For the kernel space, all ebreak instructions are determined at compile time because the kernel space debugging module is currently unsupported. Hence, it should be treated as a bug if an ebreak instruction which does not belong to BUG_TRAP_TYPE_WARN or BUG_TRAP_TYPE_BUG is executed in kernel space. For the userspace, debugging module or user problem may intentionally insert an ebreak instruction to trigger a SIGTRAP signal. To approach the above two situations, the do_trap_break() will direct the BUG_TRAP_TYPE_NONE ebreak exception issued in kernel space to die() and will send a SIGTRAP to the trapped process only when the ebreak is in userspace. Signed-off-by: Vincent Chen Reviewed-by: Christoph Hellwig [paul.walmsley@sifive.com: fixed checkpatch issue] Signed-off-by: Paul Walmsley Signed-off-by: Sasha Levin --- arch/riscv/kernel/traps.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 82f42a55451eb..93742df9067fb 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -130,8 +130,6 @@ asmlinkage void do_trap_break(struct pt_regs *regs) type = report_bug(regs->sepc, regs); switch (type) { #ifdef CONFIG_GENERIC_BUG - case BUG_TRAP_TYPE_NONE: - break; case BUG_TRAP_TYPE_WARN: regs->sepc += get_break_insn_length(regs->sepc); return; @@ -140,8 +138,10 @@ asmlinkage void do_trap_break(struct pt_regs *regs) default: die(regs, "Kernel BUG"); } + } else { + force_sig_fault(SIGTRAP, TRAP_BRKPT, + (void __user *)(regs->sepc)); } - force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)(regs->sepc)); } #ifdef CONFIG_GENERIC_BUG -- 2.20.1