Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1236925ybp; Fri, 4 Oct 2019 11:30:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdchMSwhUJxptW2tyK6kjzq0CxqhzBMpaxgFOp1g7/kJIz0GwsjkLRFhd2qLzTzUcoBTlT X-Received: by 2002:a50:934c:: with SMTP id n12mr17083450eda.12.1570213804594; Fri, 04 Oct 2019 11:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570213804; cv=none; d=google.com; s=arc-20160816; b=df+Usahm5ql50CztfjIW8DxT+Eu8eDM0e+/40XFhAJxic+hx/Q7lXwSdsVBmBY4ub6 pQDcgwmEhXsJQFF/u/8/KSzXXysu53KN7J4lwi9aqo48QWB2pcqHkpXncvn6pUr/SPP3 ITqOUY+rfFEKduenC2sBISoyiYj7p5k6GHOR7IgOYwZIZ06FnCZzhHNC40GJa2goT/UL ilDkF3JkuQF7hM5ir8YVoed7MBynxEbLjaiuk9PBJVVHAbnXSfji14MvKZ4eCHHLEJRe 3IAYMqvnW2w4x31vkte5YV+98m5WvoVx+joF6QT2GZ6IrZa28BD0sxuKo+CTM2QbeTYm vK2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=Fk8zqqB0DvKX1W+/xtDSBwvEx3/VT0qa/q3V+wIeS+4=; b=e9mOdsOXfbqGw+or6pnkowwislbX1JITIwcKN6fiiSs6/wywk3S5o8AxEm1Wblt/hb /cflfeaFQpqw0ZxKgxfbIZ3Jh9nxp4gK6uJ6TWCdOK0U5CUu5hDegqJUupzbgJOT+hGc ec49fHmODolIY/FKWgYbBUQSy2+6hg7lDAWi3yCECAMq02+/GCED+kuX/4q/sjGNCIBm tETxP4D4Bk27p4EVMsI1fgYUOVjESokGnf+GcSTMZpc63lRFfKiL0ZBEQPN/62g1LlHO RHC4i0zEwBopb/xgQfB0clMZopACjMnwD4t/XHBeiXBwMnkESBYVNAcdOu99xrJhsjSS DKnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=BJQs4oC2; 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 y11si3301142eje.365.2019.10.04.11.29.40; Fri, 04 Oct 2019 11:30:04 -0700 (PDT) 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=@sifive.com header.s=google header.b=BJQs4oC2; 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 S1728356AbfJDS20 (ORCPT + 99 others); Fri, 4 Oct 2019 14:28:26 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:41122 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbfJDS2Z (ORCPT ); Fri, 4 Oct 2019 14:28:25 -0400 Received: by mail-io1-f67.google.com with SMTP id n26so15552350ioj.8 for ; Fri, 04 Oct 2019 11:28:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=Fk8zqqB0DvKX1W+/xtDSBwvEx3/VT0qa/q3V+wIeS+4=; b=BJQs4oC2tQPqVsTxzbgiivHy+/6Ct+K69IBnhkhd6z1mC5a/kwh5ihWtOSqVtGW2Rh blUYdZmYKWkDY6MGhgOrCfw57rt2fLAH18FjnBmEjb/YfqJe8NDjYYFkMkmz94/vbmuu hFhKvlmP2BavH2D5lmn2EspTFZJv0GlZuGVKpDLinWdiswK/OA7FEnR/ovhp2o31dD63 Nw3OPrQ3kgfG7SMfrlfBBG4m+nir+5gWG2MtMrb2v71HF0bEjVYGxaBCguxP2eKSwxnC u/E1MvSzBUK6TMTjMRe8BOrdPgBJMLk3Yf5JdfX6zYg3eUV1FZ621OcySCTZt1p4+DoM ekNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=Fk8zqqB0DvKX1W+/xtDSBwvEx3/VT0qa/q3V+wIeS+4=; b=umSRsE4FRUyEt8I1LnVlUYCoen6On0ryIClHJ28lsAopyFsI5d4gN3MzAZT5Bx7WBn tNlSidRRQ++mU3QKqmR7/9aoAjS4FS6zupgT92bpgGTHBkRf3s3fwGAcraT3Cv2bG5Y0 TIV+GcFcETPgELRjhmv2LTPtrQ0NXglQuKsmXZyRLZco17XNV+iCYCrUmtLnmHf2r2xZ kBcHKK7jjY7cwhTxKaz2yA06I7NuqWKM1Ru325t8PfZXHxIo97KSeZaOZwOLYjfTtLPx yiFDnvil2Jpuz6wSfpNFypvKQWU6oU5GdJNfMDVgMRWLllIsXVDHUcLPB4YZrNu4op0b aGjg== X-Gm-Message-State: APjAAAUd56D0yDdB/MdXwahu9Tu7blz6r7syWy1F1cZJcV3+63DfHKr3 IagSiUwnG8e1nP8iNdkEx6pJtnhy4CQ= X-Received: by 2002:a92:498c:: with SMTP id k12mr16757053ilg.88.1570213705113; Fri, 04 Oct 2019 11:28:25 -0700 (PDT) Received: from localhost (67-0-10-3.albq.qwest.net. [67.0.10.3]) by smtp.gmail.com with ESMTPSA id d18sm3912869ild.63.2019.10.04.11.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2019 11:28:24 -0700 (PDT) Date: Fri, 4 Oct 2019 11:28:23 -0700 (PDT) From: Paul Walmsley X-X-Sender: paulw@viisi.sifive.com To: Vincent Chen cc: linux-riscv@lists.infradead.org, palmer@sifive.com, aou@eecs.berkeley.edu, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/4] riscv: Correct the handling of unexpected ebreak in do_trap_break() In-Reply-To: <1569199517-5884-4-git-send-email-vincent.chen@sifive.com> Message-ID: References: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com> <1569199517-5884-4-git-send-email-vincent.chen@sifive.com> User-Agent: Alpine 2.21.9999 (DEB 301 2018-08-15) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 23 Sep 2019, Vincent Chen wrote: > 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 Thanks, queued the following for v5.4-rc. - Paul From: Vincent Chen Date: Mon, 23 Sep 2019 08:45:16 +0800 Subject: [PATCH] riscv: Correct the handling of unexpected ebreak in do_trap_break() 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 --- 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 82f42a55451e..93742df9067f 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.23.0