From: Jessica Yu <jeyu@redhat.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
Petr Mladek <pmladek@suse.com>, Jiri Kosina <jikos@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, Miroslav Benes <mbenes@suse.cz>,
linux-api@vger.kernel.org, live-patching@vger.kernel.org,
x86@kernel.org, linux-kernel@vger.kernel.org,
linux-s390@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: module: preserve Elf information for livepatch modules
Date: Tue, 22 Mar 2016 13:57:01 -0400 [thread overview]
Message-ID: <20160322175700.GA30747@packer-debian-8-amd64.digitalocean.com> (raw)
In-Reply-To: <20160321140631.z6scycsxz6fhsjvg@treble.redhat.com>
+++ Josh Poimboeuf [21/03/16 09:06 -0500]:
>On Wed, Mar 16, 2016 at 03:47:04PM -0400, Jessica Yu wrote:
>> For livepatch modules, copy Elf section, symbol, and string information
>> from the load_info struct in the module loader. Persist copies of the
>> original symbol table and string table.
>>
>> Livepatch manages its own relocation sections in order to reuse module
>> loader code to write relocations. Livepatch modules must preserve Elf
>> information such as section indices in order to apply livepatch relocation
>> sections using the module loader's apply_relocate_add() function.
>>
>> In order to apply livepatch relocation sections, livepatch modules must
>> keep a complete copy of their original symbol table in memory. Normally, a
>> stripped down copy of a module's symbol table (containing only "core"
>> symbols) is made available through module->core_symtab. But for livepatch
>> modules, the symbol table copied into memory on module load must be exactly
>> the same as the symbol table produced when the patch module was compiled.
>> This is because the relocations in each livepatch relocation section refer
>> to their respective symbols with their symbol indices, and the original
>> symbol indices (and thus the symtab ordering) must be preserved in order
>> for apply_relocate_add() to find the right symbol.
>>
>> Signed-off-by: Jessica Yu <jeyu@redhat.com>
>> ---
>> include/linux/module.h | 25 ++++++++++
>> kernel/module.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++-
>> 2 files changed, 146 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/linux/module.h b/include/linux/module.h
>> index 2bb0c30..3daf2b3 100644
>> --- a/include/linux/module.h
>> +++ b/include/linux/module.h
>> @@ -330,6 +330,15 @@ struct mod_kallsyms {
>> char *strtab;
>> };
>>
>> +#ifdef CONFIG_LIVEPATCH
>> +struct klp_modinfo {
>> + Elf_Ehdr hdr;
>> + Elf_Shdr *sechdrs;
>> + char *secstrings;
>> + unsigned int symndx;
>> +};
>> +#endif
>> +
>> struct module {
>> enum module_state state;
>>
>> @@ -456,7 +465,11 @@ struct module {
>> #endif
>>
>> #ifdef CONFIG_LIVEPATCH
>> + bool klp; /* Is this a livepatch module? */
>> bool klp_alive;
>> +
>> + /* Elf information */
>> + struct klp_modinfo *klp_info;
>> #endif
>>
>> #ifdef CONFIG_MODULE_UNLOAD
>> @@ -630,6 +643,18 @@ static inline bool module_requested_async_probing(struct module *module)
>> return module && module->async_probe_requested;
>> }
>>
>> +#ifdef CONFIG_LIVEPATCH
>> +static inline bool is_livepatch_module(struct module *mod)
>> +{
>> + return mod->klp;
>> +}
>> +#else /* !CONFIG_LIVEPATCH */
>> +static inline bool is_livepatch_module(struct module *mod)
>> +{
>> + return false;
>> +}
>> +#endif /* CONFIG_LIVEPATCH */
>> +
>> #else /* !CONFIG_MODULES... */
>>
>> /* Given an address, look for it in the exception tables. */
>> diff --git a/kernel/module.c b/kernel/module.c
>> index 87cfeb2..80b7fd9 100644
>> --- a/kernel/module.c
>> +++ b/kernel/module.c
>> @@ -1971,6 +1971,82 @@ static void module_enable_nx(const struct module *mod) { }
>> static void module_disable_nx(const struct module *mod) { }
>> #endif
>>
>> +#ifdef CONFIG_LIVEPATCH
>> +/*
>> + * Persist Elf information about a module. Copy the Elf header,
>> + * section header table, section string table, and symtab section
>> + * index from info to mod->klp_info.
>> + */
>> +static int copy_module_elf(struct module *mod, struct load_info *info)
>> +{
>> + unsigned int size, symndx;
>> + int ret;
>> +
>> + size = sizeof(*mod->klp_info);
>> + mod->klp_info = kmalloc(size, GFP_KERNEL);
>> + if (mod->klp_info == NULL)
>> + return -ENOMEM;
>> +
>> + /* Elf header */
>> + size = sizeof(Elf_Ehdr);
>> + memcpy(&mod->klp_info->hdr, info->hdr, size);
>> +
>> + /* Elf section header table */
>> + size = sizeof(Elf_Shdr) * info->hdr->e_shnum;
>> + mod->klp_info->sechdrs = kmalloc(size, GFP_KERNEL);
>> + if (mod->klp_info->sechdrs == NULL) {
>> + ret = -ENOMEM;
>> + goto free_info;
>> + }
>> + memcpy(mod->klp_info->sechdrs, info->sechdrs, size);
>> +
>> + /* Elf section name string table */
>> + size = info->sechdrs[info->hdr->e_shstrndx].sh_size;
>> + mod->klp_info->secstrings = kmalloc(size, GFP_KERNEL);
>> + if (mod->klp_info->secstrings == NULL) {
>> + ret = -ENOMEM;
>> + goto free_sechdrs;
>> + }
>> + memcpy(mod->klp_info->secstrings, info->secstrings, size);
>> +
>> + /* Elf symbol section index */
>> + symndx = info->index.sym;
>> + mod->klp_info->symndx = symndx;
>
>nit: The 'symndx' local variable is superfluous.
>
The symndx variable is just there to keep the line below from reaching
an ugly length (although it is already quite long...)
>> + mod->klp_info->sechdrs[symndx].sh_addr = (unsigned long) mod->core_kallsyms.symtab;
next prev parent reply other threads:[~2016-03-22 17:57 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-16 19:47 [PATCH v5 0/6] (mostly) Arch-independent livepatch Jessica Yu
2016-03-16 19:47 ` [PATCH v5 1/6] Elf: add livepatch-specific Elf constants Jessica Yu
2016-03-21 13:47 ` Miroslav Benes
2016-03-16 19:47 ` [PATCH v5 2/6] module: preserve Elf information for livepatch modules Jessica Yu
2016-03-16 20:05 ` kbuild test robot
2016-03-16 20:28 ` kbuild test robot
2016-03-16 21:25 ` Jessica Yu
2016-03-16 21:31 ` [PATCH v5 2/6] " kbuild test robot
2016-03-21 13:48 ` Miroslav Benes
2016-03-21 14:06 ` Josh Poimboeuf
2016-03-22 17:57 ` Jessica Yu [this message]
2016-03-22 18:55 ` Josh Poimboeuf
2016-03-21 16:50 ` [PATCH v5 2/6] " Petr Mladek
2016-03-16 19:47 ` [PATCH v5 3/6] module: s390: keep mod_arch_specific " Jessica Yu
2016-03-21 13:49 ` Miroslav Benes
2016-03-16 19:47 ` [PATCH v5 4/6] livepatch: reuse module loader code to write relocations Jessica Yu
2016-03-21 13:55 ` Miroslav Benes
2016-03-21 19:18 ` Jessica Yu
2016-03-21 19:24 ` Josh Poimboeuf
2016-03-21 21:16 ` Jiri Kosina
2016-03-21 21:34 ` Josh Poimboeuf
2016-03-21 22:02 ` Jiri Kosina
2016-03-22 19:00 ` Jessica Yu
2016-03-21 15:10 ` [PATCH v5 4/6] " Josh Poimboeuf
2016-03-21 16:31 ` Petr Mladek
2016-03-21 16:46 ` Josh Poimboeuf
2016-03-21 17:36 ` Josh Poimboeuf
2016-03-21 18:07 ` Jessica Yu
2016-03-16 19:47 ` [PATCH v5 5/6] samples: livepatch: mark as livepatch module Jessica Yu
2016-03-21 13:56 ` Miroslav Benes
2016-03-21 15:54 ` Josh Poimboeuf
2016-03-16 19:47 ` [PATCH v5 6/6] Documentation: livepatch: outline Elf format and requirements for patch modules Jessica Yu
2016-03-21 13:56 ` Miroslav Benes
-- strict thread matches above, loose matches on Subject: below --
2016-02-04 1:11 [RFC PATCH v4 0/6] (mostly) Arch-independent livepatch Jessica Yu
2016-02-04 1:11 ` [RFC PATCH v4 2/6] module: preserve Elf information for livepatch modules Jessica Yu
2016-02-08 20:10 ` Josh Poimboeuf
2016-02-08 20:34 ` Jessica Yu
2016-01-08 19:28 [RFC PATCH v3 0/6] (mostly) Arch-independent livepatch Jessica Yu
2016-01-08 19:28 ` [RFC PATCH v3 2/6] module: preserve Elf information for livepatch modules Jessica Yu
2016-01-11 1:25 ` Rusty Russell
2016-01-14 4:47 ` Jessica Yu
2016-01-14 20:28 ` Rusty Russell
2015-12-01 4:21 [RFC PATCH v2 0/6] (mostly) Arch-independent livepatch Jessica Yu
2015-12-01 4:21 ` [RFC PATCH v2 2/6] module: preserve Elf information for livepatch modules Jessica Yu
2015-12-01 8:48 ` Jessica Yu
2015-12-01 21:06 ` Jessica Yu
2015-12-08 18:32 ` [RFC PATCH v2 2/6] " Josh Poimboeuf
2015-12-09 20:05 ` Jessica Yu
2015-12-10 14:38 ` Josh Poimboeuf
2015-12-16 10:46 ` Miroslav Benes
2015-12-16 10:58 ` [RFC PATCH v2 2/6] " Miroslav Benes
2015-12-17 0:40 ` Jessica Yu
2015-12-17 16:26 ` [RFC PATCH v2 2/6] " Petr Mladek
2015-12-21 5:44 ` Jessica Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160322175700.GA30747@packer-debian-8-amd64.digitalocean.com \
--to=jeyu@redhat.com \
--cc=corbet@lwn.net \
--cc=jikos@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=rusty@rustcorp.com.au \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®