Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4640980ybp; Mon, 7 Oct 2019 11:27:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxz5623Z1NTut0QofD5JieBxw6OAK14IaM5go7BJRPPph57tVMIxf7zax6hr/Y8eAIhHlLp X-Received: by 2002:a17:906:41a:: with SMTP id d26mr24826992eja.17.1570472876158; Mon, 07 Oct 2019 11:27:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570472876; cv=none; d=google.com; s=arc-20160816; b=nA40QVZuC4itWgo3mgI3oZvqfoEHBMNJLqFKoPCSRZhzCdWjaKGMedz05vP4YwP+At IKh44s34OhjNTPo8IgG+e+WmunAT+KXHOSxJ6y5KRhDXNE9JgsvbuVnA1K/fZ6wgb5P9 ekEdjZIqNKsps5ky6Qa59noxlX0m/ZH0euS5QLteocqOQp3ZRMin4w0rzyQRMlL/3SPZ Y5BkGjxtyoHr8hIer2grjysumgCEQrNfxThWo3PAucgO2L3aQWt2TdouENRzcIU6py+0 L9FxAKv0NzxexkRIXDIVmCNDERiF12FlY7Mwlz2L1KgfkFc3+2svYuUzIOE08xrKDxqm jLuw== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=nSk3gDCdiKujiI/MfH6yqJo2X7eLRyqcUNRevhIQCPM=; b=eYo7SfNkJt6q98NmzxAgMpO9WZWRo/UODKC4z/UnftvgnccC/tXIpXb++lo+vzuaCm W54nqCTh4WN8tZijXc8p5h0+a02f/cJsrePoS0AC6EVK7n2bmPw8bpCagzirK01a2mwi WS876JpEgs3yST4icKLpyThRerBeVwUzJ770EqEBW9KNNoopB3ns6/MGWXrjnxm4Zsv8 v4mUC2B9qCyCiaxIrcyEBpIrY16vE4CSBZE4PSLe4yN7jvAHBX5K1V1tYfBqtkoVLKJB W6SJKEaId3MLxU6JKEdWGj/x50ykQaaLCgZHhZCeJY53H2WZgV+wzA2A94DXluJSftoM CW/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f19si9524302edb.385.2019.10.07.11.27.32; Mon, 07 Oct 2019 11:27:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729254AbfJGSZP (ORCPT + 99 others); Mon, 7 Oct 2019 14:25:15 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:45434 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728031AbfJGSZP (ORCPT ); Mon, 7 Oct 2019 14:25:15 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iHXgv-0002LT-4R; Mon, 07 Oct 2019 20:25:05 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id A286D1C079B; Mon, 7 Oct 2019 20:25:04 +0200 (CEST) Date: Mon, 07 Oct 2019 18:25:04 -0000 From: "tip-bot2 for Ralf Ramsauer" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/platform] x86/jailhouse: Improve setup data version comparison Cc: Ralf Ramsauer , Jan Kiszka , Borislav Petkov , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , jailhouse-dev@googlegroups.com, Ingo Molnar , linux-kernel@vger.kernel.org In-Reply-To: <20191007123819.161432-2-ralf.ramsauer@oth-regensburg.de> References: <20191007123819.161432-2-ralf.ramsauer@oth-regensburg.de> MIME-Version: 1.0 Message-ID: <157047270461.9978.15691766559763031669.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/platform branch of tip: Commit-ID: a980bfcccf1ebd7cc404c381ca747191e17bc28f Gitweb: https://git.kernel.org/tip/a980bfcccf1ebd7cc404c381ca747191e17bc28f Author: Ralf Ramsauer AuthorDate: Mon, 07 Oct 2019 14:38:18 +02:00 Committer: Ingo Molnar CommitterDate: Mon, 07 Oct 2019 17:35:50 +02:00 x86/jailhouse: Improve setup data version comparison We will soon introduce a new setup_data version and extend the structure. This requires some preparational work for the sanity check of the header and the check of the version. Use the following strategy: 1. Ensure that the header declares at least enough space for the version and the compatible_version as we must hold that fields for any version. Furthermore, the location and semantics of those fields will never change. 2. Copy over data -- as much as we can. The length is either limited by the header length, or the length of setup_data. 3. Things are now in place -- sanity check if the header length complies the actual version. For future versions of the setup_data, only step 3 requires alignment. Signed-off-by: Ralf Ramsauer Reviewed-by: Jan Kiszka Cc: Borislav Petkov Cc: H . Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: jailhouse-dev@googlegroups.com Link: https://lkml.kernel.org/r/20191007123819.161432-2-ralf.ramsauer@oth-regensburg.de Signed-off-by: Ingo Molnar --- arch/x86/include/uapi/asm/bootparam.h | 22 ++++++----- arch/x86/kernel/jailhouse.c | 50 ++++++++++++++++---------- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h index c895df5..43be437 100644 --- a/arch/x86/include/uapi/asm/bootparam.h +++ b/arch/x86/include/uapi/asm/bootparam.h @@ -139,15 +139,19 @@ struct boot_e820_entry { * setup data structure. */ struct jailhouse_setup_data { - __u16 version; - __u16 compatible_version; - __u16 pm_timer_address; - __u16 num_cpus; - __u64 pci_mmconfig_base; - __u32 tsc_khz; - __u32 apic_khz; - __u8 standard_ioapic; - __u8 cpu_ids[255]; + struct { + __u16 version; + __u16 compatible_version; + } __attribute__((packed)) hdr; + struct { + __u16 pm_timer_address; + __u16 num_cpus; + __u64 pci_mmconfig_base; + __u32 tsc_khz; + __u32 apic_khz; + __u8 standard_ioapic; + __u8 cpu_ids[255]; + } __attribute__((packed)) v1; } __attribute__((packed)); /* The so-called "zeropage" */ diff --git a/arch/x86/kernel/jailhouse.c b/arch/x86/kernel/jailhouse.c index 3ad34f0..b9647ad 100644 --- a/arch/x86/kernel/jailhouse.c +++ b/arch/x86/kernel/jailhouse.c @@ -22,6 +22,8 @@ #include static __initdata struct jailhouse_setup_data setup_data; +#define SETUP_DATA_V1_LEN (sizeof(setup_data.hdr) + sizeof(setup_data.v1)) + static unsigned int precalibrated_tsc_khz; static uint32_t jailhouse_cpuid_base(void) @@ -45,7 +47,7 @@ static void jailhouse_get_wallclock(struct timespec64 *now) static void __init jailhouse_timer_init(void) { - lapic_timer_period = setup_data.apic_khz * (1000 / HZ); + lapic_timer_period = setup_data.v1.apic_khz * (1000 / HZ); } static unsigned long jailhouse_get_tsc(void) @@ -88,14 +90,14 @@ static void __init jailhouse_get_smp_config(unsigned int early) register_lapic_address(0xfee00000); - for (cpu = 0; cpu < setup_data.num_cpus; cpu++) { - generic_processor_info(setup_data.cpu_ids[cpu], + for (cpu = 0; cpu < setup_data.v1.num_cpus; cpu++) { + generic_processor_info(setup_data.v1.cpu_ids[cpu], boot_cpu_apic_version); } smp_found_config = 1; - if (setup_data.standard_ioapic) { + if (setup_data.v1.standard_ioapic) { mp_register_ioapic(0, 0xfec00000, gsi_top, &ioapic_cfg); /* Register 1:1 mapping for legacy UART IRQs 3 and 4 */ @@ -126,9 +128,9 @@ static int __init jailhouse_pci_arch_init(void) pcibios_last_bus = 0xff; #ifdef CONFIG_PCI_MMCONFIG - if (setup_data.pci_mmconfig_base) { + if (setup_data.v1.pci_mmconfig_base) { pci_mmconfig_add(0, 0, pcibios_last_bus, - setup_data.pci_mmconfig_base); + setup_data.v1.pci_mmconfig_base); pci_mmcfg_arch_init(); } #endif @@ -139,6 +141,7 @@ static int __init jailhouse_pci_arch_init(void) static void __init jailhouse_init_platform(void) { u64 pa_data = boot_params.hdr.setup_data; + unsigned long setup_data_len; struct setup_data header; void *mapping; @@ -163,16 +166,8 @@ static void __init jailhouse_init_platform(void) memcpy(&header, mapping, sizeof(header)); early_memunmap(mapping, sizeof(header)); - if (header.type == SETUP_JAILHOUSE && - header.len >= sizeof(setup_data)) { - pa_data += offsetof(struct setup_data, data); - - mapping = early_memremap(pa_data, sizeof(setup_data)); - memcpy(&setup_data, mapping, sizeof(setup_data)); - early_memunmap(mapping, sizeof(setup_data)); - + if (header.type == SETUP_JAILHOUSE) break; - } pa_data = header.next; } @@ -180,13 +175,26 @@ static void __init jailhouse_init_platform(void) if (!pa_data) panic("Jailhouse: No valid setup data found"); - if (setup_data.compatible_version > JAILHOUSE_SETUP_REQUIRED_VERSION) - panic("Jailhouse: Unsupported setup data structure"); + /* setup data must at least contain the header */ + if (header.len < sizeof(setup_data.hdr)) + goto unsupported; - pmtmr_ioport = setup_data.pm_timer_address; + pa_data += offsetof(struct setup_data, data); + setup_data_len = min(sizeof(setup_data), (unsigned long)header.len); + mapping = early_memremap(pa_data, setup_data_len); + memcpy(&setup_data, mapping, setup_data_len); + early_memunmap(mapping, setup_data_len); + + if (setup_data.hdr.version == 0 || + setup_data.hdr.compatible_version != + JAILHOUSE_SETUP_REQUIRED_VERSION || + (setup_data.hdr.version >= 1 && header.len < SETUP_DATA_V1_LEN)) + goto unsupported; + + pmtmr_ioport = setup_data.v1.pm_timer_address; pr_debug("Jailhouse: PM-Timer IO Port: %#x\n", pmtmr_ioport); - precalibrated_tsc_khz = setup_data.tsc_khz; + precalibrated_tsc_khz = setup_data.v1.tsc_khz; setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); pci_probe = 0; @@ -196,6 +204,10 @@ static void __init jailhouse_init_platform(void) * are none in a non-root cell. */ disable_acpi(); + return; + +unsupported: + panic("Jailhouse: Unsupported setup data structure"); } bool jailhouse_paravirt(void)