Skip to content

Commit 5b384f9

Browse files
jpoimboeJiri Kosina
authored andcommitted
x86/module: Use text_mutex in apply_relocate_add()
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 <[email protected]> Acked-by: Joe Lawrence <[email protected]> Acked-by: Miroslav Benes <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 0d9fbf7 commit 5b384f9

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

arch/x86/kernel/module.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/gfp.h>
1919
#include <linux/jump_label.h>
2020
#include <linux/random.h>
21+
#include <linux/memory.h>
2122

2223
#include <asm/text-patching.h>
2324
#include <asm/page.h>
@@ -227,14 +228,18 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
227228
bool early = me->state == MODULE_STATE_UNFORMED;
228229
void *(*write)(void *, const void *, size_t) = memcpy;
229230

230-
if (!early)
231+
if (!early) {
231232
write = text_poke;
233+
mutex_lock(&text_mutex);
234+
}
232235

233236
ret = __apply_relocate_add(sechdrs, strtab, symindex, relsec, me,
234237
write);
235238

236-
if (!early)
239+
if (!early) {
237240
text_poke_sync();
241+
mutex_unlock(&text_mutex);
242+
}
238243

239244
return ret;
240245
}

kernel/livepatch/core.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -775,19 +775,13 @@ static int klp_init_object_loaded(struct klp_patch *patch,
775775
int ret;
776776

777777
if (klp_is_module(obj)) {
778-
779-
mutex_lock(&text_mutex);
780-
781778
/*
782779
* Only write module-specific relocations here
783780
* (.klp.rela.{module}.*). vmlinux-specific relocations were
784781
* written earlier during the initialization of the klp module
785782
* itself.
786783
*/
787784
ret = klp_apply_object_relocs(patch, obj);
788-
789-
mutex_unlock(&text_mutex);
790-
791785
if (ret)
792786
return ret;
793787
}

0 commit comments

Comments
 (0)