livepatching changes for 7.4

-----BEGIN PGP SIGNATURE-----
 
 iQJPBAABCAA5FiEESH4wyp42V4tXvYsjUqAMR0iAlPIFAmraBUsbFIAAAAAABAAO
 bWFudTIsMi41KzEuMTIsMiwyAAoJEFKgDEdIgJTy8XwP/AjHvd4Uvj/Knb04kKlW
 So5EnEDYEpu/zVD+FfvvYx5Lf1jRrvclTEQSqfCCiW7p/QIbSO2MTLmDfSMHM7z2
 40bbtUcXnhew++2xouCvR3OOBVGshim7JvPF22K/T6lKQfunyyDcuw/6YDfwBkLP
 pWwuMCUaBLWorMEQ4Ct9CMw540Yb1cH4hdsbvfEXBYxCpguJ+uLE9SlvG3uQVb1b
 kO+zBP0MWijAelYWHBqvTmMEqiiHAgsM5lCK0sIeAmeHH47a7/NzuEB8t/uEl/GG
 n8CS+ykFh9cvuVFnR63A/rA16bYRopusX1+leYbvE2csbLi6NDjy1o5cCGWv47z2
 kkhUx38LGZIq7iRlXq18iS6kb4HP7cqNLL193XypLveMnb5CqW14dLa29SeiT63n
 RcaekJVxprwPeSyM5KXl4QMPD3eGJ4AWuVmMx1yleyLUsKyhFID+dPud1y1ExEOw
 PB08nqLc2K9Py++CVj2+eTqxYvl12s8Xq808VP3hF0LcShOVpIO6yXhO9Q82kuHM
 ZRWyKfU84FcZD0evnSSACFwyeAReno7Bm5nWnNIrYksnu+0THprPA0Xd0Dxz0gc0
 tTlhnhgfPrkB2rT+1KNpYWDQzubTPIg54TmFTQuv3pHWPoZXMu7+CK0/b1YeUxyg
 X5caXY9noZwdxZTiAR3f6LAV
 =zpzt
 -----END PGP SIGNATURE-----

Merge tag 'livepatching-for-7.4' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching

Pull livepatching updates from Petr Mladek:

 - Update maintainers list: added Joe and Song, removed Jiri

 - Prevent removing the livepatch module before releasing all kobjects

 - Ignore debug messages from other subsystems in livepatch selftests

* tag 'livepatching-for-7.4' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching:
  livepatch: Add Joe and Song as maintainers
  livepatch: remove myself from MAINTAINERS
  selftests/livepatch: filter debug messages in check_result()
  livepatch: Fix UAF of unregistered patch kobjects
This commit is contained in:
Linus Torvalds 2026-10-23 11:59:33 -10:00
commit f1e818b239
4 changed files with 25 additions and 5 deletions

View File

@ -15230,10 +15230,10 @@ N: litex
LIVE PATCHING
M: Josh Poimboeuf <jpoimboe@kernel.org>
M: Jiri Kosina <jikos@kernel.org>
M: Miroslav Benes <mbenes@suse.cz>
M: Petr Mladek <pmladek@suse.com>
R: Joe Lawrence <joe.lawrence@redhat.com>
M: Joe Lawrence <joe.lawrence@redhat.com>
M: Song Liu <song@kernel.org>
L: live-patching@vger.kernel.org
S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching.git

View File

@ -33,6 +33,7 @@
* @kobj: kobject for sysfs resources
* @node: list node for klp_object func_list
* @stack_node: list node for klp_ops func_stack list
* @obj: back pointer to the owning object
* @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
@ -72,6 +73,7 @@ struct klp_func {
struct kobject kobj;
struct list_head node;
struct list_head stack_node;
struct klp_object *obj;
unsigned long old_size, new_size;
bool nop;
bool patched;
@ -86,6 +88,7 @@ struct klp_func {
* @kobj: kobject for sysfs resources
* @func_list: dynamic list of the function entries
* @node: list node for klp_patch obj_list
* @patch: back pointer to the owning patch
* @mod: kernel module associated with the patched object
* (NULL for vmlinux)
* @dynamic: temporary object for nop functions; dynamically allocated
@ -101,6 +104,7 @@ struct klp_object {
struct kobject kobj;
struct list_head func_list;
struct list_head node;
struct klp_patch *patch;
struct module *mod;
bool dynamic;
bool patched;

View File

@ -646,12 +646,15 @@ static const struct kobj_type klp_ktype_patch = {
static void klp_kobj_release_object(struct kobject *kobj)
{
struct klp_patch *patch;
struct klp_object *obj;
obj = container_of(kobj, struct klp_object, kobj);
patch = obj->patch;
if (obj->dynamic)
klp_free_object_dynamic(obj);
kobject_put(&patch->kobj);
}
static const struct kobj_type klp_ktype_object = {
@ -662,12 +665,15 @@ static const struct kobj_type klp_ktype_object = {
static void klp_kobj_release_func(struct kobject *kobj)
{
struct klp_object *obj;
struct klp_func *func;
func = container_of(kobj, struct klp_func, kobj);
obj = func->obj;
if (func->nop)
klp_free_func_nop(func);
kobject_put(&obj->kobj);
}
static const struct kobj_type klp_ktype_func = {
@ -943,7 +949,9 @@ static void klp_init_func_early(struct klp_object *obj,
struct klp_func *func)
{
kobject_init(&func->kobj, &klp_ktype_func);
kobject_get(&obj->kobj);
list_add_tail(&func->node, &obj->func_list);
func->obj = obj;
}
static void klp_init_object_early(struct klp_patch *patch,
@ -951,7 +959,9 @@ static void klp_init_object_early(struct klp_patch *patch,
{
INIT_LIST_HEAD(&obj->func_list);
kobject_init(&obj->kobj, &klp_ktype_object);
kobject_get(&patch->kobj);
list_add_tail(&obj->node, &patch->obj_list);
obj->patch = patch;
}
static void klp_init_patch_early(struct klp_patch *patch)

View File

@ -320,9 +320,9 @@ function start_test {
# find new kernel messages since the test started.
local last_dmesg_msg="livepatch kselftest timestamp: $(date --rfc-3339=ns)"
log "$last_dmesg_msg"
loop_until 'dmesg | grep -q "$last_dmesg_msg"' ||
loop_until 'dmesg -r | grep -q "$last_dmesg_msg"' ||
die "buffer busy? can't find canary dmesg message: $last_dmesg_msg"
LAST_DMESG=$(dmesg | grep "$last_dmesg_msg")
LAST_DMESG=$(dmesg -r | grep "$last_dmesg_msg")
echo -n "TEST: $test ... "
log "===== TEST: $test ====="
@ -335,12 +335,18 @@ function check_result {
local result
# Test results include any new dmesg entry since LAST_DMESG, then:
# - exclude debug messages except with "livepatch:" prefix
# - include lines matching keywords
# - exclude lines matching keywords
# - filter out dmesg timestamp prefixes
result=$(dmesg | awk -v last_dmesg="$LAST_DMESG" 'p; $0 == last_dmesg { p=1 }' | \
# - exclude the delayed kobject release messages when CONFIG_DEBUG_KOBJECT_RELEASE is on
result=$(dmesg -r | \
awk -v last_dmesg="$LAST_DMESG" \
'p { if ($0 !~ /^<7>/ || $0 ~ /livepatch:/) print; next } $0 == last_dmesg { p = 1 }' | \
grep -e 'livepatch:' -e 'test_klp' | \
grep -v '\(tainting\|taints\) kernel' | \
grep -v 'kobject: .*parent.*(delayed' | \
sed 's/^<[0-9]*>//' | \
sed 's/^\[[ 0-9.]*\] //' | \
sed 's/^\[[ ]*[CT][0-9]*\] //')