Skip to content

Instantly share code, notes, and snippets.

@tpsilva
Last active May 3, 2024 15:19
Show Gist options
  • Save tpsilva/047d7d1dd338d4e1ce39e1c4936dd614 to your computer and use it in GitHub Desktop.
Save tpsilva/047d7d1dd338d4e1ce39e1c4936dd614 to your computer and use it in GitHub Desktop.
Simple livepatch to make all livepatches to "stay in transition" (well not really, just mocking the transition_show function) forever.
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/livepatch.h>
static ssize_t my_transition_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
return snprintf(buf, PAGE_SIZE-1, "%d\n", 1);
}
static struct klp_func funcs[] = {
{
.old_name = "transition_show",
.new_func = my_transition_show,
}, { }
};
static struct klp_object objs[] = {
{
.funcs = funcs,
}, { }
};
static struct klp_patch patch = {
.mod = THIS_MODULE,
.objs = objs,
};
static int livepatch_init(void)
{
return klp_enable_patch(&patch);
}
static void livepatch_exit(void)
{
}
module_init(livepatch_init);
module_exit(livepatch_exit);
MODULE_LICENSE("GPL");
MODULE_INFO(livepatch, "Y");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment