Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4333864ybg; Mon, 8 Jun 2020 05:23:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9CyoIKwNV0T7RkqkGcDexx0aKvPqkHcD4B/BuCmMlcPozBgWgCvUtJwqOuQAE/0AJBadk X-Received: by 2002:a17:906:7247:: with SMTP id n7mr10865421ejk.105.1591619028673; Mon, 08 Jun 2020 05:23:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591619028; cv=none; d=google.com; s=arc-20160816; b=lmARJpW5QvLkNTbIvqq/QgcdHHYXUNP2AaIMqmyKq4xPD/NhPK6O0veGK7MKLMucsH jhX/STA60B5XqY64yD9vA1wXnJ6PZzpCZhauoFYddYJMhgSIcF+t+ZStgRpq+xWY/Y29 Xc3sh3UXr142hGZXlP3zNGobcib5D2BH7OUTdoFH9wAfhIE31i7xIiVHEYbyZdciBBgQ 90VkWmqRDoLJXjj4dWfsz7EW2aBTc85m6UWPJiv3pxR97P6E+FhVxeXuIDR3iNUSMuOO p3gTMWLUqgnoBuuzrMQly7cSO5SNtJthDR5lynWiE7hMaXpaL4xRBLMiG3oq31ek7s6e KnIQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=gYYB9Ly3dQUty4Eb8fhA0MNTLhKQm7egUF4xyawly9U=; b=sYDrNkSL2lYX8CBQg8RtgaK4jhF2hC7y4SioU/2ePE3gZvaD3mSWq/Eh6iZPljDDPI gOAhdRaNnQJEUdFol7kH0yCCilA8wl5UXf/Rw8aXqmDU69ZnAeUq6jVzIQvXecoWQfAg 3IPhoU+YWz1DBE4St9HBLFeOV6qjd9y+PyN8HsW6aydCXtuE5dgTmAPRJMfuGB8NOIQ2 HNNfVq2YogO/noGOZ5cOHMRnJ+x5HXEBTqb9nly6rlnQXM8GTMj1TIH7FyeSOheoiH9/ PZ2P8CLykDgsPs5ymH9YtssLyt3nFmAmJ2jVHWxWaM6FKuGLGgvYlg3OnP1Qn1Zjp0Ym q54Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ALqSfBi4; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e2si8387845edy.212.2020.06.08.05.23.24; Mon, 08 Jun 2020 05:23:48 -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=@redhat.com header.s=mimecast20190719 header.b=ALqSfBi4; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729681AbgFHMVa (ORCPT + 99 others); Mon, 8 Jun 2020 08:21:30 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:38806 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729628AbgFHMV3 (ORCPT ); Mon, 8 Jun 2020 08:21:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591618887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=gYYB9Ly3dQUty4Eb8fhA0MNTLhKQm7egUF4xyawly9U=; b=ALqSfBi4YfmGDf5GX5h1eQzPAY2fzzq3NjVOjqKuwbNVVOBNeLg7EvukboPE8WgC1Nn2an YEHi0yaFM5zBDm7MIv/a3jWmFyqLmMa5NTkDTwDLgbsUzYgA+sBYo38RGLaz3U202Frpp9 O9z6Tvw/8PZIwCh/PvGnGJvwZXr1vc8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-133-FBsco_4rN5Oi0ULOYSkAvQ-1; Mon, 08 Jun 2020 08:21:23 -0400 X-MC-Unique: FBsco_4rN5Oi0ULOYSkAvQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67401107ACCD; Mon, 8 Jun 2020 12:21:21 +0000 (UTC) Received: from prarit.bos.redhat.com (prarit-guest.7a2m.lab.eng.bos.redhat.com [10.16.222.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8716E1002397; Mon, 8 Jun 2020 12:21:19 +0000 (UTC) From: Prarit Bhargava To: linux-kernel@vger.kernel.org Cc: Prarit Bhargava , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Tony Luck , "Peter Zijlstra (Intel)" , Sean Christopherson , Rahul Tanwar , Xiaoyao Li , Ricardo Neri , Dave Hansen Subject: [PATCH v2] x86/split_lock: Sanitize userspace and guest error output Date: Mon, 8 Jun 2020 08:21:14 -0400 Message-Id: <20200608122114.13043-1-prarit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are two problems with kernel messages in fatal mode that were found during testing of guests and userspace programs. The first is that no kernel message is output when the split lock detector is triggered with a userspace program. As a result the userspace process dies from receiving SIGBUS with no indication to the user of what caused the process to die. The second problem is that only the first triggering guest causes a kernel message to be output because the message is output with pr_warn_once(). This also results in a loss of information to the user. While fixing these I noticed that the same message was being output three times so I'm cleaning that up too. Fix fatal mode output, and use consistent messages for fatal and warn modes for both userspace and guests. Signed-off-by: Prarit Bhargava Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: x86@kernel.org Cc: "H. Peter Anvin" Cc: Tony Luck Cc: "Peter Zijlstra (Intel)" Cc: Sean Christopherson Cc: Rahul Tanwar Cc: Xiaoyao Li Cc: Ricardo Neri Cc: Dave Hansen --- v2: Do not output a message if CPL 3 Alignment Check is turned on (xiaoyao.li) arch/x86/kernel/cpu/intel.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 166d7c355896..e02ec81fe1eb 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -1074,10 +1074,17 @@ static void split_lock_init(void) split_lock_verify_msr(sld_state != sld_off); } -static void split_lock_warn(unsigned long ip) +static bool split_lock_warn(unsigned long ip, int fatal_no_warn) { - pr_warn_ratelimited("#AC: %s/%d took a split_lock trap at address: 0x%lx\n", - current->comm, current->pid, ip); + if (fatal_no_warn) + return false; + + pr_warn_ratelimited("#AC: %s/%d %ssplit_lock trap at address: 0x%lx\n", + current->comm, current->pid, + sld_state == sld_fatal ? "fatal " : "", ip); + + if (sld_state == sld_fatal) + return false; /* * Disable the split lock detection for this task so it can make @@ -1086,18 +1093,13 @@ static void split_lock_warn(unsigned long ip) */ sld_update_msr(false); set_tsk_thread_flag(current, TIF_SLD); + return true; } bool handle_guest_split_lock(unsigned long ip) { - if (sld_state == sld_warn) { - split_lock_warn(ip); + if (split_lock_warn(ip, 0)) return true; - } - - pr_warn_once("#AC: %s/%d %s split_lock trap at address: 0x%lx\n", - current->comm, current->pid, - sld_state == sld_fatal ? "fatal" : "bogus", ip); current->thread.error_code = 0; current->thread.trap_nr = X86_TRAP_AC; @@ -1108,10 +1110,7 @@ EXPORT_SYMBOL_GPL(handle_guest_split_lock); bool handle_user_split_lock(struct pt_regs *regs, long error_code) { - if ((regs->flags & X86_EFLAGS_AC) || sld_state == sld_fatal) - return false; - split_lock_warn(regs->ip); - return true; + return split_lock_warn(regs->ip, regs->flags & X86_EFLAGS_AC); } /* -- 2.21.3