@@ -146,6 +146,24 @@ static int klp_find_callback(void *data, const char *name, unsigned long addr)
146146 return 0 ;
147147}
148148
149+ static int klp_match_callback (void * data , unsigned long addr )
150+ {
151+ struct klp_find_arg * args = data ;
152+
153+ args -> addr = addr ;
154+ args -> count ++ ;
155+
156+ /*
157+ * Finish the search when the symbol is found for the desired position
158+ * or the position is not defined for a non-unique symbol.
159+ */
160+ if ((args -> pos && (args -> count == args -> pos )) ||
161+ (!args -> pos && (args -> count > 1 )))
162+ return 1 ;
163+
164+ return 0 ;
165+ }
166+
149167static int klp_find_object_symbol (const char * objname , const char * name ,
150168 unsigned long sympos , unsigned long * addr )
151169{
@@ -159,7 +177,7 @@ static int klp_find_object_symbol(const char *objname, const char *name,
159177 if (objname )
160178 module_kallsyms_on_each_symbol (objname , klp_find_callback , & args );
161179 else
162- kallsyms_on_each_symbol ( klp_find_callback , & args );
180+ kallsyms_on_each_match_symbol ( klp_match_callback , name , & args );
163181
164182 /*
165183 * Ensure an address was found. If sympos is 0, ensure symbol is unique;
@@ -182,7 +200,7 @@ static int klp_find_object_symbol(const char *objname, const char *name,
182200 return - EINVAL ;
183201}
184202
185- static int klp_resolve_symbols (Elf64_Shdr * sechdrs , const char * strtab ,
203+ static int klp_resolve_symbols (Elf_Shdr * sechdrs , const char * strtab ,
186204 unsigned int symndx , Elf_Shdr * relasec ,
187205 const char * sec_objname )
188206{
@@ -210,7 +228,7 @@ static int klp_resolve_symbols(Elf64_Shdr *sechdrs, const char *strtab,
210228 relas = (Elf_Rela * ) relasec -> sh_addr ;
211229 /* For each rela in this klp relocation section */
212230 for (i = 0 ; i < relasec -> sh_size / sizeof (Elf_Rela ); i ++ ) {
213- sym = (Elf64_Sym * )sechdrs [symndx ].sh_addr + ELF_R_SYM (relas [i ].r_info );
231+ sym = (Elf_Sym * )sechdrs [symndx ].sh_addr + ELF_R_SYM (relas [i ].r_info );
214232 if (sym -> st_shndx != SHN_LIVEPATCH ) {
215233 pr_err ("symbol %s is not marked as a livepatch symbol\n" ,
216234 strtab + sym -> st_name );
@@ -340,6 +358,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs,
340358 * /sys/kernel/livepatch/<patch>/transition
341359 * /sys/kernel/livepatch/<patch>/force
342360 * /sys/kernel/livepatch/<patch>/replace
361+ * /sys/kernel/livepatch/<patch>/stack_order
343362 * /sys/kernel/livepatch/<patch>/<object>
344363 * /sys/kernel/livepatch/<patch>/<object>/patched
345364 * /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
@@ -445,15 +464,38 @@ static ssize_t replace_show(struct kobject *kobj,
445464 return sysfs_emit (buf , "%d\n" , patch -> replace );
446465}
447466
467+ static ssize_t stack_order_show (struct kobject * kobj ,
468+ struct kobj_attribute * attr , char * buf )
469+ {
470+ struct klp_patch * patch , * this_patch ;
471+ int stack_order = 0 ;
472+
473+ this_patch = container_of (kobj , struct klp_patch , kobj );
474+
475+ mutex_lock (& klp_mutex );
476+
477+ klp_for_each_patch (patch ) {
478+ stack_order ++ ;
479+ if (patch == this_patch )
480+ break ;
481+ }
482+
483+ mutex_unlock (& klp_mutex );
484+
485+ return sysfs_emit (buf , "%d\n" , stack_order );
486+ }
487+
448488static struct kobj_attribute enabled_kobj_attr = __ATTR_RW (enabled );
449489static struct kobj_attribute transition_kobj_attr = __ATTR_RO (transition );
450490static struct kobj_attribute force_kobj_attr = __ATTR_WO (force );
451491static struct kobj_attribute replace_kobj_attr = __ATTR_RO (replace );
492+ static struct kobj_attribute stack_order_kobj_attr = __ATTR_RO (stack_order );
452493static struct attribute * klp_patch_attrs [] = {
453494 & enabled_kobj_attr .attr ,
454495 & transition_kobj_attr .attr ,
455496 & force_kobj_attr .attr ,
456497 & replace_kobj_attr .attr ,
498+ & stack_order_kobj_attr .attr ,
457499 NULL
458500};
459501ATTRIBUTE_GROUPS (klp_patch );
0 commit comments