On 12/30/24 01:09, Marek Maślanka wrote: > Hi Mike and others, > > I discovered that the patch "[v7,4/8] module: prepare to handle ROX allocations > for text" has disrupted livepatch functionality. Specifically, this occurs when > livepatch is prepared to patch a kernel module and when the livepatch module > contains a "special" relocation section named > ".klp.rela.<MODULE_NAME>.<SECTION_NAME>" to access local symbols. Thank you for the report. It is possible for me to reproduce the issue on my system. An annoying part is to create the .klp.rela.<objname>.<secname> data, for which I eventually used one floating variant of klp-convert [1]. To hit the problem, <objname> must point to an object that is different from vmlinux. Such relocations are processed by the livepatch code later than regular module relocations, as you pointed out after mod->rw_copy is already reset. I think the bug should be addressed in principle by Mike's recently posted rework of the feature [2] but unfortunately, its current version makes my system also unbootable [3]. My reproducer: $ cat test_klp_livepatch.c #include <linux/kernel.h> #include <linux/livepatch.h> #include <linux/module.h> #include <linux/seq_file.h> extern __attribute__((weak)) void *xfs_btree_new_root asm("\".klp.sym.rela.xfs.xfs.xfs_btree_new_root.0\""); static int livepatch_cmdline_proc_show(struct seq_file *m, void *v) { seq_printf(m, "live patched: xfs_btree_new_root=%p\n", &xfs_btree_new_root); return 0; } static struct klp_func funcs[] = { { .old_name = "cmdline_proc_show", .new_func = livepatch_cmdline_proc_show }, { } }; static struct klp_func xfs_funcs[] = { { } }; static struct klp_object objs[] = { { .funcs = funcs, }, { .name = "xfs", .funcs = xfs_funcs, }, { } }; static struct klp_patch patch = { .mod = THIS_MODULE, .objs = objs, }; static int test_klp_livepatch_init(void) { return klp_enable_patch(&patch); } static void test_klp_livepatch_exit(void) { } module_init(test_klp_livepatch_init); module_exit(test_klp_livepatch_exit); MODULE_LICENSE("GPL"); MODULE_INFO(livepatch, "Y"); MODULE_AUTHOR("Petr Pavlu <petr.pavlu@xxxxxxxx>"); MODULE_DESCRIPTION("Livepatch test: livepatch module"); $ make ... $ klp-convert test_klp_livepatch.ko test_klp_livepatch.conv.ko # [1] # modprobe -a xfs ./test_klp_livepatch.conv.ko [1] https://lore.kernel.org/live-patching/20240827123052.9002-3-lhruska@xxxxxxx/ [2] https://lore.kernel.org/linux-modules/20241227072825.1288491-1-rppt@xxxxxxxxxx/ [3] https://lore.kernel.org/linux-modules/86eba318-464b-4b9b-a79e-64039b17be34@lucifer.local/ -- Thanks, Petr