Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1592772pxb; Thu, 4 Feb 2021 17:56:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpl1lw0MyGdeiobWB6iysbac3Z41ZBNWr0sTsM6LgCq1WYIEccB7x7VjTg09Qm/ylipMuq X-Received: by 2002:a17:906:4dc5:: with SMTP id f5mr1813630ejw.11.1612490177688; Thu, 04 Feb 2021 17:56:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612490177; cv=none; d=google.com; s=arc-20160816; b=OXcbePOamR8bbuZxkWC1aF0qjBqeNnpoLuO3TtfoaxHbvSOTwaaVBPt+n2M87wa0dU A5dgL2bzMvkS0tbaao+DU0FcIYRKQIkPXQCFscuxwn7jy9a94QGrgrHaKVO5r80Tv65+ GD7Fqcim3EjviP39D0atW4o3iX0M+BsgO6ov1BjpFxedHz4aLcr93O5zu/P/mLVF3Mbh 6AGSqcnIjXnp+sdgDETgZkQklK2+csHedyyglFobx9d1p1MqQaUPTy9QjCxzlx7XfWU3 cdsDpnztau8e5enR+rhb1nBBIUwc1biYSP23FK6v0HcEnZbZQhm3grFq80AbNjqwNfhy 57ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=FvMLKiy+10wDnQIsFAXsgEHH0jtWBGZ0/dP1UJW7qkA=; b=09s1Dc4g2+OkHmoKzmZJ/xWqzBXVmD3vX0fe9ZwkTQ7SjBatygDv3xyXIgfxd5kvpl kC7xc/RAQCk3HRRSfVMHnjDar8eQFn5fKiFdKtH1scj2SWP9vWToVizKXSpgTeQ/EqUp B+iI40cyek3ZrPLNT/jxga05WvwKghnDf4yfpRQl5eJrhpBVhXcdAQXU6RVRC58f0dTh MoIoQCHEHJxetfVVFQBUYiukzESAD4OdK4DTVofI95MGKgJ+uF989YCpcizoIRTn/YXI 6eqFHWGo+O6ubE83wBzbF+gc3m/90wO/kp9rnZ1xvzArW/pgwEB5ILpH73mmUGwk6/Fx usqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb13si5399951edb.8.2021.02.04.17.55.53; Thu, 04 Feb 2021 17:56:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231700AbhBEALB (ORCPT + 99 others); Thu, 4 Feb 2021 19:11:01 -0500 Received: from mga07.intel.com ([134.134.136.100]:33647 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231567AbhBEAK6 (ORCPT ); Thu, 4 Feb 2021 19:10:58 -0500 IronPort-SDR: dcLHhzwVxGlhA6eizk0mzgYgWHL+jGH4p6IPB6bUnlIVtrBr4+bx13YGCPN5JE42rVzSM8BOWL J7JQ2BqAmDkQ== X-IronPort-AV: E=McAfee;i="6000,8403,9885"; a="245422593" X-IronPort-AV: E=Sophos;i="5.81,153,1610438400"; d="scan'208";a="245422593" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2021 16:10:16 -0800 IronPort-SDR: FyGhBUUZHeP4fcvvfhWFvX9OftF/q5PlQTD0LPuXDJkP8OJ1TrRk/5I7SgFZh+TPiGSD+cMsTm 9ZdEZg3R6jTw== X-IronPort-AV: E=Sophos;i="5.81,153,1610438400"; d="scan'208";a="434168522" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.209.100.6]) ([10.209.100.6]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2021 16:10:14 -0800 Subject: Re: [PATCH v19 06/25] x86/cet: Add control-protection fault handler To: Kees Cook Cc: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu , Michael Kerrisk References: <20210203225547.32221-1-yu-cheng.yu@intel.com> <20210203225547.32221-7-yu-cheng.yu@intel.com> <202102041201.C2B93F8D8A@keescook> From: "Yu, Yu-cheng" Message-ID: <518c6ce4-1e6e-ef8d-ba55-fb35a828b874@intel.com> Date: Thu, 4 Feb 2021 16:10:13 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <202102041201.C2B93F8D8A@keescook> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/4/2021 12:09 PM, Kees Cook wrote: > On Wed, Feb 03, 2021 at 02:55:28PM -0800, Yu-cheng Yu wrote: [...] >> diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c >> index 7f5aec758f0e..f5354c35df32 100644 >> --- a/arch/x86/kernel/traps.c >> +++ b/arch/x86/kernel/traps.c >> @@ -606,6 +606,66 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) >> cond_local_irq_disable(regs); >> } >> >> +#ifdef CONFIG_X86_CET >> +static const char * const control_protection_err[] = { >> + "unknown", >> + "near-ret", >> + "far-ret/iret", >> + "endbranch", >> + "rstorssp", >> + "setssbsy", >> +}; >> + >> +/* >> + * When a control protection exception occurs, send a signal to the responsible >> + * application. Currently, control protection is only enabled for user mode. >> + * This exception should not come from kernel mode. >> + */ >> +DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) >> +{ >> + static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL, >> + DEFAULT_RATELIMIT_BURST); >> + struct task_struct *tsk; >> + >> + if (!user_mode(regs)) { >> + pr_emerg("PANIC: unexpected kernel control protection fault\n"); >> + die("kernel control protection fault", regs, error_code); >> + panic("Machine halted."); >> + } >> + >> + cond_local_irq_enable(regs); >> + >> + if (!boot_cpu_has(X86_FEATURE_CET)) >> + WARN_ONCE(1, "Control protection fault with CET support disabled\n"); >> + >> + tsk = current; >> + tsk->thread.error_code = error_code; >> + tsk->thread.trap_nr = X86_TRAP_CP; >> + >> + if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) && >> + __ratelimit(&rs)) { >> + unsigned int max_err; >> + unsigned long ssp; >> + >> + max_err = ARRAY_SIZE(control_protection_err) - 1; >> + if (error_code < 0 || error_code > max_err) >> + error_code = 0; > > Do you want to mask the error_code here before printing its value? > >> + >> + rdmsrl(MSR_IA32_PL3_SSP, ssp); >> + pr_emerg("%s[%d] control protection ip:%lx sp:%lx ssp:%lx error:%lx(%s)", >> + tsk->comm, task_pid_nr(tsk), >> + regs->ip, regs->sp, ssp, error_code, >> + control_protection_err[error_code]); > > Instead, you could clamp error_code to ARRAY_SIZE(control_protection_err), > and add another "unknown" to the end of the strings: > > control_protection_err[ > array_index_nospec(error_code, > ARRAY_SIZE(control_protection_err))] > > Everything else looks good. > I will update it. Thanks! [...]