19 Aug, 2016

1 commit


17 May, 2016

1 commit


30 Apr, 2016

1 commit

  • Current object-walking helper checks the presence of obj->funcs to
    determine the end of objs array in klp_object structure. This is
    somewhat fragile because one can easily forget about funcs definition
    during livepatch creation. In such a case the livepatch module is
    successfully loaded and all objects after the incorrect one are omitted.
    This is very confusing. Let's make the helper more robust and check also
    for the other external member, name. Thus the helper correctly stops on
    an empty item of the array. We need to have a check for obj->funcs in
    klp_init_object() to make it work.

    The same applies to a func-walking helper.

    As a benefit we'll check for new_func member definition during the
    livepatch initialization. There is no such check anywhere in the code
    now.

    [jkosina@suse.cz: fix shortlog]
    Signed-off-by: Miroslav Benes
    Acked-by: Josh Poimboeuf
    Acked-by: Jessica Yu
    Signed-off-by: Jiri Kosina

    Miroslav Benes
     

01 Apr, 2016

1 commit

  • Reuse module loader code to write relocations, thereby eliminating the need
    for architecture specific relocation code in livepatch. Specifically, reuse
    the apply_relocate_add() function in the module loader to write relocations
    instead of duplicating functionality in livepatch's arch-dependent
    klp_write_module_reloc() function.

    In order to accomplish this, livepatch modules manage their own relocation
    sections (marked with the SHF_RELA_LIVEPATCH section flag) and
    livepatch-specific symbols (marked with SHN_LIVEPATCH symbol section
    index). To apply livepatch relocation sections, livepatch symbols
    referenced by relocs are resolved and then apply_relocate_add() is called
    to apply those relocations.

    In addition, remove x86 livepatch relocation code and the s390
    klp_write_module_reloc() function stub. They are no longer needed since
    relocation work has been offloaded to module loader.

    Lastly, mark the module as a livepatch module so that the module loader
    canappropriately identify and initialize it.

    Signed-off-by: Jessica Yu
    Reviewed-by: Miroslav Benes
    Acked-by: Josh Poimboeuf
    Acked-by: Heiko Carstens # for s390 changes
    Signed-off-by: Jiri Kosina

    Jessica Yu
     

17 Mar, 2016

1 commit

  • Remove the livepatch module notifier in favor of directly enabling and
    disabling patches to modules in the module loader. Hard-coding the
    function calls ensures that ftrace_module_enable() is run before
    klp_module_coming() during module load, and that klp_module_going() is
    run before ftrace_release_mod() during module unload. This way, ftrace
    and livepatch code is run in the correct order during the module
    load/unload sequence without dependence on the module notifier call chain.

    Signed-off-by: Jessica Yu
    Reviewed-by: Petr Mladek
    Acked-by: Josh Poimboeuf
    Acked-by: Rusty Russell
    Signed-off-by: Jiri Kosina

    Jessica Yu
     

07 Mar, 2016

1 commit


04 Dec, 2015

2 commits

  • In cases of duplicate symbols, sympos will be used to disambiguate instead
    of val. By default sympos will be 0, and patching will only succeed if
    the symbol is unique. Specifying a positive value will ensure that
    occurrence of the symbol in kallsyms for the patched object will be used
    for patching if it is valid. For external relocations sympos is not
    supported.

    Remove klp_verify_callback, klp_verify_args and klp_verify_vmlinux_symbol
    as they are no longer used.

    From the klp_reloc structure remove val, as it can be refactored as a
    local variable in klp_write_object_relocations.

    Signed-off-by: Chris J Arges
    Reviewed-by: Petr Mladek
    Acked-by: Josh Poimboeuf
    Signed-off-by: Jiri Kosina

    Chris J Arges
     
  • Currently, patching objects with duplicate symbol names fail because the
    creation of the sysfs function directory collides with the previous
    attempt. Appending old_addr to the function name is problematic as it
    reveals the address of the function being patch to a normal user. Using
    the symbol's occurrence in kallsyms to postfix the function name in the
    sysfs directory solves the issue of having consistent unique names and
    ensuring that the address is not exposed to a normal user.

    In addition, using the symbol position as the user's method to disambiguate
    symbols instead of addr allows for disambiguating symbols in modules as
    well for both function addresses and for relocs. This also simplifies much
    of the code. Special handling for kASLR is no longer needed and can be
    removed. The klp_find_verify_func_addr function can be replaced by
    klp_find_object_symbol, and klp_verify_vmlinux_symbol and its callback can
    be removed completely.

    In cases of duplicate symbols, old_sympos will be used to disambiguate
    instead of old_addr. By default old_sympos will be 0, and patching will
    only succeed if the symbol is unique. Specifying a positive value will
    ensure that occurrence of the symbol in kallsyms for the patched object
    will be used for patching if it is valid.

    In addition, make old_addr an internal structure field not to be specified
    by the user. Finally, remove klp_find_verify_func_addr as it can be
    replaced by klp_find_object_symbol directly.

    Support for symbol position disambiguation for relocations is added in the
    next patch in this series.

    Signed-off-by: Chris J Arges
    Reviewed-by: Petr Mladek
    Acked-by: Josh Poimboeuf
    Signed-off-by: Jiri Kosina

    Chris J Arges
     

20 May, 2015

2 commits

  • klp_for_each_object and klp_for_each_func are now used all over the
    code. One need not think what is the proper condition to check in the
    for loop now.

    Signed-off-by: Jiri Slaby
    Acked-by: Josh Poimboeuf
    Signed-off-by: Jiri Kosina

    Jiri Slaby
     
  • Make kobj variable (of type struct kobject) statically allocated in
    klp_object structure. It will allow us to move in the func-object-patch
    hierarchy through kobject links.

    The only reason to have it dynamic was to not have empty release
    callback in the code. However we have empty callbacks for function and
    patch in the code now, so it is no longer valid and the advantage of
    static allocation is clear.

    Signed-off-by: Miroslav Benes
    Signed-off-by: Jiri Slaby
    Acked-by: Josh Poimboeuf
    Signed-off-by: Jiri Kosina

    Miroslav Benes
     

19 Feb, 2015

1 commit


04 Feb, 2015

1 commit


21 Jan, 2015

1 commit

  • Add support for patching a function multiple times. If multiple patches
    affect a function, the function in the most recently enabled patch
    "wins". This enables a cumulative patch upgrade path, where each patch
    is a superset of previous patches.

    This requires restructuring the data a little bit. With the current
    design, where each klp_func struct has its own ftrace_ops, we'd have to
    unregister the old ops and then register the new ops, because
    FTRACE_OPS_FL_IPMODIFY prevents us from having two ops registered for
    the same function at the same time. That would leave a regression
    window where the function isn't patched at all (not good for a patch
    upgrade path).

    This patch replaces the per-klp_func ftrace_ops with a global klp_ops
    list, with one ftrace_ops per original function. A single ftrace_ops is
    shared between all klp_funcs which have the same old_addr. This allows
    the switch between function versions to happen instantaneously by
    updating the klp_ops struct's func_stack list. The winner is the
    klp_func at the top of the func_stack (front of the list).

    [ jkosina@suse.cz: turn WARN_ON() into WARN_ON_ONCE() in ftrace handler to
    avoid storm in pathological cases ]

    Signed-off-by: Josh Poimboeuf
    Reviewed-by: Jiri Slaby
    Signed-off-by: Jiri Kosina

    Josh Poimboeuf
     

22 Dec, 2014

1 commit

  • This commit introduces code for the live patching core. It implements
    an ftrace-based mechanism and kernel interface for doing live patching
    of kernel and kernel module functions.

    It represents the greatest common functionality set between kpatch and
    kgraft and can accept patches built using either method.

    This first version does not implement any consistency mechanism that
    ensures that old and new code do not run together. In practice, ~90% of
    CVEs are safe to apply in this way, since they simply add a conditional
    check. However, any function change that can not execute safely with
    the old version of the function can _not_ be safely applied in this
    version.

    [ jkosina@suse.cz: due to the number of contributions that got folded into
    this original patch from Seth Jennings, add SUSE's copyright as well, as
    discussed via e-mail ]

    Signed-off-by: Seth Jennings
    Signed-off-by: Josh Poimboeuf
    Reviewed-by: Miroslav Benes
    Reviewed-by: Petr Mladek
    Reviewed-by: Masami Hiramatsu
    Signed-off-by: Miroslav Benes
    Signed-off-by: Petr Mladek
    Signed-off-by: Jiri Kosina

    Seth Jennings