Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3922553pxb; Mon, 4 Oct 2021 12:43:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZnGyyb7FTjr3DIMQV/Ci66KaDeOYIXWh1tpMft4M15nKFduZl9KXnzJ7r4CIPutq1891k X-Received: by 2002:a17:906:48ce:: with SMTP id d14mr16258001ejt.336.1633376612405; Mon, 04 Oct 2021 12:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633376612; cv=none; d=google.com; s=arc-20160816; b=MOqEd5l4nPeEGenmk3nIbLVWN/O+g/3ugQcGPmw7YsJiraKJne8hDbB64H22TKNWTY anVC7m5jvPCrompNoY5dcUoGLD3u/+8+oQccZ+SP92I4e3OPnvZ6mGHgxLz3hJZQVeeX MgYl8F1yg5W0l1N9/7/UbGS81jF2kVdL6ar4SD5hv2pR1pDfPbI11PIRNivvxec+OSqb w2SA8LvS6yBuyih1tQR8kmjoVkWS48STctjgfv2hR8Da71AZHmuYH749+e40iK1Jip2A EKuWPMjn12zof/QoeX/teOrLxVe66Rsk+z3ma1c0cAKb2nx4arLD59KBMqv9dV9560Jr UxKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DsF5ih2WbSBeNWP6sXPz2KsD0gIwiQOWTbOLVRrRsJ4=; b=0ObErq4SP5LyYnZVu+IovuySXx3Tpnxi7FuwFd0e2Ku/HhNjuB6OKQzQWtaR2Ua+4t b178tt0Gj1kd6eGrgb1G9mfARRK/wvxufBCp7xcIR9hCvvTVBKZyEuYt5TH0uE6TDSYw 1Ue4RO+oOZkaqV/+oMcIN+0Adc/m3TXcCTQaPAUG/UL4FrBvPpy1BQGStC5llaSxAWKk s+pyu8clJ8USKTzNaMdwr6Vx2BFeTxerX1+U9kOUVV7PqNMJcGVgTV6uQxzhTrcQeYNo /br541tdoZ5bc737WJmolpztQhMsmq7JSLm26oBgjz9m0/ie1NsL8rPNQfJIsvjE1G11 KsMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="J1mnSqb/"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p7si18396074ejl.82.2021.10.04.12.43.07; Mon, 04 Oct 2021 12:43:32 -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=@linuxfoundation.org header.s=korg header.b="J1mnSqb/"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234851AbhJDNEg (ORCPT + 99 others); Mon, 4 Oct 2021 09:04:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:38830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234690AbhJDNDF (ORCPT ); Mon, 4 Oct 2021 09:03:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 50DC661A58; Mon, 4 Oct 2021 12:59:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633352373; bh=2vUH5UaK+CTkUML7SMrS/yBFMSd7Ex3I/o640zwF/+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J1mnSqb/3vFGqJg69hNVg54GtuvhOE6E18O6OlFTPQ199WawM5syx0BEeVEzIk/HE nJ5vogjqSOoOXtz8S8oxSTgLBzjlUrlvumJbwdqzuTRmfu834t330C+EqtfB5qGdMY 2lH1Wsy8y3hHOeB4xWBEqdW9+EKvqjoAQE9nKr1M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Beulich , Boris Ostrovsky , Juergen Gross Subject: [PATCH 4.14 05/75] xen/x86: fix PV trap handling on secondary processors Date: Mon, 4 Oct 2021 14:51:40 +0200 Message-Id: <20211004125031.708386040@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125031.530773667@linuxfoundation.org> References: <20211004125031.530773667@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Beulich commit 0594c58161b6e0f3da8efa9c6e3d4ba52b652717 upstream. The initial observation was that in PV mode under Xen 32-bit user space didn't work anymore. Attempts of system calls ended in #GP(0x402). All of the sudden the vector 0x80 handler was not in place anymore. As it turns out up to 5.13 redundant initialization did occur: Once from cpu_initialize_context() (through its VCPUOP_initialise hypercall) and a 2nd time while each CPU was brought fully up. This 2nd initialization is now gone, uncovering that the 1st one was flawed: Unlike for the set_trap_table hypercall, a full virtual IDT needs to be specified here; the "vector" fields of the individual entries are of no interest. With many (kernel) IDT entries still(?) (i.e. at that point at least) empty, the syscall vector 0x80 ended up in slot 0x20 of the virtual IDT, thus becoming the domain's handler for vector 0x20. Make xen_convert_trap_info() fit for either purpose, leveraging the fact that on the xen_copy_trap_info() path the table starts out zero-filled. This includes moving out the writing of the sentinel, which would also have lead to a buffer overrun in the xen_copy_trap_info() case if all (kernel) IDT entries were populated. Convert the writing of the sentinel to clearing of the entire table entry rather than just the address field. (I didn't bother trying to identify the commit which uncovered the issue in 5.14; the commit named below is the one which actually introduced the bad code.) Fixes: f87e4cac4f4e ("xen: SMP guest support") Cc: stable@vger.kernel.org Signed-off-by: Jan Beulich Reviewed-by: Boris Ostrovsky Link: https://lore.kernel.org/r/7a266932-092e-b68f-f2bb-1473b61adc6e@suse.com Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- arch/x86/xen/enlighten_pv.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -721,8 +721,8 @@ static void xen_write_idt_entry(gate_des preempt_enable(); } -static void xen_convert_trap_info(const struct desc_ptr *desc, - struct trap_info *traps) +static unsigned xen_convert_trap_info(const struct desc_ptr *desc, + struct trap_info *traps, bool full) { unsigned in, out, count; @@ -732,17 +732,18 @@ static void xen_convert_trap_info(const for (in = out = 0; in < count; in++) { gate_desc *entry = (gate_desc *)(desc->address) + in; - if (cvt_gate_to_trap(in, entry, &traps[out])) + if (cvt_gate_to_trap(in, entry, &traps[out]) || full) out++; } - traps[out].address = 0; + + return out; } void xen_copy_trap_info(struct trap_info *traps) { const struct desc_ptr *desc = this_cpu_ptr(&idt_desc); - xen_convert_trap_info(desc, traps); + xen_convert_trap_info(desc, traps, true); } /* Load a new IDT into Xen. In principle this can be per-CPU, so we @@ -752,6 +753,7 @@ static void xen_load_idt(const struct de { static DEFINE_SPINLOCK(lock); static struct trap_info traps[257]; + unsigned out; trace_xen_cpu_load_idt(desc); @@ -759,7 +761,8 @@ static void xen_load_idt(const struct de memcpy(this_cpu_ptr(&idt_desc), desc, sizeof(idt_desc)); - xen_convert_trap_info(desc, traps); + out = xen_convert_trap_info(desc, traps, false); + memset(&traps[out], 0, sizeof(traps[0])); xen_mc_flush(); if (HYPERVISOR_set_trap_table(traps))