Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3104577imm; Fri, 10 Aug 2018 03:59:55 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxS3OYRqvGUadtTV3gLVhBP1ITzUDlTh24QKnWCvJnWvy5QbimBhd/nrCG4qiM+oGePg59T X-Received: by 2002:a17:902:3a2:: with SMTP id d31-v6mr5845402pld.287.1533898795478; Fri, 10 Aug 2018 03:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533898795; cv=none; d=google.com; s=arc-20160816; b=V03kQH8y1qGWo0McI5rw7OYmqsXsvQu1MQQ1cARP4NmbjFNSfQXSam48xKw1JiGmHJ JrSpqjvcSBFHGHuSo7W1mKo9ijN4ER8GOlgb7kVLkmjhuUjrjteiprz4eNmZ3J+xVeVd BE1rDg8dQBBlW4sIkrKGQ/i9dTRx+YD7Jcg9TZ7t7sM2wJnOkhbvyDeN1DuSBBPaUmqF 1yE0ZZ9wMTeXRG0P1HjRiYFux6ChC9iZKcmtbOo+oqEgrTG1VI9eIt/HvYPoGKx5GMjR mKVGNwQ8kVGkH5OTfuB8datDNlKEa8Iv4KFw/50b2LYf3u5YcjHoQpFQT3e6roTBHxTC KTBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=IKlw0Ez4E/NEa+TS3gqq/CqjmnLxLoOwajt/eV+bCJQ=; b=cEJi0PBGRLWSktrGU9kbbX/0dkqFtk/1vGrYQfGCU/bu3o6mkxMW31S4+U6YJGrQ8g 7e91soSxALGrYGMDljps0gMDrvmRpb5uR07SjEqq+ii2ojt5gcFAxs55TGik+BbORivZ zEuf/BdH8VJkXMWt3DUX4kYIvhA8esXOmlWcRjLylyQNIDy9ViQUY8rKkP6YLGoirfyi FRGmL+ELbgvT0kgrR/dCcSRioMLaUcv3Hu7VD/B6S9lNebcGB0m46Pq0GGkbpIhVgjjc sDpWqUzHKSJPAheAlAY1tHoMgctflkaK4h4RAkGFRVKfDPzSR8ZZ4G6h5lcF/QenWo2G FH1g== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i62-v6si9460686pge.93.2018.08.10.03.59.40; Fri, 10 Aug 2018 03:59:55 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727763AbeHJM6N (ORCPT + 99 others); Fri, 10 Aug 2018 08:58:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44126 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727209AbeHJM6N (ORCPT ); Fri, 10 Aug 2018 08:58:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53A2C40216F4; Fri, 10 Aug 2018 10:28:55 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-93.pek2.redhat.com [10.72.12.93]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F148610CD7DE; Fri, 10 Aug 2018 10:28:51 +0000 (UTC) Date: Fri, 10 Aug 2018 18:28:46 +0800 From: Dave Young To: Mike Galbraith Cc: Baoquan He , Sebastian Andrzej Siewior , lkml Subject: Re: [PATCH] x86, kdump: Fix efi=noruntime NULL pointer dereference Message-ID: <20180810102846.GA31327@dhcp-128-65.nay.redhat.com> References: <1533737025.4936.3.camel@gmx.de> <20180810084501.GA11901@dhcp-128-65.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180810084501.GA11901@dhcp-128-65.nay.redhat.com> User-Agent: Mutt/1.9.5 (2018-04-13) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 10 Aug 2018 10:28:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 10 Aug 2018 10:28:55 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dyoung@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/10/18 at 04:45pm, Dave Young wrote: > On 08/08/18 at 04:03pm, Mike Galbraith wrote: > > When booting with efi=noruntime, we call efi_runtime_map_copy() while > > loading the kdump kernel, and trip over a NULL efi.memmap.map. Avoid > > that and a useless allocation when the only mapping we can use (1:1) > > is not available. > > > > Signed-off-by: Mike Galbraith > > --- > > arch/x86/kernel/kexec-bzimage64.c | 22 +++++++++++----------- > > 1 file changed, 11 insertions(+), 11 deletions(-) > > > > --- a/arch/x86/kernel/kexec-bzimage64.c > > +++ b/arch/x86/kernel/kexec-bzimage64.c > > @@ -122,9 +122,6 @@ static int setup_efi_info_memmap(struct > > unsigned long efi_map_phys_addr = params_load_addr + efi_map_offset; > > struct efi_info *ei = ¶ms->efi_info; > > > > - if (!efi_map_sz) > > - return 0; > > - > > efi_runtime_map_copy(efi_map, efi_map_sz); > > > > ei->efi_memmap = efi_map_phys_addr & 0xffffffff; > > @@ -176,7 +173,7 @@ setup_efi_state(struct boot_params *para > > * acpi_rsdp= on kernel command line to make second kernel boot > > * without efi. > > */ > > - if (efi_enabled(EFI_OLD_MEMMAP)) > > + if (efi_enabled(EFI_OLD_MEMMAP) || !efi_enabled(EFI_MEMMAP)) > > return 0; > > > > ei->efi_loader_signature = current_ei->efi_loader_signature; > > @@ -338,7 +335,7 @@ static void *bzImage64_load(struct kimag > > struct kexec_entry64_regs regs64; > > void *stack; > > unsigned int setup_hdr_offset = offsetof(struct boot_params, hdr); > > - unsigned int efi_map_offset, efi_map_sz, efi_setup_data_offset; > > + unsigned int efi_map_offset = 0, efi_map_sz = 0, efi_setup_data_offset = 0; > > struct kexec_buf kbuf = { .image = image, .buf_max = ULONG_MAX, > > .top_down = true }; > > struct kexec_buf pbuf = { .image = image, .buf_min = MIN_PURGATORY_ADDR, > > @@ -397,19 +394,22 @@ static void *bzImage64_load(struct kimag > > * have to create separate segment for each. Keeps things > > * little bit simple > > */ > > - efi_map_sz = efi_get_runtime_map_size(); > > params_cmdline_sz = sizeof(struct boot_params) + cmdline_len + > > MAX_ELFCOREHDR_STR_LEN; > > params_cmdline_sz = ALIGN(params_cmdline_sz, 16); > > - kbuf.bufsz = params_cmdline_sz + ALIGN(efi_map_sz, 16) + > > - sizeof(struct setup_data) + > > - sizeof(struct efi_setup_data); > > + kbuf.bufsz = params_cmdline_sz + sizeof(struct setup_data); > > + > > + /* Now add space for the efi stuff if we have a useable 1:1 mapping. */ > > + if (!efi_enabled(EFI_OLD_MEMMAP) && efi_enabled(EFI_MEMMAP)) { > > + efi_map_sz = efi_get_runtime_map_size(); > > + kbuf.bufsz += ALIGN(efi_map_sz, 16) + sizeof(struct efi_setup_data); > > + efi_map_offset = params_cmdline_sz; > > + efi_setup_data_offset = efi_map_offset + ALIGN(efi_map_sz, 16); > > + } > > > > params = kzalloc(kbuf.bufsz, GFP_KERNEL); > > if (!params) > > return ERR_PTR(-ENOMEM); > > - efi_map_offset = params_cmdline_sz; > > - efi_setup_data_offset = efi_map_offset + ALIGN(efi_map_sz, 16); > > > > /* Copy setup header onto bootparams. Documentation/x86/boot.txt */ > > setup_header_size = 0x0202 + kernel[0x0201] - setup_hdr_offset; > > BTW, this patch only fix the kexec load phase problem, even if kexec > load successfully with the fix, the 2nd kernel can not boot because efi > memmap info is not correct and usable. > > So we should go with some fix similar to below, and do the cleanup we > mentioned with a separate patch later. > > Also user space kexec-tools need a similar patch to error out in case > no runtime maps. It would be good to fix both userspace and kernel > load. > > diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c > index 7326078eaa7a..e34ba2f53cfb 100644 > --- a/arch/x86/kernel/kexec-bzimage64.c > +++ b/arch/x86/kernel/kexec-bzimage64.c > @@ -123,7 +123,7 @@ static int setup_efi_info_memmap(struct boot_params *params, > struct efi_info *ei = ¶ms->efi_info; > > if (!efi_map_sz) > - return 0; > + return -EINVAL; > > efi_runtime_map_copy(efi_map, efi_map_sz); > > @@ -166,9 +166,10 @@ setup_efi_state(struct boot_params *params, unsigned long params_load_addr, > { > struct efi_info *current_ei = &boot_params.efi_info; > struct efi_info *ei = ¶ms->efi_info; > + int ret; > > if (!current_ei->efi_memmap_size) > - return 0; > + return -EINVAL; > > /* > * If 1:1 mapping is not enabled, second kernel can not setup EFI > @@ -176,8 +177,8 @@ setup_efi_state(struct boot_params *params, unsigned long params_load_addr, > * acpi_rsdp= on kernel command line to make second kernel boot > * without efi. > */ > - if (efi_enabled(EFI_OLD_MEMMAP)) > - return 0; > + if (efi_enabled(EFI_OLD_MEMMAP) || !efi_enabled(EFI_RUNTIME_SERVICES)) > + return -ENODEV; > > ei->efi_loader_signature = current_ei->efi_loader_signature; > ei->efi_systab = current_ei->efi_systab; > @@ -186,8 +187,10 @@ setup_efi_state(struct boot_params *params, unsigned long params_load_addr, > ei->efi_memdesc_version = current_ei->efi_memdesc_version; > ei->efi_memdesc_size = efi_get_runtime_map_desc_size(); > > - setup_efi_info_memmap(params, params_load_addr, efi_map_offset, > + ret = setup_efi_info_memmap(params, params_load_addr, efi_map_offset, > efi_map_sz); > + if (ret) > + return ret; > prepare_add_efi_setup_data(params, params_load_addr, > efi_setup_data_offset); > return 0; > @@ -250,8 +253,10 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params, > > #ifdef CONFIG_EFI > /* Setup EFI state */ > - setup_efi_state(params, params_load_addr, efi_map_offset, efi_map_sz, > + ret = setup_efi_state(params, params_load_addr, efi_map_offset, efi_map_sz, > efi_setup_data_offset); > + if (ret) Here should check efi_enabled(EFI_BOOT) && ret In case efi boot we need the efi info set correctly, or one need pass acpi_rsdp= in kernel cmdline param. Still not sure how to allow one to workaround it by using acpi_rsdp= param with kexec_file_load.. > + return ret; > #endif > > /* Setup EDD info */