Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3532562imd; Mon, 29 Oct 2018 08:30:13 -0700 (PDT) X-Google-Smtp-Source: AJdET5eNc1zpgrDlhUdCG2X/GubCEujFISl82OxHeWt1Z7LwByx/FYNBz2DhNCGcWxhBK0vvKifo X-Received: by 2002:a17:902:5e3:: with SMTP id f90-v6mr15102980plf.286.1540827013120; Mon, 29 Oct 2018 08:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540827013; cv=none; d=google.com; s=arc-20160816; b=Kl+xnqiIbHLpI/pC0NHQiY9f07YiP7lR/XfIfO9B0Avyyw6Ysnv/RhPyQPqvjTGxMy tMz+ml2PV3Heg10dntspqFWUFWw3tO38X7geBN9k2Awl3AbRo0CWl9Bc5Y50grNePoO9 N+/KCag1W1oBeenmet6mbHaq/TiMMGIaq+t9nQNg8uXShB8aJF0tbOP2GwvRsst/Z+0Q 3DUPqEkwNZZRWixln2/ECvXXno6vhpiVcmWt2fU5iMx8bmQaeOn0rSDlV9gNuqx0jtaY x7xP2dbhDJcVAExm0o6oSnzTRihrqbz7d8LxnMqdJCVdDw/TECmTi0zV0Z/obz+Vf5fX 01/Q== 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; bh=4AFF0XCy8IzRQ4mw9Gq9a+tpGrD3F1y9SMQJoi2xHJQ=; b=qbmN+QCb4llFLHQiSgeTh2sqxd1Y0OHNGfNuJRf20ssRjKNXoeN6OVoXYhc/1jvFQ3 T1HSRgruXab/L2n8k6aRSDnMF+XWCWBMaXV0R+TlG38BYU7Nx8NAgeGvf0sIw6eYyR2q 6y9KPw3eOnmu5zPcICrA3iaoIaCiVRUMDwR2zujFbXam3np2ap0kDZTPqotN4Q8gPVnD s8ry9hvnNqtvA6pzhL1wEtJikk5EfmV0nXhoPFPQHzXMWp86tSyiwI2fjij11lyASTgd mO/nVsQa5MSAj15w+Rk0zZXqKbNSteHFmj68O1EKc/8YnBMi+WJFbElGMGdrY8+bRuLG vXnQ== 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 u4-v6si21110009pgi.554.2018.10.29.08.29.45; Mon, 29 Oct 2018 08:30:13 -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 S1727637AbeJ3ARe (ORCPT + 99 others); Mon, 29 Oct 2018 20:17:34 -0400 Received: from foss.arm.com ([217.140.101.70]:42280 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726741AbeJ3ARd (ORCPT ); Mon, 29 Oct 2018 20:17:33 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9C5BD341; Mon, 29 Oct 2018 08:28:27 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6BA5B3F71D; Mon, 29 Oct 2018 08:28:27 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 71FF21AE091C; Mon, 29 Oct 2018 15:28:34 +0000 (GMT) Date: Mon, 29 Oct 2018 15:28:34 +0000 From: Will Deacon To: Jessica Yu Cc: Torsten Duwe , Catalin Marinas , Julien Thierry , Steven Rostedt , Josh Poimboeuf , Ingo Molnar , Ard Biesheuvel , Arnd Bergmann , AKASHI Takahiro , Miroslav Benes , Petr Mladek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org Subject: Re: [PATCH v2] arm64/module: use mod->klp_info section header information for livepatch modules Message-ID: <20181029152834.GA16289@arm.com> References: <20181001140910.086E768BC7@newverein.lst.de> <20181001141652.5478C68BE1@newverein.lst.de> <20181023175553.gaobskk26koft6s2@linux-8ccs> <20181026172500.g65bl2p7cvey3qsx@linux-8ccs> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181026172500.g65bl2p7cvey3qsx@linux-8ccs> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jessica, On Fri, Oct 26, 2018 at 07:25:01PM +0200, Jessica Yu wrote: > The arm64 module loader keeps a pointer into info->sechdrs to keep track > of section header information for .plt section(s). A pointer to the > relevent section header (struct elf64_shdr) in info->sechdrs is stored > in mod->arch.{init,core}.plt. This pointer may be accessed while > applying relocations in apply_relocate_add() for example. And unlike > normal modules, livepatch modules can call apply_relocate_add() after > module load. But the info struct (and therefore info->sechdrs) gets > freed at the end of load_module() and so mod->arch.{init,core}.plt > becomes an invalid pointer after the module is done loading. > > Luckily, livepatch modules already keep a copy of Elf section header > information in mod->klp_info. So make sure livepatch modules on arm64 > have access to the section headers in klp_info and set > mod->arch.{init,core}.plt to the appropriate section header in > mod->klp_info so that they can call apply_relocate_add() even after > module load. > > Signed-off-by: Jessica Yu > --- > > v2: > - fix missing free_module_elf() in error path > - move copy_module_elf() and module_finalize() out of post_relocation() > to make error handling more clear > - add braces to if-else block in arm64 module_frob_arch_sections() > > arch/arm64/include/asm/module.h | 1 + > arch/arm64/kernel/module-plts.c | 17 ++++++++++++----- > arch/arm64/kernel/module.c | 10 ++++++++++ > kernel/module.c | 29 +++++++++++++++-------------- > 4 files changed, 38 insertions(+), 19 deletions(-) > > diff --git a/arch/arm64/include/asm/module.h b/arch/arm64/include/asm/module.h > index fef773c94e9d..ac9b97f9ae5e 100644 > --- a/arch/arm64/include/asm/module.h > +++ b/arch/arm64/include/asm/module.h > @@ -25,6 +25,7 @@ struct mod_plt_sec { > struct elf64_shdr *plt; > int plt_num_entries; > int plt_max_entries; > + int plt_shndx; > }; Does this mean we can drop the plt pointer from this struct altogether, and simply offset into the section headers when applying the relocations? Cheers, Will