* [PATCH 0/2] livepatch: reject internal flags set by a patch
@ 2026-11-16 13:04 Yafang Shao
2026-11-16 13:04 ` [PATCH 1/2] livepatch: reject nop flag " Yafang Shao
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Yafang Shao @ 2026-11-16 13:04 UTC (permalink / raw)
To: jpoimboe, mbenes, pmladek, joe.lawrence, song; +Cc: live-patching, Yafang Shao
While upgrading an atomic-replace livepatch, an application in a k8s
environment reported high latency spikes. While writing a reproducer
for it on a test server, I unintentionally set the .nop flag for a
function in the patch, which triggered the issue described in #1. I then
checked for other similar issues and found the one in #2.
These small fixes can be sent independently of the latency spike I am
trying to resolve.
Yafang Shao (2):
livepatch: reject nop flag set by a patch
livepatch: reject dynamic flag set by a patch
include/linux/livepatch.h | 2 ++
kernel/livepatch/core.c | 12 ++++++++++++
2 files changed, 14 insertions(+)
--
2.52.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] livepatch: reject nop flag set by a patch
2026-11-16 13:04 [PATCH 0/2] livepatch: reject internal flags set by a patch Yafang Shao
@ 2026-11-16 13:04 ` Yafang Shao
2026-11-16 13:13 ` sashiko-bot
2026-11-16 13:04 ` [PATCH 2/2] livepatch: reject dynamic " Yafang Shao
2026-11-16 13:18 ` [PATCH 0/2] livepatch: reject internal flags " Miroslav Benes
2 siblings, 1 reply; 6+ messages in thread
From: Yafang Shao @ 2026-11-16 13:04 UTC (permalink / raw)
To: jpoimboe, mbenes, pmladek, joe.lawrence, song; +Cc: live-patching, Yafang Shao
A patch module can incorrectly set .nop = true in its own struct
klp_func:
static struct klp_func funcs[] = {
{
.old_name = "cmdline_proc_show",
.nop = true,
},
{ }
};
.nop is internal to livepatch: it is set only by klp_alloc_func_nop(),
for functions that the patch does not replace. When the patch module is
removed, klp_kobj_release_func() trusts the flag and hands any func that
has it set to klp_free_func_nop():
klp_kobj_release_func
+ if (func->nop)
klp_free_func_nop(func);
For a func that was never allocated by klp_alloc_func_nop(), the free
operates on memory that livepatch does not own, and the kernel warns:
[ 679.530851] ------------[ cut here ]------------
[ 679.530853] WARNING: mm/slub.c:6855 at free_large_kmalloc+0xc0/0xe0, CPU#55: kworker/55:1/794
[ 679.531695] Modules linked in: test_klp_nop_bad(OK) vfat fat intel_rapl_msr intel_rapl_common kvm_amd ccp iTCO_wdt kvm virtio_gpu virtio_dma_buf drm_shmem_helper i2c_i801 drm_client_lib i2c_mux irqbypass i2c_smbus drm_kms_helper pcspkr lpc_ich virtio_balloon input_leds sch_fq_codel drm fuse xfs ahci libahci virtio_net aesni_intel gf128mul net_failover libata virtio_rng virtio_blk virtio_console failover serio_raw sunrpc dm_mirror dm_region_hash dm_log dm_mod qemu_fw_cfg
[ 679.533370] CPU: 55 UID: 0 PID: 794 Comm: kworker/55:1 Kdump: loaded Tainted: G O K 7.4.0-rc1+ #270 PREEMPT(full)
[ 679.533841] Tainted: [O]=OOT_MODULE, [K]=LIVEPATCH
[ 679.534047] Hardware name: Red Hat KVM/RHEL, BIOS 1.16.3-5.el9 11/05/2023
[ 679.534320] Workqueue: events klp_transition_work_fn
[ 679.534530] RIP: 0010:free_large_kmalloc+0xc0/0xe0
[ 679.534729] Code: ed 80 3d d4 23 d8 01 00 ba 00 f0 ff ff 75 9d 48 c7 c7 62 a7 94 b3 89 55 ec c6 05 bc 23 d8 01 01 e8 b5 8e cf ff 8b 55 ec eb 82 <0f> 0b 48 c7 c6 49 a7 94 b3 4c 89 e7 e8 1f 41 fa ff 48 83 c4 08 41
[ 679.535478] RSP: 0018:ff7be23881c47cb0 EFLAGS: 00010202
[ 679.535697] RAX: 00000000000000ff RBX: ffffffffc0e50280 RCX: 0000000000000001
[ 679.535999] RDX: 0000000000000000 RSI: ffffffffc0e53054 RDI: ffb8a30e57d794c0
[ 679.536287] RBP: ff7be23881c47cc8 R08: ff3c2d170ff94e58 R09: ff3c2d17008b7210
[ 679.536574] R10: ff7be23881c47c98 R11: ff7be23881c47ca0 R12: ffb8a30e57d794c0
[ 679.536865] R13: ffb8a30e57d794c0 R14: ffffffffc0e50138 R15: ffffffffc0e50260
[ 679.537163] FS: 0000000000000000(0000) GS:ff3c2d3649d15000(0000) knlGS:0000000000000000
[ 679.537490] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 679.537723] CR2: 000055eb5f6a5158 CR3: 00000015e9020004 CR4: 0000000000771ef0
[ 679.538023] PKRU: 55555554
[ 679.538139] Call Trace:
[ 679.538249] <TASK>
[ 679.538348] kfree+0x171/0x3a0
[ 679.538483] ? srso_alias_return_thunk+0x5/0xfbef5
[ 679.538681] ? kernfs_put.part.0+0xcf/0x150
[ 679.538869] klp_kobj_release_func+0x35/0x60
[ 679.539061] kobject_cleanup+0x44/0x1b0
[ 679.539236] kobject_put+0x40/0x70
[ 679.539383] __klp_free_objects+0xaa/0x160
[ 679.539556] klp_free_patch_async+0x52/0x80
[ 679.539730] klp_try_complete_transition+0x2dc/0x310
[ 679.539941] klp_transition_work_fn+0x24/0x40
[ 679.540131] process_one_work+0x1db/0x410
[ 679.540306] worker_thread+0x1bc/0x330
[ 679.540466] kthread+0xfd/0x140
[ 679.540603] ? __pfx_worker_thread+0x10/0x10
[ 679.540783] ? __pfx_kthread+0x10/0x10
[ 679.540947] ret_from_fork+0x178/0x250
[ 679.541115] ? __pfx_kthread+0x10/0x10
[ 679.541273] ret_from_fork_asm+0x1a/0x30
[ 679.541445] </TASK>
[ 679.541542] ---[ end trace 0000000000000000 ]---
[ 679.541738] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x15f5e53
[ 679.541744] flags: 0x17ffffc0000000(node=0|zone=2|lastcpupid=0x1fffff)
[ 679.541747] raw: 0017ffffc0000000 ffb8a30e57d794c8 ffb8a30e57d794c8 0000000000000000
[ 679.541749] raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
[ 679.541750] page dumped because: Not a kmalloc allocation
[ 679.541756] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x15f5e50
[ 679.541758] flags: 0x17ffffc0000000(node=0|zone=2|lastcpupid=0x1fffff)
[ 679.541759] raw: 0017ffffc0000000 ffb8a30e57d79408 ffb8a30e57d79408 0000000000000000
[ 679.541760] raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
[ 679.541761] page dumped because: Not a kmalloc allocation
A simple reproducer:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/livepatch.h>
static struct klp_func funcs[] = {
{
.old_name = "cmdline_proc_show",
.nop = true,
},
{ }
};
static struct klp_object objs[] = {
{ .funcs = funcs, },
{ }
};
static struct klp_patch patch = {
.mod = THIS_MODULE,
.objs = objs,
};
static int test_klp_nop_bad_init(void)
{
return klp_enable_patch(&patch);
}
static void test_klp_nop_bad_exit(void)
{
}
module_init(test_klp_nop_bad_init);
module_exit(test_klp_nop_bad_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("livepatch reproducer: patch-supplied nop");
MODULE_INFO(livepatch, "Y");
Fix this by rejecting such patches at initialization time, so a patch can
no longer reach klp_kobj_release_func() with a bogus .nop.
After this fix, the result is:
[ 47.563594] livepatch: test_klp_nop_bad: func 'cmdline_proc_show' must not set the internal nop flag
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
include/linux/livepatch.h | 1 +
kernel/livepatch/core.c | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index 5f74f79c22b4..76ba613830a6 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -37,6 +37,7 @@
* @old_size: size of the old function
* @new_size: size of the new function
* @nop: temporary patch to use the original code again; dyn. allocated
+ * internal only, must not be set by a patch
* @patched: the func has been added to the klp_ops list
* @transition: the func is currently being applied or reverted
*
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 517fe427ff92..ba09894eec2c 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -1113,6 +1113,11 @@ static int klp_check_patch(struct klp_patch *patch)
klp_for_each_func_static(obj, func) {
if (!func->old_name)
return -EINVAL;
+ if (func->nop) {
+ pr_err("%s: func '%s' must not set the internal nop flag\n",
+ patch->mod->name, func->old_name);
+ return -EINVAL;
+ }
}
}
return 0;
--
2.52.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] livepatch: reject dynamic flag set by a patch
2026-11-16 13:04 [PATCH 0/2] livepatch: reject internal flags set by a patch Yafang Shao
2026-11-16 13:04 ` [PATCH 1/2] livepatch: reject nop flag " Yafang Shao
@ 2026-11-16 13:04 ` Yafang Shao
2026-11-16 13:18 ` [PATCH 0/2] livepatch: reject internal flags " Miroslav Benes
2 siblings, 0 replies; 6+ messages in thread
From: Yafang Shao @ 2026-11-16 13:04 UTC (permalink / raw)
To: jpoimboe, mbenes, pmladek, joe.lawrence, song; +Cc: live-patching, Yafang Shao
A patch module may set the internal "dynamic" flag on its own klp_object:
static struct klp_object objs[] = {
{ .funcs = funcs, .dynamic = true, },
{ }
};
klp_check_patch() does not validate it. klp_kobj_release_object() however
uses the flag to decide whether the object was allocated by the core:
klp_kobj_release_object
+ if (obj->dynamic)
klp_free_object_dynamic(obj);
For a klp_object that was never allocated by klp_alloc_object_dynamic(),
the free operates on memory that livepatch does not own, and the kernel
warns:
[ 51.132051] test_klp_obj_dynamic: loading out-of-tree module taints kernel.
[ 51.132057] test_klp_obj_dynamic: tainting kernel with TAINT_LIVEPATCH
[ 51.136303] livepatch: symbol 'this_symbol_does_not_exist' not found in symbol table
[ 51.136352] ------------[ cut here ]------------
[ 51.136354] WARNING: mm/slub.c:6855 at free_large_kmalloc+0xc0/0xe0, CPU#21: insmod/2189
[ 51.137260] Modules linked in: test_klp_obj_dynamic(OK+) vfat fat intel_rapl_msr intel_rapl_common kvm_amd ccp iTCO_wdt virtio_gpu kvm virtio_dma_buf drm_shmem_helper i2c_i801 drm_client_lib i2c_mux irqbypass drm_kms_helper i2c_smbus pcspkr virtio_balloon lpc_ich input_leds sch_fq_codel drm fuse xfs ahci libahci virtio_net aesni_intel net_failover gf128mul libata virtio_rng virtio_blk virtio_console failover serio_raw sunrpc dm_mirror dm_region_hash dm_log dm_mod qemu_fw_cfg
[ 51.138982] CPU: 21 UID: 0 PID: 2189 Comm: insmod Kdump: loaded Tainted: G O K 7.4.0-rc1+ #271 PREEMPT(full)
[ 51.139431] Tainted: [O]=OOT_MODULE, [K]=LIVEPATCH
[ 51.139636] Hardware name: Red Hat KVM/RHEL, BIOS 1.16.3-5.el9 11/05/2023
[ 51.139928] RIP: 0010:free_large_kmalloc+0xc0/0xe0
[ 51.140129] Code: ed 80 3d 94 23 d8 01 00 ba 00 f0 ff ff 75 9d 48 c7 c7 c2 a7 94 97 89 55 ec c6 05 7c 23 d8 01 01 e8 75 8e cf ff 8b 55 ec eb 82 <0f> 0b 48 c7 c6 a9 a7 94 97 4c 89 e7 e8 1f 41 fa ff 48 83 c4 08 41
[ 51.140888] RSP: 0018:ff5331d9031c3aa0 EFLAGS: 00010202
[ 51.141105] RAX: 00000000000000ff RBX: ffffffffc0bfb138 RCX: 000000000000000a
[ 51.141397] RDX: 0000000000000000 RSI: ffffffffc0bfb100 RDI: ffa280331686fec0
[ 51.141707] RBP: ff5331d9031c3ab8 R08: ff22d0898472eaa0 R09: ff22d089808b7210
[ 51.141999] R10: ff5331d9031c3a88 R11: ff5331d9031c3a90 R12: ffa280331686fec0
[ 51.142288] R13: ffa280331686fec0 R14: ffffffffc0bfb050 R15: ffffffffc0bfb118
[ 51.142584] FS: 00007f55e9bed740(0000) GS:ff22d0a8e5495000(0000) knlGS:0000000000000000
[ 51.142925] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 51.143161] CR2: 00005611a26eee48 CR3: 00000001021db005 CR4: 0000000000771ef0
[ 51.143450] PKRU: 55555554
[ 51.143572] Call Trace:
[ 51.143693] <TASK>
[ 51.143792] kfree+0x171/0x3a0
[ 51.143927] ? srso_alias_return_thunk+0x5/0xfbef5
[ 51.144128] ? kernfs_put.part.0+0xcf/0x150
[ 51.144314] klp_kobj_release_object+0x3e/0x60
[ 51.144511] kobject_cleanup+0x44/0x1b0
[ 51.144700] kobject_put+0x40/0x70
[ 51.144848] __klp_free_objects+0x114/0x160
[ 51.145028] klp_enable_patch.part.0+0x29e/0x4f0
[ 51.145227] klp_enable_patch+0xb4/0xf0
[ 51.145390] ? __pfx_init_module+0x10/0x10 [test_klp_obj_dynamic]
[ 51.145645] test_klp_obj_dynamic_init+0x15/0x20 [test_klp_obj_dynamic]
[ 51.145929] do_one_initcall+0x45/0x300
[ 51.146092] ? do_init_module+0x28/0x2a0
[ 51.146262] do_init_module+0x6a/0x2a0
[ 51.146422] load_module+0x861/0x980
[ 51.146581] ? srso_alias_return_thunk+0x5/0xfbef5
[ 51.146794] ? kernel_read_file+0x23c/0x2c0
[ 51.146976] init_module_from_file+0xdf/0x100
[ 51.147163] idempotent_init_module+0x170/0x270
[ 51.147355] __x64_sys_finit_module+0x73/0xf0
[ 51.147544] x64_sys_call+0x2043/0x21d0
[ 51.147723] do_syscall_64+0x97/0x460
[ 51.147884] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 51.148095] RIP: 0033:0x7f55e93089fd
[ 51.148250] Code: 5b 41 5c c3 66 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d eb 23 0f 00 f7 d8 64 89 01 48
[ 51.149005] RSP: 002b:00007ffcb754a8f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
[ 51.149313] RAX: ffffffffffffffda RBX: 00005611a26ec7d0 RCX: 00007f55e93089fd
[ 51.149608] RDX: 0000000000000000 RSI: 000056117e373962 RDI: 0000000000000003
[ 51.149912] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
[ 51.150202] R10: 0000000000000003 R11: 0000000000000246 R12: 000056117e373962
[ 51.150493] R13: 00005611a26ec770 R14: 000056117e372550 R15: 00005611a26ec8f0
[ 51.150801] </TASK>
[ 51.150900] ---[ end trace 0000000000000000 ]---
[ 51.151101] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x15a1bfb
[ 51.151107] flags: 0x17ffffc0000000(node=0|zone=2|lastcpupid=0x1fffff)
[ 51.151111] raw: 0017ffffc0000000 ffa280331686fec8 ffa280331686fec8 0000000000000000
[ 51.151113] raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
[ 51.151113] page dumped because: Not a kmalloc allocation
A simple reproducer:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/livepatch.h>
static void dummy_new_func(void)
{
}
static struct klp_func funcs[] = {
{
.old_name = "this_symbol_does_not_exist",
.new_func = dummy_new_func,
},
{ }
};
static struct klp_object objs[] = {
{
.funcs = funcs,
.dynamic = true,
},
{ }
};
static struct klp_patch patch = {
.mod = THIS_MODULE,
.objs = objs,
};
static int test_klp_obj_dynamic_init(void)
{
return klp_enable_patch(&patch);
}
static void test_klp_obj_dynamic_exit(void)
{
}
module_init(test_klp_obj_dynamic_init);
module_exit(test_klp_obj_dynamic_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("livepatch reproducer: object dynamic flag");
MODULE_INFO(livepatch, "Y");
Fix this by rejecting such patches at initialization time, so a patch can
no longer reach klp_free_object_dynamic() with a bogus .dynamic.
After this fix, the result is:
[ 60.029559] test_klp_obj_dynamic: loading out-of-tree module taints kernel.
[ 60.029565] test_klp_obj_dynamic: tainting kernel with TAINT_LIVEPATCH
[ 60.034073] livepatch: test_klp_obj_dynamic: object vmlinux must not set the internal dynamic flag
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
include/linux/livepatch.h | 1 +
kernel/livepatch/core.c | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index 76ba613830a6..859466f08d95 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -93,6 +93,7 @@ struct klp_func {
* @mod: kernel module associated with the patched object
* (NULL for vmlinux)
* @dynamic: temporary object for nop functions; dynamically allocated
+ * internal only, must not be set by a patch
* @patched: the object's funcs have been added to the klp_ops list
*/
struct klp_object {
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index ba09894eec2c..162f4cc6e2c0 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -1110,6 +1110,13 @@ static int klp_check_patch(struct klp_patch *patch)
klp_for_each_object_static(patch, obj) {
if (!obj->funcs)
return -EINVAL;
+ if (obj->dynamic) {
+ pr_err("%s: object %s must not set the internal dynamic flag\n",
+ patch->mod->name,
+ klp_is_module(obj) ? obj->name : "vmlinux");
+ return -EINVAL;
+ }
+
klp_for_each_func_static(obj, func) {
if (!func->old_name)
return -EINVAL;
--
2.52.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] livepatch: reject nop flag set by a patch
2026-11-16 13:04 ` [PATCH 1/2] livepatch: reject nop flag " Yafang Shao
@ 2026-11-16 13:13 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-16 13:13 UTC (permalink / raw)
To: Yafang Shao, jpoimboe, mbenes, pmladek, joe.lawrence, song; +Cc: live-patching
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] livepatch: missing Fixes trailer for klp_check_patch() nop check
--
commit c7daf731e7df689ca282b8fa4f4b36f2e21c4907
Author: Yafang Shao <laoar.shao@gmail.com>
> livepatch: reject nop flag set by a patch
>
> A patch module can incorrectly set .nop = true in its own struct
> klp_func:
>
> static struct klp_func funcs[] = {
> {
> .old_name = "cmdline_proc_show",
> .nop = true,
> },
> { }
> };
>
> .nop is internal to livepatch: it is set only by klp_alloc_func_nop(),
> for functions that the patch does not replace. When the patch module is
> removed, klp_kobj_release_func() trusts the flag and hands any func that
> has it set to klp_free_func_nop():
>
> klp_kobj_release_func
> + if (func->nop)
> klp_free_func_nop(func);
>
> For a func that was never allocated by klp_alloc_func_nop(), the free
> operates on memory that livepatch does not own, and the kernel warns:
>
> [ 679.530851] ------------[ cut here ]------------
> [ 679.530853] WARNING: mm/slub.c:6855 at free_large_kmalloc+0xc0/0xe0, CPU#55: kworker/55:1/794
> [ 679.531695] Modules linked in: test_klp_nop_bad(OK) vfat fat intel_rapl_msr intel_rapl_common kvm_amd ccp iTCO_wdt kvm virtio_gpu virtio_dma_buf drm_shmem_helper i2c_i801 drm_client_lib i2c_mux irqbypass i2c_smbus drm_kms_helper pcspkr lpc_ich virtio_balloon input_leds sch_fq_codel drm fuse xfs ahci libahci virtio_net aesni_intel gf128mul net_failover libata virtio_rng virtio_blk virtio_console failover serio_raw sunrpc dm_mirror dm_region_hash dm_log dm_mod qemu_fw_cfg
> [ 679.533370] CPU: 55 UID: 0 PID: 794 Comm: kworker/55:1 Kdump: loaded Tainted: G O K 7.4.0-rc1+ #270 PREEMPT(full)
> [ 679.533841] Tainted: [O]=OOT_MODULE, [K]=LIVEPATCH
> [ 679.534047] Hardware name: Red Hat KVM/RHEL, BIOS 1.16.3-5.el9 11/05/2023
> [ 679.534320] Workqueue: events klp_transition_work_fn
> [ 679.534530] RIP: 0010:free_large_kmalloc+0xc0/0xe0
> [ 679.534729] Code: ed 80 3d d4 23 d8 01 00 ba 00 f0 ff ff 75 9d 48 c7 c7 62 a7 94 b3 89 55 ec c6 05 bc 23 d8 01 01 e8 b5 8e cf ff 8b 55 ec eb 82 <0f> 0b 48 c7 c6 49 a7 94 b3 4c 89 e7 e8 1f 41 fa ff 48 83 c4 08 41
> [ 679.535478] RSP: 0018:ff7be23881c47cb0 EFLAGS: 00010202
> [ 679.535697] RAX: 00000000000000ff RBX: ffffffffc0e50280 RCX: 0000000000000001
> [ 679.535999] RDX: 0000000000000000 RSI: ffffffffc0e53054 RDI: ffb8a30e57d794c0
> [ 679.536287] RBP: ff7be23881c47cc8 R08: ff3c2d170ff94e58 R09: ff3c2d17008b7210
> [ 679.536574] R10: ff7be23881c47c98 R11: ff7be23881c47ca0 R12: ffb8a30e57d794c0
> [ 679.536865] R13: ffb8a30e57d794c0 R14: ffffffffc0e50138 R15: ffffffffc0e50260
> [ 679.537163] FS: 0000000000000000(0000) GS:ff3c2d3649d15000(0000) knlGS:0000000000000000
> [ 679.537490] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [ 679.537723] CR2: 000055eb5f6a5158 CR3: 00000015e9020004 CR4: 0000000000771ef0
> [ 679.538023] PKRU: 55555554
> [ 679.538139] Call Trace:
> [ 679.538249] <TASK>
> [ 679.538348] kfree+0x171/0x3a0
> [ 679.538483] ? srso_alias_return_thunk+0x5/0xfbef5
> [ 679.538681] ? kernfs_put.part.0+0xcf/0x150
> [ 679.538869] klp_kobj_release_func+0x35/0x60
> [ 679.539061] kobject_cleanup+0x44/0x1b0
> [ 679.539236] kobject_put+0x40/0x70
> [ 679.539383] __klp_free_objects+0xaa/0x160
> [ 679.539556] klp_free_patch_async+0x52/0x80
> [ 679.539730] klp_try_complete_transition+0x2dc/0x310
> [ 679.539941] klp_transition_work_fn+0x24/0x40
> [ 679.540131] process_one_work+0x1db/0x410
> [ 679.540306] worker_thread+0x1bc/0x330
> [ 679.540466] kthread+0xfd/0x140
> [ 679.540603] ? __pfx_worker_thread+0x10/0x10
> [ 679.540783] ? __pfx_kthread+0x10/0x10
> [ 679.540947] ret_from_fork+0x178/0x250
> [ 679.541115] ? __pfx_kthread+0x10/0x10
> [ 679.541273] ret_from_fork_asm+0x1a/0x30
> [ 679.541445] </TASK>
> [ 679.541542] ---[ end trace 0000000000000000 ]---
> [ 679.541738] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x15f5e53
> [ 679.541744] flags: 0x17ffffc0000000(node=0|zone=2|lastcpupid=0x1fffff)
> [ 679.541747] raw: 0017ffffc0000000 ffb8a30e57d794c8 ffb8a30e57d794c8 0000000000000000
> [ 679.541749] raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
> [ 679.541750] page dumped because: Not a kmalloc allocation
> [ 679.541756] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x15f5e50
> [ 679.541758] flags: 0x17ffffc0000000(node=0|zone=2|lastcpupid=0x1fffff)
> [ 679.541759] raw: 0017ffffc0000000 ffb8a30e57d79408 ffb8a30e57d79408 0000000000000000
> [ 679.541760] raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
> [ 679.541761] page dumped because: Not a kmalloc allocation
>
> A simple reproducer:
>
> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/livepatch.h>
>
> static struct klp_func funcs[] = {
> {
> .old_name = "cmdline_proc_show",
> .nop = true,
> },
> { }
> };
>
> static struct klp_object objs[] = {
> { .funcs = funcs, },
> { }
> };
>
> static struct klp_patch patch = {
> .mod = THIS_MODULE,
> .objs = objs,
> };
>
> static int test_klp_nop_bad_init(void)
> {
> return klp_enable_patch(&patch);
> }
>
> static void test_klp_nop_bad_exit(void)
> {
> }
>
> module_init(test_klp_nop_bad_init);
> module_exit(test_klp_nop_bad_exit);
>
> MODULE_LICENSE("GPL");
> MODULE_DESCRIPTION("livepatch reproducer: patch-supplied nop");
> MODULE_INFO(livepatch, "Y");
>
> Fix this by rejecting such patches at initialization time, so a patch can
> no longer reach klp_kobj_release_func() with a bogus .nop.
>
> After this fix, the result is:
>
> [ 47.563594] livepatch: test_klp_nop_bad: func 'cmdline_proc_show' must not set the internal nop flag
>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
[Severity: Low]
Since commit e1452b607c48 ("livepatch: Add atomic replace") introduced
the nop field and the klp_free_func_nop() call in klp_kobj_release_func(),
should this include:
Fixes: e1452b607c48 ("livepatch: Add atomic replace")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116130402.76743-1-laoar.shao@gmail.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] livepatch: reject internal flags set by a patch
2026-11-16 13:04 [PATCH 0/2] livepatch: reject internal flags set by a patch Yafang Shao
2026-11-16 13:04 ` [PATCH 1/2] livepatch: reject nop flag " Yafang Shao
2026-11-16 13:04 ` [PATCH 2/2] livepatch: reject dynamic " Yafang Shao
@ 2026-11-16 13:18 ` Miroslav Benes
2026-11-16 13:37 ` Yafang Shao
2 siblings, 1 reply; 6+ messages in thread
From: Miroslav Benes @ 2026-11-16 13:18 UTC (permalink / raw)
To: Yafang Shao; +Cc: jpoimboe, pmladek, joe.lawrence, song, live-patching
Hi,
On Mon, 16 Nov 2026, Yafang Shao wrote:
> While upgrading an atomic-replace livepatch, an application in a k8s
> environment reported high latency spikes. While writing a reproducer
> for it on a test server, I unintentionally set the .nop flag for a
> function in the patch, which triggered the issue described in #1. I then
> checked for other similar issues and found the one in #2.
a nice example of shooting oneself in the foot... is it really worth
fixing this? If yes, I would rather vote for silently setting both
obj->dynamic and func->nop to false somewhere in klp_init_*_early() path.
Btw I do not think you need to add the splat and the live patch source
code to the changelog. A simple description would be enough.
Miroslav
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] livepatch: reject internal flags set by a patch
2026-11-16 13:18 ` [PATCH 0/2] livepatch: reject internal flags " Miroslav Benes
@ 2026-11-16 13:37 ` Yafang Shao
0 siblings, 0 replies; 6+ messages in thread
From: Yafang Shao @ 2026-11-16 13:37 UTC (permalink / raw)
To: Miroslav Benes; +Cc: jpoimboe, pmladek, joe.lawrence, song, live-patching
On Mon, Nov 16, 2026 at 9:18 PM Miroslav Benes <mbenes@suse.cz> wrote:
>
> Hi,
>
> On Mon, 16 Nov 2026, Yafang Shao wrote:
>
> > While upgrading an atomic-replace livepatch, an application in a k8s
> > environment reported high latency spikes. While writing a reproducer
> > for it on a test server, I unintentionally set the .nop flag for a
> > function in the patch, which triggered the issue described in #1. I then
> > checked for other similar issues and found the one in #2.
>
> a nice example of shooting oneself in the foot...
Right. I hit it by accident while writing a buggy livepatch module ;)
> is it really worth
> fixing this? If yes, I would rather vote for silently setting both
> obj->dynamic and func->nop to false somewhere in klp_init_*_early() path.
Since it triggers a noisy WARN and a page dump on the unload, I
believe we'd better fix it. Resetting sounds good to me and is
simpler.
>
> Btw I do not think you need to add the splat and the live patch source
> code to the changelog. A simple description would be enough.
Sure, will do.
--
Regards
Yafang
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-16 13:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 13:04 [PATCH 0/2] livepatch: reject internal flags set by a patch Yafang Shao
2026-11-16 13:04 ` [PATCH 1/2] livepatch: reject nop flag " Yafang Shao
2026-11-16 13:13 ` sashiko-bot
2026-11-16 13:04 ` [PATCH 2/2] livepatch: reject dynamic " Yafang Shao
2026-11-16 13:18 ` [PATCH 0/2] livepatch: reject internal flags " Miroslav Benes
2026-11-16 13:37 ` Yafang Shao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox