Commit 01526ed0830643bd53a8434c3068e4c077e1b09d

Authored by Jan Glauber
Committed by Rusty Russell
1 parent 448694a1d5

module: split unset_section_ro_nx function.

Split the unprotect function into a function per section to make
the code more readable and add the missing static declaration.

Signed-off-by: Jan Glauber <jang@linux.vnet.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Showing 1 changed file with 23 additions and 22 deletions Side-by-side Diff

... ... @@ -1607,26 +1607,26 @@
1607 1607 }
1608 1608 }
1609 1609  
1610   -/* Setting memory back to W+X before releasing it */
1611   -void unset_section_ro_nx(struct module *mod, void *module_region)
  1610 +static void unset_module_core_ro_nx(struct module *mod)
1612 1611 {
1613   - if (mod->module_core == module_region) {
1614   - set_page_attributes(mod->module_core + mod->core_text_size,
1615   - mod->module_core + mod->core_size,
1616   - set_memory_x);
1617   - set_page_attributes(mod->module_core,
1618   - mod->module_core + mod->core_ro_size,
1619   - set_memory_rw);
1620   - } else if (mod->module_init == module_region) {
1621   - set_page_attributes(mod->module_init + mod->init_text_size,
1622   - mod->module_init + mod->init_size,
1623   - set_memory_x);
1624   - set_page_attributes(mod->module_init,
1625   - mod->module_init + mod->init_ro_size,
1626   - set_memory_rw);
1627   - }
  1612 + set_page_attributes(mod->module_core + mod->core_text_size,
  1613 + mod->module_core + mod->core_size,
  1614 + set_memory_x);
  1615 + set_page_attributes(mod->module_core,
  1616 + mod->module_core + mod->core_ro_size,
  1617 + set_memory_rw);
1628 1618 }
1629 1619  
  1620 +static void unset_module_init_ro_nx(struct module *mod)
  1621 +{
  1622 + set_page_attributes(mod->module_init + mod->init_text_size,
  1623 + mod->module_init + mod->init_size,
  1624 + set_memory_x);
  1625 + set_page_attributes(mod->module_init,
  1626 + mod->module_init + mod->init_ro_size,
  1627 + set_memory_rw);
  1628 +}
  1629 +
1630 1630 /* Iterate through all modules and set each module's text as RW */
1631 1631 void set_all_modules_text_rw(void)
1632 1632 {
... ... @@ -1670,7 +1670,8 @@
1670 1670 }
1671 1671 #else
1672 1672 static inline void set_section_ro_nx(void *base, unsigned long text_size, unsigned long ro_size, unsigned long total_size) { }
1673   -static inline void unset_section_ro_nx(struct module *mod, void *module_region) { }
  1673 +static void unset_module_core_ro_nx(struct module *mod) { }
  1674 +static void unset_module_init_ro_nx(struct module *mod) { }
1674 1675 #endif
1675 1676  
1676 1677 /* Free a module, remove from lists, etc. */
... ... @@ -1697,7 +1698,7 @@
1697 1698 destroy_params(mod->kp, mod->num_kp);
1698 1699  
1699 1700 /* This may be NULL, but that's OK */
1700   - unset_section_ro_nx(mod, mod->module_init);
  1701 + unset_module_init_ro_nx(mod);
1701 1702 module_free(mod, mod->module_init);
1702 1703 kfree(mod->args);
1703 1704 percpu_modfree(mod);
... ... @@ -1706,7 +1707,7 @@
1706 1707 lockdep_free_key_range(mod->module_core, mod->core_size);
1707 1708  
1708 1709 /* Finally, free the core (containing the module structure) */
1709   - unset_section_ro_nx(mod, mod->module_core);
  1710 + unset_module_core_ro_nx(mod);
1710 1711 module_free(mod, mod->module_core);
1711 1712  
1712 1713 #ifdef CONFIG_MPU
... ... @@ -2932,7 +2933,7 @@
2932 2933 mod->symtab = mod->core_symtab;
2933 2934 mod->strtab = mod->core_strtab;
2934 2935 #endif
2935   - unset_section_ro_nx(mod, mod->module_init);
  2936 + unset_module_init_ro_nx(mod);
2936 2937 module_free(mod, mod->module_init);
2937 2938 mod->module_init = NULL;
2938 2939 mod->init_size = 0;