All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Lawrence <joe.lawrence@redhat.com>
To: Song Liu <song@kernel.org>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>,
	"live-patching@vger.kernel.org" <live-patching@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"pmladek@suse.com" <pmladek@suse.com>,
	"jikos@kernel.org" <jikos@kernel.org>,
	"x86@kernel.org" <x86@kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	"mbenes@suse.cz" <mbenes@suse.cz>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"jpoimboe@kernel.org" <jpoimboe@kernel.org>
Subject: Re: [PATCH v5] livepatch: Clear relocation targets on a module removal
Date: Wed, 31 Aug 2022 16:06:33 -0400	[thread overview]
Message-ID: <Yw+/SXhh5puipgmo@redhat.com> (raw)
In-Reply-To: <CAPhsuW6CwQoU0GsXj0YhxngFfNMgD1mu6AjwqiZumTyWL84i1g@mail.gmail.com>

On Wed, Aug 31, 2022 at 10:05:43AM -0700, Song Liu wrote:
> On Wed, Aug 31, 2022 at 1:01 AM Christophe Leroy
> <christophe.leroy@csgroup.eu> wrote:
> >
> >
> >
> > Le 30/08/2022 à 20:53, Song Liu a écrit :
> > > From: Miroslav Benes <mbenes@suse.cz>
> > >
> > > Josh reported a bug:
> > >
> > >    When the object to be patched is a module, and that module is
> > >    rmmod'ed and reloaded, it fails to load with:
> > >
> > >    module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 2, loc 00000000ba0302e9, val ffffffffa03e293c
> > >    livepatch: failed to initialize patch 'livepatch_nfsd' for module 'nfsd' (-8)
> > >    livepatch: patch 'livepatch_nfsd' failed for module 'nfsd', refusing to load module 'nfsd'
> > >
> > >    The livepatch module has a relocation which references a symbol
> > >    in the _previous_ loading of nfsd. When apply_relocate_add()
> > >    tries to replace the old relocation with a new one, it sees that
> > >    the previous one is nonzero and it errors out.
> > >
> > >    On ppc64le, we have a similar issue:
> > >
> > >    module_64: livepatch_nfsd: Expected nop after call, got e8410018 at e_show+0x60/0x548 [livepatch_nfsd]
> > >    livepatch: failed to initialize patch 'livepatch_nfsd' for module 'nfsd' (-8)
> > >    livepatch: patch 'livepatch_nfsd' failed for module 'nfsd', refusing to load module 'nfsd'
> > >
> > > He also proposed three different solutions. We could remove the error
> > > check in apply_relocate_add() introduced by commit eda9cec4c9a1
> > > ("x86/module: Detect and skip invalid relocations"). However the check
> > > is useful for detecting corrupted modules.
> > >
> > > We could also deny the patched modules to be removed. If it proved to be
> > > a major drawback for users, we could still implement a different
> > > approach. The solution would also complicate the existing code a lot.
> > >
> > > We thus decided to reverse the relocation patching (clear all relocation
> > > targets on x86_64). The solution is not
> > > universal and is too much arch-specific, but it may prove to be simpler
> > > in the end.
> > >
> > > Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > > Signed-off-by: Miroslav Benes <mbenes@suse.cz>
> > > Signed-off-by: Song Liu <song@kernel.org>
> > >
> > > ---
> > >
> > > NOTE: powerpc code has not be tested.
> > >
> > > Changes v4 = v5:
> > > 1. Fix compile with powerpc.
> >
> > Not completely it seems.
> >
> >    CC      kernel/livepatch/core.o
> > kernel/livepatch/core.c: In function 'klp_clear_object_relocations':
> > kernel/livepatch/core.c:352:50: error: passing argument 1 of
> > 'clear_relocate_add' from incompatible pointer type
> > [-Werror=incompatible-pointer-types]
> >    352 |                 clear_relocate_add(pmod->klp_info->sechdrs,
> >        |                                    ~~~~~~~~~~~~~~^~~~~~~~~
> >        |                                                  |
> >        |                                                  Elf32_Shdr *
> > {aka struct elf32_shdr *}
> > In file included from kernel/livepatch/core.c:19:
> > ./include/linux/moduleloader.h:76:37: note: expected 'Elf64_Shdr *' {aka
> > 'struct elf64_shdr *'} but argument is of type 'Elf32_Shdr *' {aka
> > 'struct elf32_shdr *'}
> >     76 | void clear_relocate_add(Elf64_Shdr *sechdrs,
> >        |                         ~~~~~~~~~~~~^~~~~~~
> > cc1: some warnings being treated as errors
> >
> >
> > Fixup:
> >
> > diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
> > index d22b36b84b4b..958e6da7f475 100644
> > --- a/include/linux/moduleloader.h
> > +++ b/include/linux/moduleloader.h
> > @@ -73,7 +73,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs,
> >                        unsigned int relsec,
> >                        struct module *mod);
> >   #ifdef CONFIG_LIVEPATCH
> > -void clear_relocate_add(Elf64_Shdr *sechdrs,
> > +void clear_relocate_add(Elf_Shdr *sechdrs,
> >                    const char *strtab,
> >                    unsigned int symindex,
> >                    unsigned int relsec,
> >
> >
> > But then the link fails.
> >
> >    LD      .tmp_vmlinux.kallsyms1
> > powerpc64-linux-ld: kernel/livepatch/core.o: in function
> > `klp_cleanup_module_patches_limited':
> > core.c:(.text+0xdb4): undefined reference to `clear_relocate_add'
> 
> Hmm.. I am not seeing either error. Could you please share your .config file?
> 
> Thanks,
> Song
> 

If it's any help, I see the same build error Christophe reported using
the 'cross-dev' script that's in my klp-convert-tree [1].

  $ BUILD_ARCHES="ppc32" ./cross-dev config
  $ BUILD_ARCHES="ppc32" ./cross-dev build -j$(nproc)

(The kernel will be built in /tmp/klp-convert-ppc32 btw.)

Applying the header file fix results in the same linker error, too.


[1] https://github.com/joe-lawrence/klp-convert-tree/tree/klp-convert-v7-devel+song

-- Joe


WARNING: multiple messages have this Message-ID (diff)
From: Joe Lawrence <joe.lawrence@redhat.com>
To: Song Liu <song@kernel.org>
Cc: "pmladek@suse.com" <pmladek@suse.com>,
	"jikos@kernel.org" <jikos@kernel.org>,
	"x86@kernel.org" <x86@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	"live-patching@vger.kernel.org" <live-patching@vger.kernel.org>,
	"mbenes@suse.cz" <mbenes@suse.cz>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"jpoimboe@kernel.org" <jpoimboe@kernel.org>
Subject: Re: [PATCH v5] livepatch: Clear relocation targets on a module removal
Date: Wed, 31 Aug 2022 16:06:33 -0400	[thread overview]
Message-ID: <Yw+/SXhh5puipgmo@redhat.com> (raw)
In-Reply-To: <CAPhsuW6CwQoU0GsXj0YhxngFfNMgD1mu6AjwqiZumTyWL84i1g@mail.gmail.com>

On Wed, Aug 31, 2022 at 10:05:43AM -0700, Song Liu wrote:
> On Wed, Aug 31, 2022 at 1:01 AM Christophe Leroy
> <christophe.leroy@csgroup.eu> wrote:
> >
> >
> >
> > Le 30/08/2022 à 20:53, Song Liu a écrit :
> > > From: Miroslav Benes <mbenes@suse.cz>
> > >
> > > Josh reported a bug:
> > >
> > >    When the object to be patched is a module, and that module is
> > >    rmmod'ed and reloaded, it fails to load with:
> > >
> > >    module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 2, loc 00000000ba0302e9, val ffffffffa03e293c
> > >    livepatch: failed to initialize patch 'livepatch_nfsd' for module 'nfsd' (-8)
> > >    livepatch: patch 'livepatch_nfsd' failed for module 'nfsd', refusing to load module 'nfsd'
> > >
> > >    The livepatch module has a relocation which references a symbol
> > >    in the _previous_ loading of nfsd. When apply_relocate_add()
> > >    tries to replace the old relocation with a new one, it sees that
> > >    the previous one is nonzero and it errors out.
> > >
> > >    On ppc64le, we have a similar issue:
> > >
> > >    module_64: livepatch_nfsd: Expected nop after call, got e8410018 at e_show+0x60/0x548 [livepatch_nfsd]
> > >    livepatch: failed to initialize patch 'livepatch_nfsd' for module 'nfsd' (-8)
> > >    livepatch: patch 'livepatch_nfsd' failed for module 'nfsd', refusing to load module 'nfsd'
> > >
> > > He also proposed three different solutions. We could remove the error
> > > check in apply_relocate_add() introduced by commit eda9cec4c9a1
> > > ("x86/module: Detect and skip invalid relocations"). However the check
> > > is useful for detecting corrupted modules.
> > >
> > > We could also deny the patched modules to be removed. If it proved to be
> > > a major drawback for users, we could still implement a different
> > > approach. The solution would also complicate the existing code a lot.
> > >
> > > We thus decided to reverse the relocation patching (clear all relocation
> > > targets on x86_64). The solution is not
> > > universal and is too much arch-specific, but it may prove to be simpler
> > > in the end.
> > >
> > > Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > > Signed-off-by: Miroslav Benes <mbenes@suse.cz>
> > > Signed-off-by: Song Liu <song@kernel.org>
> > >
> > > ---
> > >
> > > NOTE: powerpc code has not be tested.
> > >
> > > Changes v4 = v5:
> > > 1. Fix compile with powerpc.
> >
> > Not completely it seems.
> >
> >    CC      kernel/livepatch/core.o
> > kernel/livepatch/core.c: In function 'klp_clear_object_relocations':
> > kernel/livepatch/core.c:352:50: error: passing argument 1 of
> > 'clear_relocate_add' from incompatible pointer type
> > [-Werror=incompatible-pointer-types]
> >    352 |                 clear_relocate_add(pmod->klp_info->sechdrs,
> >        |                                    ~~~~~~~~~~~~~~^~~~~~~~~
> >        |                                                  |
> >        |                                                  Elf32_Shdr *
> > {aka struct elf32_shdr *}
> > In file included from kernel/livepatch/core.c:19:
> > ./include/linux/moduleloader.h:76:37: note: expected 'Elf64_Shdr *' {aka
> > 'struct elf64_shdr *'} but argument is of type 'Elf32_Shdr *' {aka
> > 'struct elf32_shdr *'}
> >     76 | void clear_relocate_add(Elf64_Shdr *sechdrs,
> >        |                         ~~~~~~~~~~~~^~~~~~~
> > cc1: some warnings being treated as errors
> >
> >
> > Fixup:
> >
> > diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
> > index d22b36b84b4b..958e6da7f475 100644
> > --- a/include/linux/moduleloader.h
> > +++ b/include/linux/moduleloader.h
> > @@ -73,7 +73,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs,
> >                        unsigned int relsec,
> >                        struct module *mod);
> >   #ifdef CONFIG_LIVEPATCH
> > -void clear_relocate_add(Elf64_Shdr *sechdrs,
> > +void clear_relocate_add(Elf_Shdr *sechdrs,
> >                    const char *strtab,
> >                    unsigned int symindex,
> >                    unsigned int relsec,
> >
> >
> > But then the link fails.
> >
> >    LD      .tmp_vmlinux.kallsyms1
> > powerpc64-linux-ld: kernel/livepatch/core.o: in function
> > `klp_cleanup_module_patches_limited':
> > core.c:(.text+0xdb4): undefined reference to `clear_relocate_add'
> 
> Hmm.. I am not seeing either error. Could you please share your .config file?
> 
> Thanks,
> Song
> 

If it's any help, I see the same build error Christophe reported using
the 'cross-dev' script that's in my klp-convert-tree [1].

  $ BUILD_ARCHES="ppc32" ./cross-dev config
  $ BUILD_ARCHES="ppc32" ./cross-dev build -j$(nproc)

(The kernel will be built in /tmp/klp-convert-ppc32 btw.)

Applying the header file fix results in the same linker error, too.


[1] https://github.com/joe-lawrence/klp-convert-tree/tree/klp-convert-v7-devel+song

-- Joe


  parent reply	other threads:[~2022-08-31 20:06 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 18:53 [PATCH v5] livepatch: Clear relocation targets on a module removal Song Liu
2022-08-30 18:53 ` Song Liu
2022-08-31  8:01 ` Christophe Leroy
2022-08-31  8:01   ` Christophe Leroy
2022-08-31 17:05   ` Song Liu
2022-08-31 17:05     ` Song Liu
2022-08-31 17:16     ` Christophe Leroy
2022-08-31 17:16       ` Christophe Leroy
2022-08-31 20:06     ` Joe Lawrence [this message]
2022-08-31 20:06       ` Joe Lawrence
2022-08-31 19:38 ` Joe Lawrence
2022-08-31 19:38   ` Joe Lawrence
2022-08-31 22:30   ` Michael Ellerman
2022-08-31 22:30     ` Michael Ellerman
2022-08-31 22:48     ` Song Liu
2022-08-31 22:48       ` Song Liu
2022-09-01  2:05       ` Joe Lawrence
2022-09-01  2:05         ` Joe Lawrence
2022-09-01 17:03         ` Song Liu
2022-09-01 17:03           ` Song Liu
2022-09-01  2:46     ` Joe Lawrence
2022-09-01  2:46       ` Joe Lawrence
2022-09-01  3:39       ` Michael Ellerman
2022-09-01  3:39         ` Michael Ellerman
2022-09-01 12:42         ` Joe Lawrence
2022-09-01 12:42           ` Joe Lawrence
2022-09-08  2:22           ` Russell Currey

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=Yw+/SXhh5puipgmo@redhat.com \
    --to=joe.lawrence@redhat.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=jikos@kernel.org \
    --cc=jpoimboe@kernel.org \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=pmladek@suse.com \
    --cc=song@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.