Skip to content

livepatch: Allow user to specify functions to search for on a stack

Miroslav Benes linux-kselftest live-patching lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 8 repliesIn review
  2. v13 patches 10 repliesSuperseded

Changes in v2 from the cover letter

- no separate klp_funcs, stack_only attribute is defined
- tests rewritten

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2livepatch: Allow user to specify functions to search for on a stackinclude/linux/livepatch.h kernel/livepatch/core.c kernel/livepatch/patch.c +1 more+40 -28 replies
2/2selftests/livepatch: Test of the API for specifying functions to search for on a stacklib/livepatch/Makefile lib/livepatch/test_klp_func_stack_only_demo.c lib/livepatch/test_klp_func_stack_only_demo2.c +3 more+362 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] livepatch: Allow user to specify functions to search for on a stack

livepatch's consistency model requires that no live patched function must be found on any task's stack during a transition process after a live patch is applied. It is achieved by walking through stacks of all blocked tasks.

The user might also want to define more functions to search for without them being patched at all. It may either help with preparing a live patch, which would otherwise require adding more functions just to achieve the consistency, or it can be used to overcome deficiencies the stack checking inherently has.

Consider the following example, in which GCC may optimize function parent() so that a part of it is moved to a different section (child.cold()) and parent() jumps to it. If both parent() and child2() are to patching targets, things can break easily if a task sleeps in child.cold() and new patched child2() changes ABI. parent() is not found on the stack, child.cold() jumps back to parent() eventually and new child2() is called.

parent(): /* to-be-patched */

    ...
    jmp child.cold()    /* cannot be patched */
      ...
      schedule()
      ...
      jmp <back>
    ...
    call child2()       /* to-be-patched */
    ...

The patch set adds a new API which allows the user to specify such functions.

v1: https://lore.kernel.org/all/[email protected]/

Changes:
--------
v2:
- no separate klp_funcs, stack_only attribute is defined
- tests rewritten

Miroslav Benes (2):
livepatch: Allow user to specify functions to search for on a stack selftests/livepatch: Test of the API for specifying functions to
search for on a stack

 include/linux/livepatch.h                     |   3 +
 kernel/livepatch/core.c                       |  28 ++-
 kernel/livepatch/patch.c                      |   6 +
 kernel/livepatch/transition.c                 |   5 +-
 lib/livepatch/Makefile                        |   5 +-
 lib/livepatch/test_klp_func_stack_only_demo.c |  66 ++++++++
 .../test_klp_func_stack_only_demo2.c          |  61 +++++++
 lib/livepatch/test_klp_func_stack_only_mod.c  |  70 ++++++++
 tools/testing/selftests/livepatch/Makefile    |   3 +-
 .../livepatch/test-func-stack-only.sh         | 159 ++++++++++++++++++
 10 files changed, 402 insertions(+), 4 deletions(-)
 create mode 100644 lib/livepatch/test_klp_func_stack_only_demo.c
 create mode 100644 lib/livepatch/test_klp_func_stack_only_demo2.c
 create mode 100644 lib/livepatch/test_klp_func_stack_only_mod.c
 create mode 100755 tools/testing/selftests/livepatch/test-func-stack-only.sh
Signature · 1 line
2.34.1