Received: by 10.223.185.82 with SMTP id b18csp60152wrg; Thu, 8 Mar 2018 19:15:55 -0800 (PST) X-Google-Smtp-Source: AG47ELvLzXzQPTdhbREmaI09wGVSIl+EeYslN5iS7tkYpvCmHtnhAR9aewpLtYlJlXmt6/XHUF3X X-Received: by 2002:a17:902:aa89:: with SMTP id d9-v6mr26270157plr.337.1520565355364; Thu, 08 Mar 2018 19:15:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520565355; cv=none; d=google.com; s=arc-20160816; b=yXDSAiaFa7D/87ZderaSu42aVRnR2qxzGpL+EHeHkmr75o1d3pmxozY6q2ZDHPPTTr wx7VRjnxDXiaBQZf699MGhIZtRx8a1/fb0/1YsUswgAgvdnPry4rSajmHgJCphXSdJ8P H0z7g/TxjFZ5UUfBOxVZjI4OIwLWH/OFgVjrg7fQOZdpbSM6Pu7XRwj1Vl5dKftHBLIH YkZam8lliF7KA8GF0U5CJfbbCmaNNislm/EoakG4v1p9aqNT8cK683wlbdxziqrrLcy8 28d6nI8x+bkqjpdjXTfVHsuVj98Z5CtrS+eymtmTUVLwpynPyDZkkAvlMdUv6Tccq5NK KXJg== 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=FNKjw/DyOQTrwMqF45VKENQAycSBJlbDtyloGONSTLQ=; b=w0pqq8T6zqLgm0RA9r9dgsckXseIzaB8qBTbwYURacxO4KGYvfEXT0KJRnHrL6QMHc yh9Aj9XVT3ymk9F6OjBMGHGlc7VOy7US/Xc+kS2SdFpTa/nDtLrbcas0yafeDN+xGBzw Z+5KgdFuPnQDBZtGyTul99LMbCD1YATR+OnJztfSnzOwkiAu+X1Kla1Bgh9BkkE6v6BO /JWfPorsRHLX2h9bXm4zi5gaVQHaDAPzGkfmRVf7OiGvzPqIcQ+DnPJKT67u4p5R1Q6C LNCajAUEZD9ro8BreTtbquixPYefUeLjaVjhzVB9jA/zQiY0My2ZMhIBriP3j8FjVbj7 QnVg== 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 i4si79591pgr.266.2018.03.08.19.15.40; Thu, 08 Mar 2018 19:15:55 -0800 (PST) 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 S1751306AbeCIDOh (ORCPT + 99 others); Thu, 8 Mar 2018 22:14:37 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45322 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751078AbeCIDOc (ORCPT ); Thu, 8 Mar 2018 22:14:32 -0500 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 685164023BB3; Fri, 9 Mar 2018 03:14:31 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-79.pek2.redhat.com [10.72.12.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C045011701C3; Fri, 9 Mar 2018 03:14:25 +0000 (UTC) Date: Fri, 9 Mar 2018 11:14:20 +0800 From: Dave Young To: Philipp Rudo Cc: kexec@lists.infradead.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biederman , Vivek Goyal , Michael Ellerman , Thiago Jung Bauermann , Martin Schwidefsky , Heiko Carstens , Andrew Morton , x86@kernel.org, AKASHI Takahiro Subject: Re: [PATCH 09/11] kexec_file: Remove mis-use of sh_offset field Message-ID: <20180309031420.GA3246@dhcp-128-65.nay.redhat.com> References: <20180226151620.20970-1-prudo@linux.vnet.ibm.com> <20180226151620.20970-10-prudo@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180226151620.20970-10-prudo@linux.vnet.ibm.com> User-Agent: Mutt/1.9.1 (2017-09-22) 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.7]); Fri, 09 Mar 2018 03:14:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Mar 2018 03:14:31 +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 02/26/18 at 04:16pm, Philipp Rudo wrote: > The current code uses the sh_offset field in purgatory_info->sechdrs to > store a pointer to the current load address of the section. Depending > whether the section will be loaded or not this is either a pointer into > purgatory_info->purgatory_buf or kexec_purgatory. This is not only a > violation of the ELF standard but also makes the code very hard to > understand as you cannot tell if the memory you are using is read-only or > not. > > Remove this mis-use and store the offset of the section in > pugaroty_info->purgatory_buf in sh_offset. > > Signed-off-by: Philipp Rudo > --- > arch/x86/kernel/machine_kexec_64.c | 10 ++++++---- > kernel/kexec_file.c | 33 +++------------------------------ > 2 files changed, 9 insertions(+), 34 deletions(-) > > diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c > index 51667c8b5c9b..41db74bdc88b 100644 > --- a/arch/x86/kernel/machine_kexec_64.c > +++ b/arch/x86/kernel/machine_kexec_64.c > @@ -457,13 +457,15 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi, > * rel[i].r_offset contains byte offset from beginning > * of section to the storage unit affected. > * > - * This is location to update (->sh_offset). This is temporary > - * buffer where section is currently loaded. This will finally > - * be loaded to a different address later, pointed to by > + * This is location to update. This is temporary buffer > + * where section is currently loaded. This will finally be > + * loaded to a different address later, pointed to by > * ->sh_addr. kexec takes care of moving it > * (kexec_load_segment()). > */ > - location = (void *)(section->sh_offset + rel[i].r_offset); > + location = pi->purgatory_buf; > + location += section->sh_offset; > + location += rel[i].r_offset; > > /* Final address of the location */ > address = section->sh_addr + rel[i].r_offset; > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > index 746b91e46e34..25b44d1a664a 100644 > --- a/kernel/kexec_file.c > +++ b/kernel/kexec_file.c > @@ -736,28 +736,6 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, > pi->ehdr->e_shnum * sizeof(Elf_Shdr)); > pi->sechdrs = sechdrs; > > - /* > - * We seem to have multiple copies of sections. First copy is which > - * is embedded in kernel in read only section. Some of these sections > - * will be copied to a temporary buffer and relocated. And these > - * sections will finally be copied to their final destination at > - * segment load time. It would be good to keep above part comment somewhere.. > - * > - * Use ->sh_offset to reflect section address in memory. It will > - * point to original read only copy if section is not allocatable. > - * Otherwise it will point to temporary copy which will be relocated. > - * > - * Use ->sh_addr to contain final address of the section where it > - * will go during execution time. > - */ > - for (i = 0; i < pi->ehdr->e_shnum; i++) { > - if (sechdrs[i].sh_type == SHT_NOBITS) > - continue; > - > - sechdrs[i].sh_offset = (unsigned long)pi->ehdr + > - sechdrs[i].sh_offset; > - } > - > offset = 0; > bss_addr = kbuf->mem + kbuf->bufsz; > kbuf->image->start = pi->ehdr->e_entry; > @@ -786,17 +764,12 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, > kbuf->image->start += kbuf->mem + offset; > } > > - src = (void *)sechdrs[i].sh_offset; > + src = (void *)pi->ehdr + sechdrs[i].sh_offset; > dst = pi->purgatory_buf + offset; > memcpy(dst, src, sechdrs[i].sh_size); > > sechdrs[i].sh_addr = kbuf->mem + offset; > - > - /* > - * This section got copied to temporary buffer. Update > - * ->sh_offset accordingly. > - */ > - sechdrs[i].sh_offset = (unsigned long)dst; > + sechdrs[i].sh_offset = offset; > offset += sechdrs[i].sh_size; > } > > @@ -1006,7 +979,7 @@ int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name, > return -EINVAL; > } > > - sym_buf = (char *)sec->sh_offset + sym->st_value; > + sym_buf = (char *)pi->purgatory_buf + sec->sh_offset + sym->st_value; > > if (get_value) > memcpy((void *)buf, sym_buf, size); > -- > 2.13.5 > Thanks Dave