Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1309106

Re: livepatch: reuse module loader code to write relocations

From Miroslav Benes <mbenes@suse.cz>
Newsgroups linux.kernel
Subject Re: livepatch: reuse module loader code to write relocations
Date 2016-01-14 10:20 +0100
Message-ID <qQMeu-4Y2-17@gated-at.bofh.it> (permalink)
References <qOKTv-2Pp-3@gated-at.bofh.it> <qOL3d-2Tb-33@gated-at.bofh.it> <qQpKW-60h-3@gated-at.bofh.it> <qQyuR-3Ce-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, 13 Jan 2016, Jessica Yu wrote:

> +++ Miroslav Benes [13/01/16 10:19 +0100]:
> > On Fri, 8 Jan 2016, Jessica Yu wrote:
> > 
> > >  static int klp_write_object_relocations(struct module *pmod,
> > >  					struct klp_object *obj)
> > >  {
> > > -	int ret = 0;
> > > -	unsigned long val;
> > > -	struct klp_reloc *reloc;
> > > +	int i, len, ret = 0;
> > > +	char *secname;
> > > +	const char *objname;
> > > 
> > >  	if (WARN_ON(!klp_is_object_loaded(obj)))
> > >  		return -EINVAL;
> > > 
> > > -	if (WARN_ON(!obj->relocs))
> > > -		return -EINVAL;
> > > +	objname = klp_is_module(obj) ? obj->name : "vmlinux";
> > > 
> > >  	module_disable_ro(pmod);
> > > +	/* For each klp rela section for this object */
> > > +	for (i = 1; i < pmod->info->hdr->e_shnum; i++) {
> > > +		if (!(pmod->info->sechdrs[i].sh_flags & SHF_RELA_LIVEPATCH))
> > > +			continue;
> > 
> > One more thing. If the module does not specify it is a live patch module
> > in modinfo (with MODULE_INFO(livepatch, "Y")), but it is a perfect live
> > patch module otherwise (it calls klp_register_patch in its init function),
> > the kernel crashes here. pmod->info is not initialized at all. This should
> > be fixed. Perhaps the easiest would be to call
> > klp_write_object_relocations() in klp_init_object_loaded() only if
> > is_livepatch_module() returns true. Similar to a check for obj->relocs
> > before.
> 
> Hm yes, that's a problem. To remedy this, I think it makes sense to
> require all livepatch modules to identify themselves with the modinfo
> attribute, since it is a very simple requirement. If some module calls
> klp_register_patch() and it does not have the livepatch attribute,
> klp_register_patch() can just return an error. We can call
> is_livepatch_module() at the beginning of klp_register_patch(), and
> proceed only if the check succeeds, since we'll then know that the
> required structures have been properly initialized in the module
> loader. What do you think?

This is similar to what Jiri proposed in his mail. It is up to you. Both 
ways (the warning and the check, or what you propose) are fine.

Miroslav

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

[RFC PATCH v3 0/6] (mostly) Arch-independent livepatch Jessica Yu <jeyu@redhat.com> - 2016-01-08 20:30 +0100
  [RFC PATCH v3 1/6] Elf: add livepatch-specific Elf constants Jessica Yu <jeyu@redhat.com> - 2016-01-08 20:30 +0100
  [RFC PATCH v3 3/6] module: s390: keep mod_arch_specific for livepatch modules Jessica Yu <jeyu@redhat.com> - 2016-01-08 20:30 +0100
  [RFC PATCH v3 5/6] samples: livepatch: mark as livepatch module Jessica Yu <jeyu@redhat.com> - 2016-01-08 20:30 +0100
  [RFC PATCH v3 4/6] livepatch: reuse module loader code to write relocations Jessica Yu <jeyu@redhat.com> - 2016-01-08 20:40 +0100
    Re: [RFC PATCH v3 4/6] livepatch: reuse module loader code to write  relocations Petr Mladek <pmladek@suse.com> - 2016-01-11 18:00 +0100
      Re: [RFC PATCH v3 4/6] livepatch: reuse module loader code to write  relocations Josh Poimboeuf <jpoimboe@redhat.com> - 2016-01-11 22:00 +0100
    Re: [RFC PATCH v3 4/6] livepatch: reuse module loader code to write  relocations Josh Poimboeuf <jpoimboe@redhat.com> - 2016-01-11 22:40 +0100
      Re: livepatch: reuse module loader code to write relocations Jessica Yu <jeyu@redhat.com> - 2016-01-11 23:40 +0100
        Re: livepatch: reuse module loader code to write relocations Josh Poimboeuf <jpoimboe@redhat.com> - 2016-01-12 04:10 +0100
          Re: livepatch: reuse module loader code to write relocations Petr Mladek <pmladek@suse.com> - 2016-01-12 10:20 +0100
          Re: livepatch: reuse module loader code to write relocations Jessica Yu <jeyu@redhat.com> - 2016-01-14 06:10 +0100
    Re: [RFC PATCH v3 4/6] livepatch: reuse module loader code to write  relocations Miroslav Benes <mbenes@suse.cz> - 2016-01-12 17:50 +0100
      Re: livepatch: reuse module loader code to write relocations Jessica Yu <jeyu@redhat.com> - 2016-01-14 05:00 +0100
        Re: livepatch: reuse module loader code to write relocations Miroslav Benes <mbenes@suse.cz> - 2016-01-14 10:10 +0100
    Re: [RFC PATCH v3 4/6] livepatch: reuse module loader code to write  relocations Miroslav Benes <mbenes@suse.cz> - 2016-01-13 10:20 +0100
      Re: [RFC PATCH v3 4/6] livepatch: reuse module loader code to write  relocations Jiri Kosina <jikos@kernel.org> - 2016-01-13 10:40 +0100
      Re: livepatch: reuse module loader code to write relocations Jessica Yu <jeyu@redhat.com> - 2016-01-13 19:40 +0100
        Re: livepatch: reuse module loader code to write relocations Miroslav Benes <mbenes@suse.cz> - 2016-01-14 10:20 +0100

csiph-web