anolis-cloud-kernel/kernel/livepatch
Wardenjohn 2738978bab livepatch,x86: Clear relocation targets on a module removal
ANBZ: #11304

commit 0c05e7bd2d upstream

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.

    He also proposed three different solutions. We could remove the error
    check in apply_relocate_add() introduced by commit eda9cec4c9
    ("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>
    Originally-by: Miroslav Benes <mbenes@suse.cz>
    Signed-off-by: Song Liu <song@kernel.org>
    Acked-by: Miroslav Benes <mbenes@suse.cz>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
    Reviewed-by: Joe Lawrence <joe.lawrence@redhat.com>
    Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230125185401.279042-2-song@kernel.org
    Signed-off-by: Wardenjohn <ydzhang@linux.alibaba.com>
    Tested-by: Wardenjohn <ydzhang@linux.alibaba.com>

commit bbb93362a4 upstream

x86/module: remove unused code in __apply_relocate_add

    This "#if 0" block has been untouched for many years. Remove it to clean
    up the code.

    Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Song Liu <song@kernel.org>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
    Reviewed-by: Joe Lawrence <joe.lawrence@redhat.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230125185401.279042-1-song@kernel.org
    Signed-off-by: Wardenjohn <ydzhang@linux.alibaba.com>
    Tested-by: Wardenjohn <ydzhang@linux.alibaba.com>
Acked-by: Zelin Deng <zelin.deng@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/3987
2024-10-17 03:05:34 +00:00
..
Kconfig livepatch: Use the default ftrace_ops instead of REGS when ARGS is available 2024-02-01 13:23:07 +00:00
Makefile livepatch: Basic API to track system state changes 2019-11-01 13:08:14 +01:00
core.c livepatch,x86: Clear relocation targets on a module removal 2024-10-17 03:05:34 +00:00
core.h livepatch: Keep replaced patches until post_patch callback is called 2019-11-01 13:08:08 +01:00
patch.c ftrace: arm64: move from REGS to ARGS 2024-03-01 07:25:29 +00:00
patch.h livepatch: Remove Nop structures when unused 2019-01-11 20:51:24 +01:00
shadow.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 13 2019-05-21 11:28:45 +02:00
state.c kernel/: fix repeated words in comments 2020-10-16 11:11:19 -07:00
state.h livepatch: Allow to distinguish different version of system state changes 2019-11-01 13:08:19 +01:00
transition.c ck: livepatch: fix stack check when disabling patch 2022-08-01 11:31:05 +00:00
transition.h ck: livepatch: introduce stop machine consistency model 2022-08-01 11:16:09 +00:00