Skip to content

livepatch: Allocate and free shadow variables more safely

Petr Mladek lkml 3 versions – Applied

Status from this message: Queued in for-4.17/upstream-fixes. Thanks,

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 3 repliesApplied
  2. v22 patches 3 repliesSuperseded
  3. v12 patches 9 repliesSuperseded

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/2livepatch: Initialize shadow variables safely by a custom callbackDocumentation/livepatch/shadow-vars.txt include/linux/livepatch.h kernel/livepatch/shadow.c +2 more+104 -470 replies
2/2livepatch: Allow to call a custom callback when freeing shadow variablesDocumentation/livepatch/shadow-vars.txt include/linux/livepatch.h kernel/livepatch/shadow.c +2 more+59 -340 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchJosh PoimboeufMiroslav Benes
SeriesA-b A-b
1/2
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/2] livepatch: Allocate and free shadow variables more safely

Nikolai started to use shadow variables and found that list_head is not initialized correctly using the existing API.

The problem is that LIST_HEAD_INIT() set pointers to itself. klp_shadow_alloc() then copies these pointers to another location.

It would be possible to solve this by a late initialization. But this does not work well with klp_shadow_get_or_alloc(). Also this behavior is error prone. Note that list_head might be hidden in another structure, for example mutex.

I suggest to change the API and allow to initialize the shadow variables using a custom callback. I think that we have already talked about this but we decided to go the easier way. It seems that it was a bad decision.

I send also patch that add a symmetric callback to the klp_shadow_free() functions. It might be handy especially for klp_shadow_free_all().

Changes against v2:

+ Use pr_err() instead of WARN() when ctor() fails [Josh]
+ Some typos [Mirek]

Changes against v1:

+ Rename init/free callbacks to ctor/dtor
+ Misc update of comments and commit messages
+ Fix sizeof() in the sample code in shadow-vars.txt

Petr Mladek (2):
livepatch: Initialize shadow variables safely by a custom callback
livepatch: Allow to call a custom callback when freeing shadow
variables

 Documentation/livepatch/shadow-vars.txt   |  41 ++++++++----
 include/linux/livepatch.h                 |  19 ++++--
 kernel/livepatch/shadow.c                 | 108 ++++++++++++++++++++----------
 samples/livepatch/livepatch-shadow-fix1.c |  43 +++++++++---
 samples/livepatch/livepatch-shadow-fix2.c |  33 ++++-----
 5 files changed, 163 insertions(+), 81 deletions(-)
Signature · 1 line
2.13.6