Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2172970pxb; Fri, 5 Feb 2021 10:38:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJx587DoQkc+VwSWjdRchUVz7bCW5KshSdpKT+gnOBWvQE4viuIB8KyniQK7swe4U/Of/tOF X-Received: by 2002:a17:906:8159:: with SMTP id z25mr5262674ejw.270.1612550331700; Fri, 05 Feb 2021 10:38:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612550331; cv=none; d=google.com; s=arc-20160816; b=JJ9BcYvbAM6MxJ4nwNYl2iC6jMB5w7iJjiOsrAoGPzarv0m5otPpBmMLroVDY4bf93 IrdZQ/2Bx91yjmD7CWmCDQEHlIboHbYHv8i2e0iiXwlj6DTn4qS3DfeV5hm+afeHNHAM 9Khc44W4YTlNEACJ2/+9Uy6RiqkzCLtH4HV7A4TewjjmsJNAbPXYLZkcIELIUGWzbJ6i CDaQji1q1vrfcXburrzJAPqW32x5dyrn5oDG0mgVu7nzL3+wGBnIvol71nib/JC3Fw9C kNlF0GV5hwQU7ngOqEJua90VZ0X/+VKgoOL06Ok6DJni4BYbp+33Xn8WYJ0+FT9uu0bn 5hhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/gKrMLsfGobXkiI6sjUHxc4o3Yi1e64+iFtcBHCUDvY=; b=cMNEvBxjRY0Wq50a4ydAWofQ39s6rk3mt95C55Ii74TEzvsdaJrkLVocGxUHlPhJk7 LBpGw1nxU2oPof+kAniCjOe2EgVVmo57PvM/l6aTeT7MF2/85W6d5vTEEyUDvAaSc4mh gGXYMDN1JVHL2ivtajUpQB/PBwEm7WqMId2/JKV6V224RjG4HaQqU5JkrE0ymY9gyncL 3kg+nLg5rN7KGVFRt6LC8z2sn3F8tR/kuYA2ssOAJVVuVYaro00850yzrozEzTiJjft9 jaAj2Mzgn1h2ZFI3F8x5CjB/4nh5tFY/cC8YszGGup9OezRnlx5doeKgn0msgyRQaY+6 f+fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AiVGW8Zf; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x23si5681017ejv.558.2021.02.05.10.38.26; Fri, 05 Feb 2021 10:38:51 -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; dkim=pass header.i=@chromium.org header.s=google header.b=AiVGW8Zf; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232852AbhBEQws (ORCPT + 99 others); Fri, 5 Feb 2021 11:52:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233542AbhBEQtV (ORCPT ); Fri, 5 Feb 2021 11:49:21 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A08C061A2A for ; Fri, 5 Feb 2021 10:29:12 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id o16so5141417pgg.5 for ; Fri, 05 Feb 2021 10:29:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/gKrMLsfGobXkiI6sjUHxc4o3Yi1e64+iFtcBHCUDvY=; b=AiVGW8ZfV6b/ee/LcCv+Op+DKesFAlTEGF/07NV2m2QST+5RqOHjwLrN8SOTlsHXpp GbTzYG/+F9OEtL49Tmfgwy9qbiHLoh6BzlrxNqzQJg8e0KXxzOS/DRVO7uq4SegSZl/A bNR0Obo6GjVDXaQLKqtbvrdxhjKO3vjvpLXwA= 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:message-id:references :mime-version:content-disposition:in-reply-to; bh=/gKrMLsfGobXkiI6sjUHxc4o3Yi1e64+iFtcBHCUDvY=; b=RIdu4afrezrh2P2roRsBY8yjlFRaXdAmpAsnZ1eIWEuUJc3+5O4caEUMDjGbF7Mnnl yhDWJQP2BqTDt3d0gvPeUmk96HHFZ2n4hhHi/sFkrsZY9b3iKa4YzNsWODrW7ku/8fGU QiagU3VSRSA8Wel9hE1pYonOEcc8z2se9hOWUtNUamzhuR38C2GBCqsYDZw/hgXzkv2t kF3b1acncoQ2euHDKQ2mb+WHh/Y99Uq4EbJeLguElfOT6pANy7mreKB+qigSti3AK/cQ oU1HRtjql0GRa+r7wdhbdgOHPbrUGXTX07Isr3dVidZVWgsbU1f5YCVV2Y/Q32l25EbW MTcg== X-Gm-Message-State: AOAM530aolJznneiCnOtOKscLUlfdE7rBIfIE3maghCsxmlMrogZWz08 K/TdhDfG4i2umiJmCG7hMjrhKA== X-Received: by 2002:a62:8c05:0:b029:1d8:7f36:bcd8 with SMTP id m5-20020a628c050000b02901d87f36bcd8mr2771317pfd.43.1612549752486; Fri, 05 Feb 2021 10:29:12 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id v3sm9644169pff.217.2021.02.05.10.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 10:29:11 -0800 (PST) Date: Fri, 5 Feb 2021 10:29:10 -0800 From: Kees Cook To: "Yu, Yu-cheng" Cc: Borislav Petkov , 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 , 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 Subject: Re: [PATCH v19 06/25] x86/cet: Add control-protection fault handler Message-ID: <202102051028.A10679FF@keescook> References: <20210203225547.32221-1-yu-cheng.yu@intel.com> <20210203225547.32221-7-yu-cheng.yu@intel.com> <20210205135927.GH17488@zn.tnic> <2d829cba-784e-635a-e0c5-a7b334fa9b40@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2d829cba-784e-635a-e0c5-a7b334fa9b40@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 05, 2021 at 10:00:21AM -0800, Yu, Yu-cheng wrote: > On 2/5/2021 5:59 AM, Borislav Petkov wrote: > > On Wed, Feb 03, 2021 at 02:55:28PM -0800, Yu-cheng Yu wrote: > > > +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)) { > > > > I can't find it written down anywhere why the ratelimiting is needed at > > all? > > > > The ratelimit here is only for #CP, and its rate is not counted together > with other types of faults. If a task gets here, it will exit. The only > condition the ratelimit will trigger is when multiple tasks hit #CP at once, > which is unlikely. Are you suggesting that we do not need the ratelimit > here? Since this is a potentially unprivileged-userspace-triggerable condition, I tend to prefer having a ratelimit. I don't feel _strongly_ about it, but I find it better to be defensive against log spamming (whether malicious or accidental). -- Kees Cook