linux/samples/livepatch
Petr Mladek e91c2518a5 livepatch: Initialize shadow variables safely by a custom callback
The existing API allows to pass a sample data to initialize the shadow
data. It works well when the data are position independent. But it fails
miserably when we need to set a pointer to the shadow structure itself.

Unfortunately, we might need to initialize the pointer surprisingly
often because of struct list_head. It is even worse because the list
might be hidden in other common structures, for example, struct mutex,
struct wait_queue_head.

For example, this was needed to fix races in ALSA sequencer. It required
to add mutex into struct snd_seq_client. See commit b3defb791b
("ALSA: seq: Make ioctls race-free") and commit d15d662e89
("ALSA: seq: Fix racy pool initializations")

This patch makes the API more safe. A custom constructor function and data
are passed to klp_shadow_*alloc() functions instead of the sample data.

Note that ctor_data are no longer a template for shadow->data. It might
point to any data that might be necessary when the constructor is called.

Also note that the constructor is called under klp_shadow_lock. It is
an internal spin_lock that synchronizes alloc() vs. get() operations,
see klp_shadow_get_or_alloc(). On one hand, this adds a risk of ABBA
deadlocks. On the other hand, it allows to do some operations safely.
For example, we could add the new structure into an existing list.
This must be done only once when the structure is allocated.

Reported-by: Nicolai Stange <nstange@suse.de>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2018-04-17 13:42:48 +02:00
..
livepatch-callbacks-busymod.c livepatch: add (un)patch callbacks 2017-10-19 10:08:56 +02:00
livepatch-callbacks-demo.c livepatch: Remove immediate feature 2018-01-11 10:58:03 +01:00
livepatch-callbacks-mod.c livepatch: add (un)patch callbacks 2017-10-19 10:08:56 +02:00
livepatch-sample.c livepatch: Remove immediate feature 2018-01-11 10:58:03 +01:00
livepatch-shadow-fix1.c livepatch: Initialize shadow variables safely by a custom callback 2018-04-17 13:42:48 +02:00
livepatch-shadow-fix2.c livepatch: Initialize shadow variables safely by a custom callback 2018-04-17 13:42:48 +02:00
livepatch-shadow-mod.c livepatch: introduce shadow variable API 2017-09-14 23:06:12 +02:00
Makefile livepatch: add (un)patch callbacks 2017-10-19 10:08:56 +02:00