The module loader will reject unsigned modules from loading if such a
module attempts to import a symbol which has the import protection bit
set in the kflagstab entry for the symbol.

Signed-off-by: Siddharth Nayyar <sidnay...@google.com>
---
 kernel/module/internal.h |  1 +
 kernel/module/main.c     | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/kernel/module/internal.h b/kernel/module/internal.h
index 061161cc79d9..98faaf8900aa 100644
--- a/kernel/module/internal.h
+++ b/kernel/module/internal.h
@@ -108,6 +108,7 @@ struct find_symbol_arg {
        const u32 *crc;
        const struct kernel_symbol *sym;
        enum mod_license license;
+       bool is_protected;
 };
 
 /* modules using other modules */
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 4437c2a451ea..ece074a6ba7b 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -380,6 +380,7 @@ static bool find_exported_symbol_in_section(const struct 
symsearch *syms,
        fsa->crc = symversion(syms->crcs, sym - syms->start);
        fsa->sym = sym;
        fsa->license = (sym_flags & KSYM_FLAG_GPL_ONLY) ? GPL_ONLY : 
NOT_GPL_ONLY;
+       fsa->is_protected = sym_flags & KSYM_FLAG_PROTECTED;
 
        return true;
 }
@@ -1273,6 +1274,11 @@ static const struct kernel_symbol *resolve_symbol(struct 
module *mod,
                goto getname;
        }
 
+       if (fsa.is_protected && !mod->sig_ok) {
+               fsa.sym = ERR_PTR(-EACCES);
+               goto getname;
+       }
+
 getname:
        /* We must make copy under the lock if we failed to get ref. */
        strscpy(ownername, module_name(fsa.owner), MODULE_NAME_LEN);
@@ -1550,8 +1556,12 @@ static int simplify_symbols(struct module *mod, const 
struct load_info *info)
                                break;
 
                        ret = PTR_ERR(ksym) ?: -ENOENT;
-                       pr_warn("%s: Unknown symbol %s (err %d)\n",
-                               mod->name, name, ret);
+                       if (ret == -EACCES)
+                               pr_warn("%s: Protected symbol %s (err %d)\n",
+                                       mod->name, name, ret);
+                       else
+                               pr_warn("%s: Unknown symbol %s (err %d)\n",
+                                       mod->name, name, ret);
                        break;
 
                default:
-- 
2.51.0.338.gd7d06c2dae-goog


Reply via email to