08 Apr, 2022

1 commit

  • [ Upstream commit 2f293651eca3eacaeb56747dede31edace7329d2 ]

    Trying to build livepatch on powerpc/32 results in:

    kernel/livepatch/core.c: In function 'klp_resolve_symbols':
    kernel/livepatch/core.c:221:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
    221 | sym = (Elf64_Sym *)sechdrs[symndx].sh_addr + ELF_R_SYM(relas[i].r_info);
    | ^
    kernel/livepatch/core.c:221:21: error: assignment to 'Elf32_Sym *' {aka 'struct elf32_sym *'} from incompatible pointer type 'Elf64_Sym *' {aka 'struct elf64_sym *'} [-Werror=incompatible-pointer-types]
    221 | sym = (Elf64_Sym *)sechdrs[symndx].sh_addr + ELF_R_SYM(relas[i].r_info);
    | ^
    kernel/livepatch/core.c: In function 'klp_apply_section_relocs':
    kernel/livepatch/core.c:312:35: error: passing argument 1 of 'klp_resolve_symbols' from incompatible pointer type [-Werror=incompatible-pointer-types]
    312 | ret = klp_resolve_symbols(sechdrs, strtab, symndx, sec, sec_objname);
    | ^~~~~~~
    | |
    | Elf32_Shdr * {aka struct elf32_shdr *}
    kernel/livepatch/core.c:193:44: note: expected 'Elf64_Shdr *' {aka 'struct elf64_shdr *'} but argument is of type 'Elf32_Shdr *' {aka 'struct elf32_shdr *'}
    193 | static int klp_resolve_symbols(Elf64_Shdr *sechdrs, const char *strtab,
    | ~~~~~~~~~~~~^~~~~~~

    Fix it by using the right types instead of forcing 64 bits types.

    Fixes: 7c8e2bdd5f0d ("livepatch: Apply vmlinux-specific KLP relocations early")
    Signed-off-by: Christophe Leroy
    Acked-by: Petr Mladek
    Acked-by: Joe Lawrence
    Acked-by: Miroslav Benes
    Signed-off-by: Michael Ellerman
    Link: https://lore.kernel.org/r/5288e11b018a762ea3351cc8fb2d4f15093a4457.1640017960.git.christophe.leroy@csgroup.eu
    Signed-off-by: Sasha Levin

    Christophe Leroy
     

19 Aug, 2021

1 commit

  • The functions get_online_cpus() and put_online_cpus() have been
    deprecated during the CPU hotplug rework. They map directly to
    cpus_read_lock() and cpus_read_unlock().

    Replace deprecated CPU-hotplug functions with the official version.
    The behavior remains unchanged.

    Cc: Josh Poimboeuf
    Cc: Jiri Kosina
    Cc: Miroslav Benes
    Cc: Petr Mladek
    Cc: Joe Lawrence
    Cc: live-patching@vger.kernel.org
    Signed-off-by: Sebastian Andrzej Siewior
    Reviewed-by: Petr Mladek
    Signed-off-by: Jiri Kosina

    Sebastian Andrzej Siewior
     

28 Apr, 2021

1 commit


30 Mar, 2021

1 commit

  • Livepatch sends a fake signal to all remaining blocking tasks of a
    running transition after a set period of time. It uses TIF_SIGPENDING
    flag for the purpose. Commit 12db8b690010 ("entry: Add support for
    TIF_NOTIFY_SIGNAL") added a generic infrastructure to achieve the same.
    Replace our bespoke solution with the generic one.

    Reviewed-by: Jens Axboe
    Reviewed-by: Petr Mladek
    Acked-by: Joe Lawrence
    Signed-off-by: Miroslav Benes
    Signed-off-by: Jiri Kosina

    Miroslav Benes
     

08 Feb, 2021

2 commits

  • Require an explicit call to module_kallsyms_on_each_symbol to look
    for symbols in modules instead of the call from kallsyms_on_each_symbol,
    and acquire module_mutex inside of module_kallsyms_on_each_symbol instead
    of leaving that up to the caller. Note that this slightly changes the
    behavior for the livepatch code in that the symbols from vmlinux are not
    iterated anymore if objname is set, but that actually is the desired
    behavior in this case.

    Reviewed-by: Petr Mladek
    Acked-by: Miroslav Benes
    Signed-off-by: Christoph Hellwig
    Signed-off-by: Jessica Yu

    Christoph Hellwig
     
  • Allow for a RCU-sched critical section around find_module, following
    the lower level find_module_all helper, and switch the two callers
    outside of module.c to use such a RCU-sched critical section instead
    of module_mutex.

    Reviewed-by: Petr Mladek
    Acked-by: Miroslav Benes
    Signed-off-by: Christoph Hellwig
    Signed-off-by: Jessica Yu

    Christoph Hellwig
     

14 Nov, 2020

2 commits

  • When CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS is available, the ftrace call
    will be able to set the ip of the calling function. This will improve the
    performance of live kernel patching where it does not need all the regs to
    be stored just to change the instruction pointer.

    If all archs that support live kernel patching also support
    HAVE_DYNAMIC_FTRACE_WITH_ARGS, then the architecture specific function
    klp_arch_set_pc() could be made generic.

    It is possible that an arch can support HAVE_DYNAMIC_FTRACE_WITH_ARGS but
    not HAVE_DYNAMIC_FTRACE_WITH_REGS and then have access to live patching.

    Cc: Josh Poimboeuf
    Cc: Jiri Kosina
    Cc: live-patching@vger.kernel.org
    Acked-by: Peter Zijlstra (Intel)
    Acked-by: Miroslav Benes
    Signed-off-by: Steven Rostedt (VMware)

    Steven Rostedt (VMware)
     
  • In preparation to have arguments of a function passed to callbacks attached
    to functions as default, change the default callback prototype to receive a
    struct ftrace_regs as the forth parameter instead of a pt_regs.

    For callbacks that set the FL_SAVE_REGS flag in their ftrace_ops flags, they
    will now need to get the pt_regs via a ftrace_get_regs() helper call. If
    this is called by a callback that their ftrace_ops did not have a
    FL_SAVE_REGS flag set, it that helper function will return NULL.

    This will allow the ftrace_regs to hold enough just to get the parameters
    and stack pointer, but without the worry that callbacks may have a pt_regs
    that is not completely filled.

    Acked-by: Peter Zijlstra (Intel)
    Reviewed-by: Masami Hiramatsu
    Signed-off-by: Steven Rostedt (VMware)

    Steven Rostedt (VMware)
     

06 Nov, 2020

3 commits

  • This adds CONFIG_FTRACE_RECORD_RECURSION that will record to a file
    "recursed_functions" all the functions that caused recursion while a
    callback to the function tracer was running.

    Link: https://lkml.kernel.org/r/20201106023548.102375687@goodmis.org

    Cc: Masami Hiramatsu
    Cc: Andrew Morton
    Cc: Peter Zijlstra
    Cc: Ingo Molnar
    Cc: Jonathan Corbet
    Cc: Guo Ren
    Cc: "James E.J. Bottomley"
    Cc: Helge Deller
    Cc: Michael Ellerman
    Cc: Benjamin Herrenschmidt
    Cc: Paul Mackerras
    Cc: Heiko Carstens
    Cc: Vasily Gorbik
    Cc: Christian Borntraeger
    Cc: Thomas Gleixner
    Cc: Borislav Petkov
    Cc: x86@kernel.org
    Cc: "H. Peter Anvin"
    Cc: Kees Cook
    Cc: Anton Vorontsov
    Cc: Colin Cross
    Cc: Tony Luck
    Cc: Josh Poimboeuf
    Cc: Jiri Kosina
    Cc: Miroslav Benes
    Cc: Petr Mladek
    Cc: Joe Lawrence
    Cc: Kamalesh Babulal
    Cc: Mauro Carvalho Chehab
    Cc: Sebastian Andrzej Siewior
    Cc: linux-doc@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Cc: linux-csky@vger.kernel.org
    Cc: linux-parisc@vger.kernel.org
    Cc: linuxppc-dev@lists.ozlabs.org
    Cc: linux-s390@vger.kernel.org
    Cc: live-patching@vger.kernel.org
    Signed-off-by: Steven Rostedt (VMware)

    Steven Rostedt (VMware)
     
  • If for some reason a function is called that triggers the recursion
    detection of live patching, trigger a warning. By not executing the live
    patch code, it is possible that the old unpatched function will be called
    placing the system into an unknown state.

    Link: https://lore.kernel.org/r/20201029145709.GD16774@alley
    Link: https://lkml.kernel.org/r/20201106023547.312639435@goodmis.org

    Cc: Masami Hiramatsu
    Cc: Andrew Morton
    Cc: Peter Zijlstra
    Cc: Ingo Molnar
    Cc: Josh Poimboeuf
    Cc: Jiri Kosina
    Cc: Joe Lawrence
    Cc: live-patching@vger.kernel.org
    Suggested-by: Miroslav Benes
    Reviewed-by: Petr Mladek
    Acked-by: Miroslav Benes
    Signed-off-by: Steven Rostedt (VMware)

    Steven Rostedt (VMware)
     
  • If a ftrace callback does not supply its own recursion protection and
    does not set the RECURSION_SAFE flag in its ftrace_ops, then ftrace will
    make a helper trampoline to do so before calling the callback instead of
    just calling the callback directly.

    The default for ftrace_ops is going to change. It will expect that handlers
    provide their own recursion protection, unless its ftrace_ops states
    otherwise.

    Link: https://lkml.kernel.org/r/20201028115613.291169246@goodmis.org
    Link: https://lkml.kernel.org/r/20201106023547.122802424@goodmis.org

    Cc: Peter Zijlstra
    Cc: Ingo Molnar
    Cc: Masami Hiramatsu
    Cc: Andrew Morton
    Cc: Josh Poimboeuf
    Cc: Jiri Kosina
    Cc: Joe Lawrence
    Cc: live-patching@vger.kernel.org
    Reviewed-by: Petr Mladek
    Acked-by: Miroslav Benes
    Signed-off-by: Steven Rostedt (VMware)

    Steven Rostedt (VMware)
     

17 Oct, 2020

1 commit

  • Fix multiple occurrences of duplicated words in kernel/.

    Fix one typo/spello on the same line as a duplicate word. Change one
    instance of "the the" to "that the". Otherwise just drop one of the
    repeated words.

    Signed-off-by: Randy Dunlap
    Signed-off-by: Andrew Morton
    Link: https://lkml.kernel.org/r/98202fa6-8919-ef63-9efe-c0fad5ca7af1@infradead.org
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

11 May, 2020

1 commit

  • Fix the following sparse warning:

    kernel/livepatch/core.c:748:5: warning: symbol 'klp_apply_object_relocs' was
    not declared.

    The klp_apply_object_relocs() has only one call site within core.c;
    it should be static

    Fixes: 7c8e2bdd5f0d ("livepatch: Apply vmlinux-specific KLP relocations early")
    Reported-by: Hulk Robot
    Signed-off-by: Samuel Zou
    Acked-by: Josh Poimboeuf
    Signed-off-by: Jiri Kosina

    Samuel Zou
     

08 May, 2020

6 commits

  • Now that the livepatch code no longer needs the text_mutex for changing
    module permissions, move its usage down to apply_relocate_add().

    Note the s390 version of apply_relocate_add() doesn't need to use the
    text_mutex because it already uses s390_kernel_write_lock, which
    accomplishes the same task.

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

    Josh Poimboeuf
     
  • With arch_klp_init_object_loaded() gone, and apply_relocate_add() now
    using text_poke(), livepatch no longer needs to use module_disable_ro().

    Signed-off-by: Josh Poimboeuf
    Acked-by: Peter Zijlstra (Intel)
    Acked-by: Joe Lawrence
    Acked-by: Miroslav Benes
    Signed-off-by: Jiri Kosina

    Josh Poimboeuf
     
  • Prevent module-specific KLP rela sections from referencing vmlinux
    symbols. This helps prevent ordering issues with module special section
    initializations. Presumably such symbols are exported and normal relas
    can be used instead.

    Suggested-by: Peter Zijlstra
    Signed-off-by: Josh Poimboeuf
    Acked-by: Peter Zijlstra (Intel)
    Acked-by: Joe Lawrence
    Acked-by: Miroslav Benes
    Signed-off-by: Jiri Kosina

    Josh Poimboeuf
     
  • After the previous patch, vmlinux-specific KLP relocations are now
    applied early during KLP module load. This means that .klp.arch
    sections are no longer needed for *vmlinux-specific* KLP relocations.

    One might think they're still needed for *module-specific* KLP
    relocations. If a to-be-patched module is loaded *after* its
    corresponding KLP module is loaded, any corresponding KLP relocations
    will be delayed until the to-be-patched module is loaded. If any
    special sections (.parainstructions, for example) rely on those
    relocations, their initializations (apply_paravirt) need to be done
    afterwards. Thus the apparent need for arch_klp_init_object_loaded()
    and its corresponding .klp.arch sections -- it allows some of the
    special section initializations to be done at a later time.

    But... if you look closer, that dependency between the special sections
    and the module-specific KLP relocations doesn't actually exist in
    reality. Looking at the contents of the .altinstructions and
    .parainstructions sections, there's not a realistic scenario in which a
    KLP module's .altinstructions or .parainstructions section needs to
    access a symbol in a to-be-patched module. It might need to access a
    local symbol or even a vmlinux symbol; but not another module's symbol.
    When a special section needs to reference a local or vmlinux symbol, a
    normal rela can be used instead of a KLP rela.

    Since the special section initializations don't actually have any real
    dependency on module-specific KLP relocations, .klp.arch and
    arch_klp_init_object_loaded() no longer have a reason to exist. So
    remove them.

    As Peter said much more succinctly:

    So the reason for .klp.arch was that .klp.rela.* stuff would overwrite
    paravirt instructions. If that happens you're doing it wrong. Those
    RELAs are core kernel, not module, and thus should've happened in
    .rela.* sections at patch-module loading time.

    Reverting this removes the two apply_{paravirt,alternatives}() calls
    from the late patching path, and means we don't have to worry about
    them when removing module_disable_ro().

    [ jpoimboe: Rewrote patch description. Tweaked klp_init_object_loaded()
    error path. ]

    Signed-off-by: Peter Zijlstra (Intel)
    Signed-off-by: Josh Poimboeuf
    Acked-by: Peter Zijlstra (Intel)
    Acked-by: Joe Lawrence
    Acked-by: Miroslav Benes
    Signed-off-by: Jiri Kosina

    Peter Zijlstra
     
  • KLP relocations are livepatch-specific relocations which are applied to
    a KLP module's text or data. They exist for two reasons:

    1) Unexported symbols: replacement functions often need to access
    unexported symbols (e.g. static functions), which "normal"
    relocations don't allow.

    2) Late module patching: this is the ability for a KLP module to
    bypass normal module dependencies, such that the KLP module can be
    loaded *before* a to-be-patched module. This means that
    relocations which need to access symbols in the to-be-patched
    module might need to be applied to the KLP module well after it has
    been loaded.

    Non-late-patched KLP relocations are applied from the KLP module's init
    function. That usually works fine, unless the patched code wants to use
    alternatives, paravirt patching, jump tables, or some other special
    section which needs relocations. Then we run into ordering issues and
    crashes.

    In order for those special sections to work properly, the KLP
    relocations should be applied *before* the special section init code
    runs, such as apply_paravirt(), apply_alternatives(), or
    jump_label_apply_nops().

    You might think the obvious solution would be to move the KLP relocation
    initialization earlier, but it's not necessarily that simple. The
    problem is the above-mentioned late module patching, for which KLP
    relocations can get applied well after the KLP module is loaded.

    To "fix" this issue in the past, we created .klp.arch sections:

    .klp.arch.{module}..altinstructions
    .klp.arch.{module}..parainstructions

    Those sections allow KLP late module patching code to call
    apply_paravirt() and apply_alternatives() after the module-specific KLP
    relocations (.klp.rela.{module}.{section}) have been applied.

    But that has a lot of drawbacks, including code complexity, the need for
    arch-specific code, and the (per-arch) danger that we missed some
    special section -- for example the __jump_table section which is used
    for jump labels.

    It turns out there's a simpler and more functional approach. There are
    two kinds of KLP relocation sections:

    1) vmlinux-specific KLP relocation sections

    .klp.rela.vmlinux.{sec}

    These are relocations (applied to the KLP module) which reference
    unexported vmlinux symbols.

    2) module-specific KLP relocation sections

    .klp.rela.{module}.{sec}:

    These are relocations (applied to the KLP module) which reference
    unexported or exported module symbols.

    Up until now, these have been treated the same. However, they're
    inherently different.

    Because of late module patching, module-specific KLP relocations can be
    applied very late, thus they can create the ordering headaches described
    above.

    But vmlinux-specific KLP relocations don't have that problem. There's
    nothing to prevent them from being applied earlier. So apply them at
    the same time as normal relocations, when the KLP module is being
    loaded.

    This means that for vmlinux-specific KLP relocations, we no longer have
    any ordering issues. vmlinux-referencing jump labels, alternatives, and
    paravirt patching will work automatically, without the need for the
    .klp.arch hacks.

    All that said, for module-specific KLP relocations, the ordering
    problems still exist and we *do* still need .klp.arch. Or do we? Stay
    tuned.

    Suggested-by: Peter Zijlstra
    Signed-off-by: Josh Poimboeuf
    Acked-by: Peter Zijlstra (Intel)
    Acked-by: Joe Lawrence
    Acked-by: Miroslav Benes
    Acked-by: Jessica Yu
    Signed-off-by: Jiri Kosina

    Josh Poimboeuf
     
  • This is purely a theoretical issue, but if there were a module named
    vmlinux.ko, the livepatch relocation code wouldn't be able to
    distinguish between vmlinux-specific and vmlinux.o-specific KLP
    relocations.

    If CONFIG_LIVEPATCH is enabled, don't allow a module named vmlinux.ko.

    Suggested-by: Peter Zijlstra
    Signed-off-by: Josh Poimboeuf
    Acked-by: Miroslav Benes
    Acked-by: Joe Lawrence
    Signed-off-by: Jiri Kosina

    Josh Poimboeuf
     

28 Nov, 2019

1 commit

  • Pull tracing updates from Steven Rostedt:
    "New tracing features:

    - New PERMANENT flag to ftrace_ops when attaching a callback to a
    function.

    As /proc/sys/kernel/ftrace_enabled when set to zero will disable
    all attached callbacks in ftrace, this has a detrimental impact on
    live kernel tracing, as it disables all that it patched. If a
    ftrace_ops is registered to ftrace with the PERMANENT flag set, it
    will prevent ftrace_enabled from being disabled, and if
    ftrace_enabled is already disabled, it will prevent a ftrace_ops
    with PREMANENT flag set from being registered.

    - New register_ftrace_direct().

    As eBPF would like to register its own trampolines to be called by
    the ftrace nop locations directly, without going through the ftrace
    trampoline, this function has been added. This allows for eBPF
    trampolines to live along side of ftrace, perf, kprobe and live
    patching. It also utilizes the ftrace enabled_functions file that
    keeps track of functions that have been modified in the kernel, to
    allow for security auditing.

    - Allow for kernel internal use of ftrace instances.

    Subsystems in the kernel can now create and destroy their own
    tracing instances which allows them to have their own tracing
    buffer, and be able to record events without worrying about other
    users from writing over their data.

    - New seq_buf_hex_dump() that lets users use the hex_dump() in their
    seq_buf usage.

    - Notifications now added to tracing_max_latency to allow user space
    to know when a new max latency is hit by one of the latency
    tracers.

    - Wider spread use of generic compare operations for use of bsearch
    and friends.

    - More synthetic event fields may be defined (32 up from 16)

    - Use of xarray for architectures with sparse system calls, for the
    system call trace events.

    This along with small clean ups and fixes"

    * tag 'trace-v5.5' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (51 commits)
    tracing: Enable syscall optimization for MIPS
    tracing: Use xarray for syscall trace events
    tracing: Sample module to demonstrate kernel access to Ftrace instances.
    tracing: Adding new functions for kernel access to Ftrace instances
    tracing: Fix Kconfig indentation
    ring-buffer: Fix typos in function ring_buffer_producer
    ftrace: Use BIT() macro
    ftrace: Return ENOTSUPP when DYNAMIC_FTRACE_WITH_DIRECT_CALLS is not configured
    ftrace: Rename ftrace_graph_stub to ftrace_stub_graph
    ftrace: Add a helper function to modify_ftrace_direct() to allow arch optimization
    ftrace: Add helper find_direct_entry() to consolidate code
    ftrace: Add another check for match in register_ftrace_direct()
    ftrace: Fix accounting bug with direct->count in register_ftrace_direct()
    ftrace/selftests: Fix spelling mistake "wakeing" -> "waking"
    tracing: Increase SYNTH_FIELDS_MAX for synthetic_events
    ftrace/samples: Add a sample module that implements modify_ftrace_direct()
    ftrace: Add modify_ftrace_direct()
    tracing: Add missing "inline" in stub function of latency_fsnotify()
    tracing: Remove stray tab in TRACE_EVAL_MAP_FILE's help text
    tracing: Use seq_buf_hex_dump() to dump buffers
    ...

    Linus Torvalds
     

04 Nov, 2019

1 commit

  • Livepatch uses ftrace for redirection to new patched functions. It means
    that if ftrace is disabled, all live patched functions are disabled as
    well. Toggling global 'ftrace_enabled' sysctl thus affect it directly.
    It is not a problem per se, because only administrator can set sysctl
    values, but it still may be surprising.

    Introduce PERMANENT ftrace_ops flag to amend this. If the
    FTRACE_OPS_FL_PERMANENT is set on any ftrace ops, the tracing cannot be
    disabled by disabling ftrace_enabled. Equally, a callback with the flag
    set cannot be registered if ftrace_enabled is disabled.

    Link: http://lkml.kernel.org/r/20191016113316.13415-2-mbenes@suse.cz

    Reviewed-by: Petr Mladek
    Reviewed-by: Kamalesh Babulal
    Signed-off-by: Miroslav Benes
    Signed-off-by: Steven Rostedt (VMware)

    Miroslav Benes
     

01 Nov, 2019

3 commits

  • The atomic replace runs pre/post (un)install callbacks only from the new
    livepatch. There are several reasons for this:

    + Simplicity: clear ordering of operations, no interactions between
    old and new callbacks.

    + Reliability: only new livepatch knows what changes can already be made
    by older livepatches and how to take over the state.

    + Testing: the atomic replace can be properly tested only when a newer
    livepatch is available. It might be too late to fix unwanted effect
    of callbacks from older livepatches.

    It might happen that an older change is not enough and the same system
    state has to be modified another way. Different changes need to get
    distinguished by a version number added to struct klp_state.

    The version can also be used to prevent loading incompatible livepatches.
    The check is done when the livepatch is enabled. The rules are:

    + Any completely new system state modification is allowed.

    + System state modifications with the same or higher version are allowed
    for already modified system states.

    + Cumulative livepatches must handle all system state modifications from
    already installed livepatches.

    + Non-cumulative livepatches are allowed to touch already modified
    system states.

    Link: http://lkml.kernel.org/r/20191030154313.13263-4-pmladek@suse.com
    To: Jiri Kosina
    Cc: Kamalesh Babulal
    Cc: Nicolai Stange
    Cc: live-patching@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Acked-by: Miroslav Benes
    Acked-by: Joe Lawrence
    Acked-by: Josh Poimboeuf
    Signed-off-by: Petr Mladek

    Petr Mladek
     
  • This is another step how to help maintaining more livepatches.

    One big help was the atomic replace and cumulative livepatches. These
    livepatches replace the already installed ones. Therefore it should
    be enough when each cumulative livepatch is consistent.

    The problems might come with shadow variables and callbacks. They might
    change the system behavior or state so that it is no longer safe to
    go back and use an older livepatch or the original kernel code. Also,
    a new livepatch must be able to detect changes which were made by
    the already installed livepatches.

    This is where the livepatch system state tracking gets useful. It
    allows to:

    - find whether a system state has already been modified by
    previous livepatches

    - store data needed to manipulate and restore the system state

    The information about the manipulated system states is stored in an
    array of struct klp_state. It can be searched by two new functions
    klp_get_state() and klp_get_prev_state().

    The dependencies are going to be solved by a version field added later.
    The only important information is that it will be allowed to modify
    the same state by more non-cumulative livepatches. It is similar
    to allowing to modify the same function several times. The livepatch
    author is responsible for preventing incompatible changes.

    Link: http://lkml.kernel.org/r/20191030154313.13263-3-pmladek@suse.com
    To: Jiri Kosina
    Cc: Kamalesh Babulal
    Cc: Nicolai Stange
    Cc: live-patching@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Acked-by: Miroslav Benes
    Acked-by: Joe Lawrence
    Acked-by: Josh Poimboeuf
    Signed-off-by: Petr Mladek

    Petr Mladek
     
  • Pre/post (un)patch callbacks might manipulate the system state. Cumulative
    livepatches might need to take over the changes made by the replaced
    ones. For this they might need to access some data stored or referenced
    by the old livepatches.

    Therefore the replaced livepatches have to stay around until post_patch()
    callback is called. It is achieved by calling the free functions later.
    It is the same location where disabled livepatches have already been
    freed.

    Link: http://lkml.kernel.org/r/20191030154313.13263-2-pmladek@suse.com
    To: Jiri Kosina
    Cc: Kamalesh Babulal
    Cc: Nicolai Stange
    Cc: live-patching@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Acked-by: Miroslav Benes
    Acked-by: Joe Lawrence
    Acked-by: Josh Poimboeuf
    Signed-off-by: Petr Mladek

    Petr Mladek
     

19 Aug, 2019

1 commit

  • klp_module_coming() is called for every module appearing in the system.
    It sets obj->mod to a patched module for klp_object obj. Unfortunately
    it leaves it set even if an error happens later in the function and the
    patched module is not allowed to be loaded.

    klp_is_object_loaded() uses obj->mod variable and could currently give a
    wrong return value. The bug is probably harmless as of now.

    Signed-off-by: Miroslav Benes
    Reviewed-by: Petr Mladek
    Acked-by: Josh Poimboeuf
    Signed-off-by: Petr Mladek

    Miroslav Benes
     

12 Jul, 2019

1 commit

  • Pull livepatching updates from Jiri Kosina:

    - stacktrace handling improvements from Miroslav benes

    - debug output improvements from Petr Mladek

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching:
    livepatch: Remove duplicate warning about missing reliable stacktrace support
    Revert "livepatch: Remove reliable stacktrace check in klp_try_switch_task()"
    stacktrace: Remove weak version of save_stack_trace_tsk_reliable()
    livepatch: Use static buffer for debugging messages under rq lock
    livepatch: Remove stale kobj_added entries from kernel-doc descriptions

    Linus Torvalds
     

20 Jun, 2019

2 commits

  • WARN_ON_ONCE() could not be called safely under rq lock because
    of console deadlock issues. Moreover WARN_ON_ONCE() is superfluous in
    klp_check_stack(), because stack_trace_save_tsk_reliable() cannot return
    -ENOSYS thanks to klp_have_reliable_stack() check in
    klp_try_switch_task().

    [ mbenes: changelog edited ]
    Signed-off-by: Miroslav Benes
    Acked-by: Josh Poimboeuf
    Reviewed-by: Kamalesh Babulal
    Signed-off-by: Petr Mladek

    Petr Mladek
     
  • This reverts commit 1d98a69e5cef3aeb68bcefab0e67e342d6bb4dad. Commit
    31adf2308f33 ("livepatch: Convert error about unsupported reliable
    stacktrace into a warning") weakened the enforcement for architectures
    to have reliable stack traces support. The system only warns now about
    it.

    It only makes sense to reintroduce the compile time checking in
    klp_try_switch_task() again and bail out early.

    Signed-off-by: Miroslav Benes
    Acked-by: Josh Poimboeuf
    Reviewed-by: Kamalesh Babulal
    Signed-off-by: Petr Mladek

    Miroslav Benes
     

16 Jun, 2019

1 commit

  • Pull tracing fixes from Steven Rostedt:

    - Out of range read of stack trace output

    - Fix for NULL pointer dereference in trace_uprobe_create()

    - Fix to a livepatching / ftrace permission race in the module code

    - Fix for NULL pointer dereference in free_ftrace_func_mapper()

    - A couple of build warning clean ups

    * tag 'trace-v5.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace:
    ftrace: Fix NULL pointer dereference in free_ftrace_func_mapper()
    module: Fix livepatch/ftrace module text permissions race
    tracing/uprobe: Fix obsolete comment on trace_uprobe_create()
    tracing/uprobe: Fix NULL pointer dereference in trace_uprobe_create()
    tracing: Make two symbols static
    tracing: avoid build warning with HAVE_NOP_MCOUNT
    tracing: Fix out-of-range read in trace_stack_print()

    Linus Torvalds
     

15 Jun, 2019

1 commit

  • It's possible for livepatch and ftrace to be toggling a module's text
    permissions at the same time, resulting in the following panic:

    BUG: unable to handle page fault for address: ffffffffc005b1d9
    #PF: supervisor write access in kernel mode
    #PF: error_code(0x0003) - permissions violation
    PGD 3ea0c067 P4D 3ea0c067 PUD 3ea0e067 PMD 3cc13067 PTE 3b8a1061
    Oops: 0003 [#1] PREEMPT SMP PTI
    CPU: 1 PID: 453 Comm: insmod Tainted: G O K 5.2.0-rc1-a188339ca5 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-20181126_142135-anatol 04/01/2014
    RIP: 0010:apply_relocate_add+0xbe/0x14c
    Code: fa 0b 74 21 48 83 fa 18 74 38 48 83 fa 0a 75 40 eb 08 48 83 38 00 74 33 eb 53 83 38 00 75 4e 89 08 89 c8 eb 0a 83 38 00 75 43 08 48 63 c1 48 39 c8 74 2e eb 48 83 38 00 75 32 48 29 c1 89 08
    RSP: 0018:ffffb223c00dbb10 EFLAGS: 00010246
    RAX: ffffffffc005b1d9 RBX: 0000000000000000 RCX: ffffffff8b200060
    RDX: 000000000000000b RSI: 0000004b0000000b RDI: ffff96bdfcd33000
    RBP: ffffb223c00dbb38 R08: ffffffffc005d040 R09: ffffffffc005c1f0
    R10: ffff96bdfcd33c40 R11: ffff96bdfcd33b80 R12: 0000000000000018
    R13: ffffffffc005c1f0 R14: ffffffffc005e708 R15: ffffffff8b2fbc74
    FS: 00007f5f447beba8(0000) GS:ffff96bdff900000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: ffffffffc005b1d9 CR3: 000000003cedc002 CR4: 0000000000360ea0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
    klp_init_object_loaded+0x10f/0x219
    ? preempt_latency_start+0x21/0x57
    klp_enable_patch+0x662/0x809
    ? virt_to_head_page+0x3a/0x3c
    ? kfree+0x8c/0x126
    patch_init+0x2ed/0x1000 [livepatch_test02]
    ? 0xffffffffc0060000
    do_one_initcall+0x9f/0x1c5
    ? kmem_cache_alloc_trace+0xc4/0xd4
    ? do_init_module+0x27/0x210
    do_init_module+0x5f/0x210
    load_module+0x1c41/0x2290
    ? fsnotify_path+0x3b/0x42
    ? strstarts+0x2b/0x2b
    ? kernel_read+0x58/0x65
    __do_sys_finit_module+0x9f/0xc3
    ? __do_sys_finit_module+0x9f/0xc3
    __x64_sys_finit_module+0x1a/0x1c
    do_syscall_64+0x52/0x61
    entry_SYSCALL_64_after_hwframe+0x44/0xa9

    The above panic occurs when loading two modules at the same time with
    ftrace enabled, where at least one of the modules is a livepatch module:

    CPU0 CPU1
    klp_enable_patch()
    klp_init_object_loaded()
    module_disable_ro()
    ftrace_module_enable()
    ftrace_arch_code_modify_post_process()
    set_all_modules_text_ro()
    klp_write_object_relocations()
    apply_relocate_add()
    *patches read-only code* - BOOM

    A similar race exists when toggling ftrace while loading a livepatch
    module.

    Fix it by ensuring that the livepatch and ftrace code patching
    operations -- and their respective permissions changes -- are protected
    by the text_mutex.

    Link: http://lkml.kernel.org/r/ab43d56ab909469ac5d2520c5d944ad6d4abd476.1560474114.git.jpoimboe@redhat.com

    Reported-by: Johannes Erdfelt
    Fixes: 444d13ff10fb ("modules: add ro_after_init support")
    Acked-by: Jessica Yu
    Reviewed-by: Petr Mladek
    Reviewed-by: Miroslav Benes
    Signed-off-by: Josh Poimboeuf
    Signed-off-by: Steven Rostedt (VMware)

    Josh Poimboeuf
     

05 Jun, 2019

1 commit


21 May, 2019

2 commits

  • Based on 2 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details you
    should have received a copy of the gnu general public license along
    with this program if not see http www gnu org licenses

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details [based]
    [from] [clk] [highbank] [c] you should have received a copy of the
    gnu general public license along with this program if not see http
    www gnu org licenses

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 355 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Kate Stewart
    Reviewed-by: Jilayne Lovejoy
    Reviewed-by: Steve Winslow
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190519154041.837383322@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     
  • Add SPDX license identifiers to all Make/Kconfig files which:

    - Have no license information of any form

    These files fall under the project license, GPL v2 only. The resulting SPDX
    license identifier is:

    GPL-2.0-only

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

16 May, 2019

1 commit

  • Pull tracing updates from Steven Rostedt:
    "The major changes in this tracing update includes:

    - Removal of non-DYNAMIC_FTRACE from 32bit x86

    - Removal of mcount support from x86

    - Emulating a call from int3 on x86_64, fixes live kernel patching

    - Consolidated Tracing Error logs file

    Minor updates:

    - Removal of klp_check_compiler_support()

    - kdb ftrace dumping output changes

    - Accessing and creating ftrace instances from inside the kernel

    - Clean up of #define if macro

    - Introduction of TRACE_EVENT_NOP() to disable trace events based on
    config options

    And other minor fixes and clean ups"

    * tag 'trace-v5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (44 commits)
    x86: Hide the int3_emulate_call/jmp functions from UML
    livepatch: Remove klp_check_compiler_support()
    ftrace/x86: Remove mcount support
    ftrace/x86_32: Remove support for non DYNAMIC_FTRACE
    tracing: Simplify "if" macro code
    tracing: Fix documentation about disabling options using trace_options
    tracing: Replace kzalloc with kcalloc
    tracing: Fix partial reading of trace event's id file
    tracing: Allow RCU to run between postponed startup tests
    tracing: Fix white space issues in parse_pred() function
    tracing: Eliminate const char[] auto variables
    ring-buffer: Fix mispelling of Calculate
    tracing: probeevent: Fix to make the type of $comm string
    tracing: probeevent: Do not accumulate on ret variable
    tracing: uprobes: Re-enable $comm support for uprobe events
    ftrace/x86_64: Emulate call function while updating in breakpoint handler
    x86_64: Allow breakpoints to emulate call instructions
    x86_64: Add gap to int3 to allow for call emulation
    tracing: kdb: Allow ftdump to skip all but the last few entries
    tracing: Add trace_total_entries() / trace_total_entries_cpu()
    ...

    Linus Torvalds
     

11 May, 2019

1 commit

  • The only purpose of klp_check_compiler_support() is to make sure that we
    are not using ftrace on x86 via mcount (because that's executed only after
    prologue has already happened, and that's too late for livepatching
    purposes).

    Now that mcount is not supported by ftrace any more, there is no need for
    klp_check_compiler_support() either.

    Link: http://lkml.kernel.org/r/nycvar.YFH.7.76.1905102346100.17054@cbobk.fhfr.pm

    Reported-by: Linus Torvalds
    Signed-off-by: Jiri Kosina
    Signed-off-by: Steven Rostedt (VMware)

    Jiri Kosina
     

08 May, 2019

1 commit

  • Pull driver core/kobject updates from Greg KH:
    "Here is the "big" set of driver core patches for 5.2-rc1

    There are a number of ACPI patches in here as well, as Rafael said
    they should go through this tree due to the driver core changes they
    required. They have all been acked by the ACPI developers.

    There are also a number of small subsystem-specific changes in here,
    due to some changes to the kobject core code. Those too have all been
    acked by the various subsystem maintainers.

    As for content, it's pretty boring outside of the ACPI changes:
    - spdx cleanups
    - kobject documentation updates
    - default attribute groups for kobjects
    - other minor kobject/driver core fixes

    All have been in linux-next for a while with no reported issues"

    * tag 'driver-core-5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (47 commits)
    kobject: clean up the kobject add documentation a bit more
    kobject: Fix kernel-doc comment first line
    kobject: Remove docstring reference to kset
    firmware_loader: Fix a typo ("syfs" -> "sysfs")
    kobject: fix dereference before null check on kobj
    Revert "driver core: platform: Fix the usage of platform device name(pdev->name)"
    init/config: Do not select BUILD_BIN2C for IKCONFIG
    Provide in-kernel headers to make extending kernel easier
    kobject: Improve doc clarity kobject_init_and_add()
    kobject: Improve docs for kobject_add/del
    driver core: platform: Fix the usage of platform device name(pdev->name)
    livepatch: Replace klp_ktype_patch's default_attrs with groups
    cpufreq: schedutil: Replace default_attrs field with groups
    padata: Replace padata_attr_type default_attrs field with groups
    irqdesc: Replace irq_kobj_type's default_attrs field with groups
    net-sysfs: Replace ktype default_attrs field with groups
    block: Replace all ktype default_attrs with groups
    samples/kobject: Replace foo_ktype's default_attrs field with groups
    kobject: Add support for default attribute groups to kobj_type
    driver core: Postpone DMA tear-down until after devres release for probe failure
    ...

    Linus Torvalds
     

07 May, 2019

1 commit

  • Pull livepatching updates from Jiri Kosina:

    - livepatching kselftests improvements from Joe Lawrence and Miroslav
    Benes

    - making use of gcc's -flive-patching option when available, from
    Miroslav Benes

    - kobject handling cleanups, from Petr Mladek

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching:
    livepatch: Remove duplicated code for early initialization
    livepatch: Remove custom kobject state handling
    livepatch: Convert error about unsupported reliable stacktrace into a warning
    selftests/livepatch: Add functions.sh to TEST_PROGS_EXTENDED
    kbuild: use -flive-patching when CONFIG_LIVEPATCH is enabled
    selftests/livepatch: use TEST_PROGS for test scripts

    Linus Torvalds
     

04 May, 2019

2 commits

  • kobject_init() call added one more operation that has to be
    done when doing the early initialization of both static and
    dynamic livepatch structures.

    It would have been easier when the early initialization code
    was not duplicated. Let's deduplicate it for future generations
    of livepatching hackers.

    The patch does not change the existing behavior.

    Signed-off-by: Petr Mladek
    Reviewed-by: Kamalesh Babulal
    Acked-by: Joe Lawrence
    Signed-off-by: Jiri Kosina

    Petr Mladek
     
  • kobject_init() always succeeds and sets the reference count to 1.
    It allows to always free the structures via kobject_put() and
    the related release callback.

    Note that the custom kobject state handling was used only
    because we did not know that kobject_put() can and actually
    should get called even when kobject_init_and_add() fails.

    The patch should not change the existing behavior.

    Suggested-by: "Tobin C. Harding"
    Signed-off-by: Petr Mladek
    Reviewed-by: Kamalesh Babulal
    Acked-by: Joe Lawrence
    Signed-off-by: Jiri Kosina

    Petr Mladek
     

29 Apr, 2019

1 commit

  • The commit d0807da78e11d46f ("livepatch: Remove immediate feature") caused
    that any livepatch was refused when reliable stacktraces were not supported
    on the given architecture.

    The limitation is too strong. User space processes are safely migrated
    even when entering or leaving the kernel. Kthreads transition would
    need to get forced. But it is safe when:

    + The livepatch does not change the semantic of the code.
    + Callbacks do not depend on a safely finished transition.

    Suggested-by: Josh Poimboeuf
    Acked-by: Josh Poimboeuf
    Acked-by: Miroslav Benes
    Reviewed-by: Kamalesh Babulal
    Signed-off-by: Petr Mladek

    Petr Mladek