livepatch: store function sizes
authorJosh Poimboeuf <jpoimboe@redhat.com>
Tue, 14 Feb 2017 01:42:39 +0000 (19:42 -0600)
committerJiri Kosina <jkosina@suse.cz>
Wed, 8 Mar 2017 08:24:04 +0000 (09:24 +0100)
For the consistency model we'll need to know the sizes of the old and
new functions to determine if they're on the stacks of any tasks.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
include/linux/livepatch.h
kernel/livepatch/core.c

index 9787a63b57accafffd9b2ffa84c81e1a7d665eaf..6602b34bed2b5f10b1591a96f9107066c09976e8 100644 (file)
@@ -37,6 +37,8 @@
  * @old_addr:  the address of the function being patched
  * @kobj:      kobject for sysfs resources
  * @stack_node:        list node for klp_ops func_stack list
+ * @old_size:  size of the old function
+ * @new_size:  size of the new function
  * @patched:   the func has been added to the klp_ops list
  */
 struct klp_func {
@@ -56,6 +58,7 @@ struct klp_func {
        unsigned long old_addr;
        struct kobject kobj;
        struct list_head stack_node;
+       unsigned long old_size, new_size;
        bool patched;
 };
 
index 83c4949862b429bc9e92f1135f7b3c3a8183c3ce..10ba3a1578bdf09d6f825a5a2fb8696508b6fd42 100644 (file)
@@ -584,6 +584,22 @@ static int klp_init_object_loaded(struct klp_patch *patch,
                                             &func->old_addr);
                if (ret)
                        return ret;
+
+               ret = kallsyms_lookup_size_offset(func->old_addr,
+                                                 &func->old_size, NULL);
+               if (!ret) {
+                       pr_err("kallsyms size lookup failed for '%s'\n",
+                              func->old_name);
+                       return -ENOENT;
+               }
+
+               ret = kallsyms_lookup_size_offset((unsigned long)func->new_func,
+                                                 &func->new_size, NULL);
+               if (!ret) {
+                       pr_err("kallsyms size lookup failed for '%s' replacement\n",
+                              func->old_name);
+                       return -ENOENT;
+               }
        }
 
        return 0;