Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp521598pxa; Wed, 19 Aug 2020 07:51:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCkdshQ18td7inmT0PS0HtlSYObt682bnLI3ZOEfj8ZJO9pEKbySj9kV/HdfyBtdQwYlOU X-Received: by 2002:a17:906:29d5:: with SMTP id y21mr24478848eje.131.1597848696500; Wed, 19 Aug 2020 07:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597848696; cv=none; d=google.com; s=arc-20160816; b=hYnuPQjMpmb8i0keoCTUpYjjStkYJ5YNUYmxBOyHdHuQU+vB9vYpJg3mg0O3g8dZqg 0rPnwbuBlArmCwrO2c7viU2Iij+2naO8SQ8aOuy0l/jiquBoDVui5qj08XjPNOT9+af1 A2C+II21AsQ0C751l+8ARq4Gi/Zeq1MX9WV47EubItZjunise1giuv56aekyfEoGVJqY QzcxPuVLSQ0B0icf9AR7ZwgvEj2Vv/Tv4bCNl26e6vn0KveIRA+gYCYJHKBbmjsehQd7 cw9s08MM7of0X2YHhM396hfKKE3HU+oNwcdlMxULwPHutdWYBTLRTlOW4Nj1JuGQtSMY UPlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=zfgqjDL3wMsihT1LjZEPze5peMiaUv389dpHBHHb2Ck=; b=aLafI7snLroOYnmuyVIAkY5DRZ5/w/QpQxF0ISd7PUohMSEPws5QlXr9rJA/3pftQ/ KI38cmHaomGISF6wRmswbtADPWDrzHzuFTgbtnLzlG/T6+eSDidJ06u7K7hqgtspEIF1 CODGYro9WgoyYGq3gP9XwUn4a/h9EqPP505VeyM5ev5xq/+LLrq85MjsOeSAFeyvNMBg pFA3vJjz+AxAiL4mj6azz/NpacU8qaS1yR8uyydgU70RgfeH0kF8L9Fw5ZL93a3zdWb2 p7QvFmRvODOZlc1liSkiaLBd0Mjb6+bY/9xeHimwNXR48/LmIzo5/SF4htVYFXoikntL UqmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="aNIPYl/q"; 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=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b12si15578729ejg.578.2020.08.19.07.51.10; Wed, 19 Aug 2020 07:51:36 -0700 (PDT) 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=@alien8.de header.s=dkim header.b="aNIPYl/q"; 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=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727975AbgHSOu3 (ORCPT + 99 others); Wed, 19 Aug 2020 10:50:29 -0400 Received: from mail.skyhub.de ([5.9.137.197]:54200 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726578AbgHSOu2 (ORCPT ); Wed, 19 Aug 2020 10:50:28 -0400 Received: from zn.tnic (p200300ec2f26be00329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ec:2f26:be00:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 86A521EC0246; Wed, 19 Aug 2020 16:50:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1597848626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=zfgqjDL3wMsihT1LjZEPze5peMiaUv389dpHBHHb2Ck=; b=aNIPYl/qzmq4gH8+HVGo2Yw2Gn2Cj0g2T9qd+BdQdGmCRz/htPyuPwOZdDQEbPKcr94XyD MseUctl91d5+wwbfUW4NMxJnj6RgD3bukByiLxuWTSFTagdpRAaiwG8CNBxVB+FqmArcDw h+Ww29CL4umedhwSY/V+qQXS485sa9o= Date: Wed, 19 Aug 2020 16:50:21 +0200 From: Borislav Petkov To: Chris Down Cc: linux-kernel@vger.kernel.org, Jakub Kicinski , Andrew Morton , kernel-team@fb.com, sean.j.christopherson@intel.com, tony.luck@intel.com, torvalds@linux-foundation.org, x86@kernel.org Subject: Re: [PATCH 1/2] x86: Prevent userspace MSR access from dominating the console Message-ID: <20200819144914.GB19351@zn.tnic> References: <8ebda3f90bca583f12969892e0f0e97166c4d492.1597677395.git.chris@chrisdown.name> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <8ebda3f90bca583f12969892e0f0e97166c4d492.1597677395.git.chris@chrisdown.name> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 17, 2020 at 04:24:29PM +0100, Chris Down wrote: > Applications which manipulate MSRs from userspace often do so > infrequently, and all at once. As such, the default printk ratelimit > architecture supplied by pr_err_ratelimited doesn't do enough to prevent > kmsg becoming completely overwhelmed with their messages and pushing > other salient information out of the circular buffer. In one case, I saw > over 80% of kmsg being filled with these messages, and the default kmsg > buffer being completely filled less than 5 minutes after boot(!). > > This change makes things much less aggressive, while still achieving the s/This change makes/Make/ > original goal of fiter_write(). Operators will still get warnings that > MSRs are being manipulated from userspace, but they won't have other > also potentially useful messages pushed out of the kmsg buffer. > > Of course, one can boot with `allow_writes=1` to avoid these messages at > all, but that then has the downfall that one doesn't get _any_ > notification at all about these problems in the first place, and so is > much less likely to forget to fix it. One might rather it was less > binary: it was still logged, just less often, so that application > developers _do_ have the incentive to improve their current methods, > without us having to push other useful stuff out of the kmsg buffer. > > This one example isn't the point, of course: I'm sure there are plenty > of other non-ideal-but-pragmatic cases where people are writing to MSRs > from userspace right now, and it will take time for those people to find > other solutions. > > Overall, this patch keeps the intent of the original patch, while Avoid having "This patch" or "This commit" in the commit message. It is tautologically useless. Also, do $ git grep 'This patch' Documentation/process for more details. > mitigating its sometimes heavy effects on kmsg composition. > > Signed-off-by: Chris Down > Cc: Borislav Petkov > Cc: Jakub Kicinski > --- > arch/x86/kernel/msr.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c > index 49dcfb85e773..3babb0e58b0e 100644 > --- a/arch/x86/kernel/msr.c > +++ b/arch/x86/kernel/msr.c > @@ -80,18 +80,27 @@ static ssize_t msr_read(struct file *file, char __user *buf, > > static int filter_write(u32 reg) > { > + /* > + * Banging MSRs usually happens all at once, and can easily saturate Yeah we have a lot of non-native speakers so "Banging" might be confusing - please formulate less colloquial. > + * kmsg. Only allow 1 MSR message every 30 seconds. > + * > + * We could be smarter here and do it per-MSR, or whatever, but it would Please avoid the "we" in text as it is ambiguous - try formulating passively like your commit message. > + * certainly be more complex, and this is enough at least to stop > + * completely saturating the ring buffer. > + */ > + static DEFINE_RATELIMIT_STATE(fw_rs, 30 * HZ, 1); > + > switch (allow_writes) { > case MSR_WRITES_ON: return 0; > case MSR_WRITES_OFF: return -EPERM; > default: break; > } > > - if (reg == MSR_IA32_ENERGY_PERF_BIAS) > + if (!__ratelimit(&fw_rs) || reg == MSR_IA32_ENERGY_PERF_BIAS) > return 0; Let's keep those two tests separate: if (!__ratelimit(&fw_rs)) return 0; if (reg == MSR_IA32_ENERGY_PERF_BIAS) return 0; > > - pr_err_ratelimited("Write to unrecognized MSR 0x%x by %s\n" > - "Please report to x86@kernel.org\n", > - reg, current->comm); > + pr_err("Write to unrecognized MSR 0x%x by %s\n" > + "Please report to x86@kernel.org\n", reg, current->comm); > > return 0; > } > -- > 2.28.0 > -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette