Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Linux/kernel/module/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 99 kB image not shown  

Quelle  main.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (C) 2002 Richard Henderson
 * Copyright (C) 2001 Rusty Russell, 2002, 2010 Rusty Russell IBM.
 * Copyright (C) 2023 Luis Chamberlain <mcgrof@kernel.org>
 */


#define INCLUDE_VERMAGIC

#include <linux/export.h>
#include <linux/extable.h>
#include <linux/moduleloader.h>
#include <linux/module_signature.h>
#include <linux/trace_events.h>
#include <linux/init.h>
#include <linux/kallsyms.h>
#include <linux/buildid.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/kernel_read_file.h>
#include <linux/kstrtox.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/elf.h>
#include <linux/seq_file.h>
#include <linux/syscalls.h>
#include <linux/fcntl.h>
#include <linux/rcupdate.h>
#include <linux/capability.h>
#include <linux/cpu.h>
#include <linux/moduleparam.h>
#include <linux/errno.h>
#include <linux/err.h>
#include <linux/vermagic.h>
#include <linux/notifier.h>
#include <linux/sched.h>
#include <linux/device.h>
#include <linux/string.h>
#include <linux/mutex.h>
#include <linux/rculist.h>
#include <linux/uaccess.h>
#include <asm/cacheflush.h>
#include <linux/set_memory.h>
#include <asm/mmu_context.h>
#include <linux/license.h>
#include <asm/sections.h>
#include <linux/tracepoint.h>
#include <linux/ftrace.h>
#include <linux/livepatch.h>
#include <linux/async.h>
#include <linux/percpu.h>
#include <linux/kmemleak.h>
#include <linux/jump_label.h>
#include <linux/pfn.h>
#include <linux/bsearch.h>
#include <linux/dynamic_debug.h>
#include <linux/audit.h>
#include <linux/cfi.h>
#include <linux/codetag.h>
#include <linux/debugfs.h>
#include <linux/execmem.h>
#include <uapi/linux/module.h>
#include "internal.h"

#define CREATE_TRACE_POINTS
#include <trace/events/module.h>

/*
 * Mutex protects:
 * 1) List of modules (also safely readable within RCU read section),
 * 2) module_use links,
 * 3) mod_tree.addr_min/mod_tree.addr_max.
 * (delete and add uses RCU list operations).
 */

DEFINE_MUTEX(module_mutex);
LIST_HEAD(modules);

/* Work queue for freeing init sections in success case */
static void do_free_init(struct work_struct *w);
static DECLARE_WORK(init_free_wq, do_free_init);
static LLIST_HEAD(init_free_list);

struct mod_tree_root mod_tree __cacheline_aligned = {
 .addr_min = -1UL,
};

struct symsearch {
 const struct kernel_symbol *start, *stop;
 const u32 *crcs;
 enum mod_license license;
};

/*
 * Bounds of module memory, for speeding up __module_address.
 * Protected by module_mutex.
 */

static void __mod_update_bounds(enum mod_mem_type type __maybe_unused, void *base,
    unsigned int size, struct mod_tree_root *tree)
{
 unsigned long min = (unsigned long)base;
 unsigned long max = min + size;

#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
 if (mod_mem_type_is_core_data(type)) {
  if (min < tree->data_addr_min)
   tree->data_addr_min = min;
  if (max > tree->data_addr_max)
   tree->data_addr_max = max;
  return;
 }
#endif
 if (min < tree->addr_min)
  tree->addr_min = min;
 if (max > tree->addr_max)
  tree->addr_max = max;
}

static void mod_update_bounds(struct module *mod)
{
 for_each_mod_mem_type(type) {
  struct module_memory *mod_mem = &mod->mem[type];

  if (mod_mem->size)
   __mod_update_bounds(type, mod_mem->base, mod_mem->size, &mod_tree);
 }
}

/* Block module loading/unloading? */
static int modules_disabled;
core_param(nomodule, modules_disabled, bint, 0);

static const struct ctl_table module_sysctl_table[] = {
 {
  .procname = "modprobe",
  .data  = &modprobe_path,
  .maxlen  = KMOD_PATH_LEN,
  .mode  = 0644,
  .proc_handler = proc_dostring,
 },
 {
  .procname = "modules_disabled",
  .data  = &modules_disabled,
  .maxlen  = sizeof(int),
  .mode  = 0644,
  /* only handle a transition from default "0" to "1" */
  .proc_handler = proc_dointvec_minmax,
  .extra1  = SYSCTL_ONE,
  .extra2  = SYSCTL_ONE,
 },
};

static int __init init_module_sysctl(void)
{
 register_sysctl_init("kernel", module_sysctl_table);
 return 0;
}

subsys_initcall(init_module_sysctl);

/* Waiting for a module to finish initializing? */
static DECLARE_WAIT_QUEUE_HEAD(module_wq);

static BLOCKING_NOTIFIER_HEAD(module_notify_list);

int register_module_notifier(struct notifier_block *nb)
{
 return blocking_notifier_chain_register(&module_notify_list, nb);
}
EXPORT_SYMBOL(register_module_notifier);

int unregister_module_notifier(struct notifier_block *nb)
{
 return blocking_notifier_chain_unregister(&module_notify_list, nb);
}
EXPORT_SYMBOL(unregister_module_notifier);

/*
 * We require a truly strong try_module_get(): 0 means success.
 * Otherwise an error is returned due to ongoing or failed
 * initialization etc.
 */

static inline int strong_try_module_get(struct module *mod)
{
 BUG_ON(mod && mod->state == MODULE_STATE_UNFORMED);
 if (mod && mod->state == MODULE_STATE_COMING)
  return -EBUSY;
 if (try_module_get(mod))
  return 0;
 else
  return -ENOENT;
}

static inline void add_taint_module(struct module *mod, unsigned flag,
        enum lockdep_ok lockdep_ok)
{
 add_taint(flag, lockdep_ok);
 set_bit(flag, &mod->taints);
}

/*
 * Like strncmp(), except s/-/_/g as per scripts/Makefile.lib:name-fix-token rule.
 */

static int mod_strncmp(const char *str_a, const char *str_b, size_t n)
{
 for (int i = 0; i < n; i++) {
  char a = str_a[i];
  char b = str_b[i];
  int d;

  if (a == '-') a = '_';
  if (b == '-') b = '_';

  d = a - b;
  if (d)
   return d;

  if (!a)
   break;
 }

 return 0;
}

/*
 * A thread that wants to hold a reference to a module only while it
 * is running can call this to safely exit.
 */

void __noreturn __module_put_and_kthread_exit(struct module *mod, long code)
{
 module_put(mod);
 kthread_exit(code);
}
EXPORT_SYMBOL(__module_put_and_kthread_exit);

/* Find a module section: 0 means not found. */
static unsigned int find_sec(const struct load_info *info, const char *name)
{
 unsigned int i;

 for (i = 1; i < info->hdr->e_shnum; i++) {
  Elf_Shdr *shdr = &info->sechdrs[i];
  /* Alloc bit cleared means "ignore it." */
  if ((shdr->sh_flags & SHF_ALLOC)
      && strcmp(info->secstrings + shdr->sh_name, name) == 0)
   return i;
 }
 return 0;
}

/**
 * find_any_unique_sec() - Find a unique section index by name
 * @info: Load info for the module to scan
 * @name: Name of the section we're looking for
 *
 * Locates a unique section by name. Ignores SHF_ALLOC.
 *
 * Return: Section index if found uniquely, zero if absent, negative count
 *         of total instances if multiple were found.
 */

static int find_any_unique_sec(const struct load_info *info, const char *name)
{
 unsigned int idx;
 unsigned int count = 0;
 int i;

 for (i = 1; i < info->hdr->e_shnum; i++) {
  if (strcmp(info->secstrings + info->sechdrs[i].sh_name,
      name) == 0) {
   count++;
   idx = i;
  }
 }
 if (count == 1) {
  return idx;
 } else if (count == 0) {
  return 0;
 } else {
  return -count;
 }
}

/* Find a module section, or NULL. */
static void *section_addr(const struct load_info *info, const char *name)
{
 /* Section 0 has sh_addr 0. */
 return (void *)info->sechdrs[find_sec(info, name)].sh_addr;
}

/* Find a module section, or NULL.  Fill in number of "objects" in section. */
static void *section_objs(const struct load_info *info,
     const char *name,
     size_t object_size,
     unsigned int *num)
{
 unsigned int sec = find_sec(info, name);

 /* Section 0 has sh_addr 0 and sh_size 0. */
 *num = info->sechdrs[sec].sh_size / object_size;
 return (void *)info->sechdrs[sec].sh_addr;
}

/* Find a module section: 0 means not found. Ignores SHF_ALLOC flag. */
static unsigned int find_any_sec(const struct load_info *info, const char *name)
{
 unsigned int i;

 for (i = 1; i < info->hdr->e_shnum; i++) {
  Elf_Shdr *shdr = &info->sechdrs[i];
  if (strcmp(info->secstrings + shdr->sh_name, name) == 0)
   return i;
 }
 return 0;
}

/*
 * Find a module section, or NULL. Fill in number of "objects" in section.
 * Ignores SHF_ALLOC flag.
 */

static __maybe_unused void *any_section_objs(const struct load_info *info,
          const char *name,
          size_t object_size,
          unsigned int *num)
{
 unsigned int sec = find_any_sec(info, name);

 /* Section 0 has sh_addr 0 and sh_size 0. */
 *num = info->sechdrs[sec].sh_size / object_size;
 return (void *)info->sechdrs[sec].sh_addr;
}

#ifndef CONFIG_MODVERSIONS
#define symversion(base, idx) NULL
#else
#define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
#endif

static const char *kernel_symbol_name(const struct kernel_symbol *sym)
{
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
 return offset_to_ptr(&sym->name_offset);
#else
 return sym->name;
#endif
}

static const char *kernel_symbol_namespace(const struct kernel_symbol *sym)
{
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
 if (!sym->namespace_offset)
  return NULL;
 return offset_to_ptr(&sym->namespace_offset);
#else
 return sym->namespace;
#endif
}

int cmp_name(const void *name, const void *sym)
{
 return strcmp(name, kernel_symbol_name(sym));
}

static bool find_exported_symbol_in_section(const struct symsearch *syms,
         struct module *owner,
         struct find_symbol_arg *fsa)
{
 struct kernel_symbol *sym;

 if (!fsa->gplok && syms->license == GPL_ONLY)
  return false;

 sym = bsearch(fsa->name, syms->start, syms->stop - syms->start,
   sizeof(struct kernel_symbol), cmp_name);
 if (!sym)
  return false;

 fsa->owner = owner;
 fsa->crc = symversion(syms->crcs, sym - syms->start);
 fsa->sym = sym;
 fsa->license = syms->license;

 return true;
}

/*
 * Find an exported symbol and return it, along with, (optional) crc and
 * (optional) module which owns it. Needs RCU or module_mutex.
 */

bool find_symbol(struct find_symbol_arg *fsa)
{
 static const struct symsearch arr[] = {
  { __start___ksymtab, __stop___ksymtab, __start___kcrctab,
    NOT_GPL_ONLY },
  { __start___ksymtab_gpl, __stop___ksymtab_gpl,
    __start___kcrctab_gpl,
    GPL_ONLY },
 };
 struct module *mod;
 unsigned int i;

 for (i = 0; i < ARRAY_SIZE(arr); i++)
  if (find_exported_symbol_in_section(&arr[i], NULL, fsa))
   return true;

 list_for_each_entry_rcu(mod, &modules, list,
    lockdep_is_held(&module_mutex)) {
  struct symsearch arr[] = {
   { mod->syms, mod->syms + mod->num_syms, mod->crcs,
     NOT_GPL_ONLY },
   { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
     mod->gpl_crcs,
     GPL_ONLY },
  };

  if (mod->state == MODULE_STATE_UNFORMED)
   continue;

  for (i = 0; i < ARRAY_SIZE(arr); i++)
   if (find_exported_symbol_in_section(&arr[i], mod, fsa))
    return true;
 }

 pr_debug("Failed to find symbol %s\n", fsa->name);
 return false;
}

/*
 * Search for module by name: must hold module_mutex (or RCU for read-only
 * access).
 */

struct module *find_module_all(const char *name, size_t len,
          bool even_unformed)
{
 struct module *mod;

 list_for_each_entry_rcu(mod, &modules, list,
    lockdep_is_held(&module_mutex)) {
  if (!even_unformed && mod->state == MODULE_STATE_UNFORMED)
   continue;
  if (strlen(mod->name) == len && !memcmp(mod->name, name, len))
   return mod;
 }
 return NULL;
}

struct module *find_module(const char *name)
{
 return find_module_all(name, strlen(name), false);
}

#ifdef CONFIG_SMP

static inline void __percpu *mod_percpu(struct module *mod)
{
 return mod->percpu;
}

static int percpu_modalloc(struct module *mod, struct load_info *info)
{
 Elf_Shdr *pcpusec = &info->sechdrs[info->index.pcpu];
 unsigned long align = pcpusec->sh_addralign;

 if (!pcpusec->sh_size)
  return 0;

 if (align > PAGE_SIZE) {
  pr_warn("%s: per-cpu alignment %li > %li\n",
   mod->name, align, PAGE_SIZE);
  align = PAGE_SIZE;
 }

 mod->percpu = __alloc_reserved_percpu(pcpusec->sh_size, align);
 if (!mod->percpu) {
  pr_warn("%s: Could not allocate %lu bytes percpu data\n",
   mod->name, (unsigned long)pcpusec->sh_size);
  return -ENOMEM;
 }
 mod->percpu_size = pcpusec->sh_size;
 return 0;
}

static void percpu_modfree(struct module *mod)
{
 free_percpu(mod->percpu);
}

static unsigned int find_pcpusec(struct load_info *info)
{
 return find_sec(info, ".data..percpu");
}

static void percpu_modcopy(struct module *mod,
      const void *from, unsigned long size)
{
 int cpu;

 for_each_possible_cpu(cpu)
  memcpy(per_cpu_ptr(mod->percpu, cpu), from, size);
}

bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
{
 struct module *mod;
 unsigned int cpu;

 guard(rcu)();
 list_for_each_entry_rcu(mod, &modules, list) {
  if (mod->state == MODULE_STATE_UNFORMED)
   continue;
  if (!mod->percpu_size)
   continue;
  for_each_possible_cpu(cpu) {
   void *start = per_cpu_ptr(mod->percpu, cpu);
   void *va = (void *)addr;

   if (va >= start && va < start + mod->percpu_size) {
    if (can_addr) {
     *can_addr = (unsigned long) (va - start);
     *can_addr += (unsigned long)
      per_cpu_ptr(mod->percpu,
           get_boot_cpu_id());
    }
    return true;
   }
  }
 }
 return false;
}

/**
 * is_module_percpu_address() - test whether address is from module static percpu
 * @addr: address to test
 *
 * Test whether @addr belongs to module static percpu area.
 *
 * Return: %true if @addr is from module static percpu area
 */

bool is_module_percpu_address(unsigned long addr)
{
 return __is_module_percpu_address(addr, NULL);
}

#else /* ... !CONFIG_SMP */

static inline void __percpu *mod_percpu(struct module *mod)
{
 return NULL;
}
static int percpu_modalloc(struct module *mod, struct load_info *info)
{
 /* UP modules shouldn't have this section: ENOMEM isn't quite right */
 if (info->sechdrs[info->index.pcpu].sh_size != 0)
  return -ENOMEM;
 return 0;
}
static inline void percpu_modfree(struct module *mod)
{
}
static unsigned int find_pcpusec(struct load_info *info)
{
 return 0;
}
static inline void percpu_modcopy(struct module *mod,
      const void *from, unsigned long size)
{
 /* pcpusec should be 0, and size of that section should be 0. */
 BUG_ON(size != 0);
}
bool is_module_percpu_address(unsigned long addr)
{
 return false;
}

bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
{
 return false;
}

#endif /* CONFIG_SMP */

#define MODINFO_ATTR(field) \
static void setup_modinfo_##field(struct module *mod, const char *s)  \
{                                                                     \
 mod->field = kstrdup(s, GFP_KERNEL);                          \
}                                                                     \
static ssize_t show_modinfo_##field(const struct module_attribute *mattr, \
   struct module_kobject *mk, char *buffer)      \
{                                                                     \
 return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field);  \
}                                                                     \
static int modinfo_##field##_exists(struct module *mod)               \
{                                                                     \
 return mod->field != NULL;                                    \
}                                                                     \
static void free_modinfo_##field(struct module *mod)                  \
{                                                                     \
 kfree(mod->field);                                            \
 mod->field = NULL;                                            \
}                                                                     \
static const struct module_attribute modinfo_##field = {              \
 .attr = { .name = __stringify(field), .mode = 0444 },         \
 .show = show_modinfo_##field,                                 \
 .setup = setup_modinfo_##field,                               \
 .test = modinfo_##field##_exists,                             \
 .free = free_modinfo_##field,                                 \
};

MODINFO_ATTR(version);
MODINFO_ATTR(srcversion);

static struct {
 char name[MODULE_NAME_LEN];
 char taints[MODULE_FLAGS_BUF_SIZE];
} last_unloaded_module;

#ifdef CONFIG_MODULE_UNLOAD

EXPORT_TRACEPOINT_SYMBOL(module_get);

/* MODULE_REF_BASE is the base reference count by kmodule loader. */
#define MODULE_REF_BASE 1

/* Init the unload section of the module. */
static int module_unload_init(struct module *mod)
{
 /*
 * Initialize reference counter to MODULE_REF_BASE.
 * refcnt == 0 means module is going.
 */

 atomic_set(&mod->refcnt, MODULE_REF_BASE);

 INIT_LIST_HEAD(&mod->source_list);
 INIT_LIST_HEAD(&mod->target_list);

 /* Hold reference count during initialization. */
 atomic_inc(&mod->refcnt);

 return 0;
}

/* Does a already use b? */
static int already_uses(struct module *a, struct module *b)
{
 struct module_use *use;

 list_for_each_entry(use, &b->source_list, source_list) {
  if (use->source == a)
   return 1;
 }
 pr_debug("%s does not use %s!\n", a->name, b->name);
 return 0;
}

/*
 * Module a uses b
 *  - we add 'a' as a "source", 'b' as a "target" of module use
 *  - the module_use is added to the list of 'b' sources (so
 *    'b' can walk the list to see who sourced them), and of 'a'
 *    targets (so 'a' can see what modules it targets).
 */

static int add_module_usage(struct module *a, struct module *b)
{
 struct module_use *use;

 pr_debug("Allocating new usage for %s.\n", a->name);
 use = kmalloc(sizeof(*use), GFP_ATOMIC);
 if (!use)
  return -ENOMEM;

 use->source = a;
 use->target = b;
 list_add(&use->source_list, &b->source_list);
 list_add(&use->target_list, &a->target_list);
 return 0;
}

/* Module a uses b: caller needs module_mutex() */
static int ref_module(struct module *a, struct module *b)
{
 int err;

 if (b == NULL || already_uses(a, b))
  return 0;

 /* If module isn't available, we fail. */
 err = strong_try_module_get(b);
 if (err)
  return err;

 err = add_module_usage(a, b);
 if (err) {
  module_put(b);
  return err;
 }
 return 0;
}

/* Clear the unload stuff of the module. */
static void module_unload_free(struct module *mod)
{
 struct module_use *use, *tmp;

 mutex_lock(&module_mutex);
 list_for_each_entry_safe(use, tmp, &mod->target_list, target_list) {
  struct module *i = use->target;
  pr_debug("%s unusing %s\n", mod->name, i->name);
  module_put(i);
  list_del(&use->source_list);
  list_del(&use->target_list);
  kfree(use);
 }
 mutex_unlock(&module_mutex);
}

#ifdef CONFIG_MODULE_FORCE_UNLOAD
static inline int try_force_unload(unsigned int flags)
{
 int ret = (flags & O_TRUNC);
 if (ret)
  add_taint(TAINT_FORCED_RMMOD, LOCKDEP_NOW_UNRELIABLE);
 return ret;
}
#else
static inline int try_force_unload(unsigned int flags)
{
 return 0;
}
#endif /* CONFIG_MODULE_FORCE_UNLOAD */

/* Try to release refcount of module, 0 means success. */
static int try_release_module_ref(struct module *mod)
{
 int ret;

 /* Try to decrement refcnt which we set at loading */
 ret = atomic_sub_return(MODULE_REF_BASE, &mod->refcnt);
 BUG_ON(ret < 0);
 if (ret)
  /* Someone can put this right now, recover with checking */
  ret = atomic_add_unless(&mod->refcnt, MODULE_REF_BASE, 0);

 return ret;
}

static int try_stop_module(struct module *mod, int flags, int *forced)
{
 /* If it's not unused, quit unless we're forcing. */
 if (try_release_module_ref(mod) != 0) {
  *forced = try_force_unload(flags);
  if (!(*forced))
   return -EWOULDBLOCK;
 }

 /* Mark it as dying. */
 mod->state = MODULE_STATE_GOING;

 return 0;
}

/**
 * module_refcount() - return the refcount or -1 if unloading
 * @mod: the module we're checking
 *
 * Return:
 * -1 if the module is in the process of unloading
 * otherwise the number of references in the kernel to the module
 */

int module_refcount(struct module *mod)
{
 return atomic_read(&mod->refcnt) - MODULE_REF_BASE;
}
EXPORT_SYMBOL(module_refcount);

/* This exists whether we can unload or not */
static void free_module(struct module *mod);

SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
  unsigned int, flags)
{
 struct module *mod;
 char name[MODULE_NAME_LEN];
 char buf[MODULE_FLAGS_BUF_SIZE];
 int ret, len, forced = 0;

 if (!capable(CAP_SYS_MODULE) || modules_disabled)
  return -EPERM;

 len = strncpy_from_user(name, name_user, MODULE_NAME_LEN);
 if (len == 0 || len == MODULE_NAME_LEN)
  return -ENOENT;
 if (len < 0)
  return len;

 audit_log_kern_module(name);

 if (mutex_lock_interruptible(&module_mutex) != 0)
  return -EINTR;

 mod = find_module(name);
 if (!mod) {
  ret = -ENOENT;
  goto out;
 }

 if (!list_empty(&mod->source_list)) {
  /* Other modules depend on us: get rid of them first. */
  ret = -EWOULDBLOCK;
  goto out;
 }

 /* Doing init or already dying? */
 if (mod->state != MODULE_STATE_LIVE) {
  /* FIXME: if (force), slam module count damn the torpedoes */
  pr_debug("%s already dying\n", mod->name);
  ret = -EBUSY;
  goto out;
 }

 /* If it has an init func, it must have an exit func to unload */
 if (mod->init && !mod->exit) {
  forced = try_force_unload(flags);
  if (!forced) {
   /* This module can't be removed */
   ret = -EBUSY;
   goto out;
  }
 }

 ret = try_stop_module(mod, flags, &forced);
 if (ret != 0)
  goto out;

 mutex_unlock(&module_mutex);
 /* Final destruction now no one is using it. */
 if (mod->exit != NULL)
  mod->exit();
 blocking_notifier_call_chain(&module_notify_list,
         MODULE_STATE_GOING, mod);
 klp_module_going(mod);
 ftrace_release_mod(mod);

 async_synchronize_full();

 /* Store the name and taints of the last unloaded module for diagnostic purposes */
 strscpy(last_unloaded_module.name, mod->name);
 strscpy(last_unloaded_module.taints, module_flags(mod, buf, false));

 free_module(mod);
 /* someone could wait for the module in add_unformed_module() */
 wake_up_all(&module_wq);
 return 0;
out:
 mutex_unlock(&module_mutex);
 return ret;
}

void __symbol_put(const char *symbol)
{
 struct find_symbol_arg fsa = {
  .name = symbol,
  .gplok = true,
 };

 guard(rcu)();
 BUG_ON(!find_symbol(&fsa));
 module_put(fsa.owner);
}
EXPORT_SYMBOL(__symbol_put);

/* Note this assumes addr is a function, which it currently always is. */
void symbol_put_addr(void *addr)
{
 struct module *modaddr;
 unsigned long a = (unsigned long)dereference_function_descriptor(addr);

 if (core_kernel_text(a))
  return;

 /*
 * Even though we hold a reference on the module; we still need to
 * RCU read section in order to safely traverse the data structure.
 */

 guard(rcu)();
 modaddr = __module_text_address(a);
 BUG_ON(!modaddr);
 module_put(modaddr);
}
EXPORT_SYMBOL_GPL(symbol_put_addr);

static ssize_t show_refcnt(const struct module_attribute *mattr,
      struct module_kobject *mk, char *buffer)
{
 return sprintf(buffer, "%i\n", module_refcount(mk->mod));
}

static const struct module_attribute modinfo_refcnt =
 __ATTR(refcnt, 0444, show_refcnt, NULL);

void __module_get(struct module *module)
{
 if (module) {
  atomic_inc(&module->refcnt);
  trace_module_get(module, _RET_IP_);
 }
}
EXPORT_SYMBOL(__module_get);

bool try_module_get(struct module *module)
{
 bool ret = true;

 if (module) {
  /* Note: here, we can fail to get a reference */
  if (likely(module_is_live(module) &&
      atomic_inc_not_zero(&module->refcnt) != 0))
   trace_module_get(module, _RET_IP_);
  else
   ret = false;
 }
 return ret;
}
EXPORT_SYMBOL(try_module_get);

void module_put(struct module *module)
{
 int ret;

 if (module) {
  ret = atomic_dec_if_positive(&module->refcnt);
  WARN_ON(ret < 0); /* Failed to put refcount */
  trace_module_put(module, _RET_IP_);
 }
}
EXPORT_SYMBOL(module_put);

#else /* !CONFIG_MODULE_UNLOAD */
static inline void module_unload_free(struct module *mod)
{
}

static int ref_module(struct module *a, struct module *b)
{
 return strong_try_module_get(b);
}

static inline int module_unload_init(struct module *mod)
{
 return 0;
}
#endif /* CONFIG_MODULE_UNLOAD */

size_t module_flags_taint(unsigned long taints, char *buf)
{
 size_t l = 0;
 int i;

 for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
  if (taint_flags[i].module && test_bit(i, &taints))
   buf[l++] = taint_flags[i].c_true;
 }

 return l;
}

static ssize_t show_initstate(const struct module_attribute *mattr,
         struct module_kobject *mk, char *buffer)
{
 const char *state = "unknown";

 switch (mk->mod->state) {
 case MODULE_STATE_LIVE:
  state = "live";
  break;
 case MODULE_STATE_COMING:
  state = "coming";
  break;
 case MODULE_STATE_GOING:
  state = "going";
  break;
 default:
  BUG();
 }
 return sprintf(buffer, "%s\n", state);
}

static const struct module_attribute modinfo_initstate =
 __ATTR(initstate, 0444, show_initstate, NULL);

static ssize_t store_uevent(const struct module_attribute *mattr,
       struct module_kobject *mk,
       const char *buffer, size_t count)
{
 int rc;

 rc = kobject_synth_uevent(&mk->kobj, buffer, count);
 return rc ? rc : count;
}

const struct module_attribute module_uevent =
 __ATTR(uevent, 0200, NULL, store_uevent);

static ssize_t show_coresize(const struct module_attribute *mattr,
        struct module_kobject *mk, char *buffer)
{
 unsigned int size = mk->mod->mem[MOD_TEXT].size;

 if (!IS_ENABLED(CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC)) {
  for_class_mod_mem_type(type, core_data)
   size += mk->mod->mem[type].size;
 }
 return sprintf(buffer, "%u\n", size);
}

static const struct module_attribute modinfo_coresize =
 __ATTR(coresize, 0444, show_coresize, NULL);

#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
static ssize_t show_datasize(const struct module_attribute *mattr,
        struct module_kobject *mk, char *buffer)
{
 unsigned int size = 0;

 for_class_mod_mem_type(type, core_data)
  size += mk->mod->mem[type].size;
 return sprintf(buffer, "%u\n", size);
}

static const struct module_attribute modinfo_datasize =
 __ATTR(datasize, 0444, show_datasize, NULL);
#endif

static ssize_t show_initsize(const struct module_attribute *mattr,
        struct module_kobject *mk, char *buffer)
{
 unsigned int size = 0;

 for_class_mod_mem_type(type, init)
  size += mk->mod->mem[type].size;
 return sprintf(buffer, "%u\n", size);
}

static const struct module_attribute modinfo_initsize =
 __ATTR(initsize, 0444, show_initsize, NULL);

static ssize_t show_taint(const struct module_attribute *mattr,
     struct module_kobject *mk, char *buffer)
{
 size_t l;

 l = module_flags_taint(mk->mod->taints, buffer);
 buffer[l++] = '\n';
 return l;
}

static const struct module_attribute modinfo_taint =
 __ATTR(taint, 0444, show_taint, NULL);

const struct module_attribute *const modinfo_attrs[] = {
 &module_uevent,
 &modinfo_version,
 &modinfo_srcversion,
 &modinfo_initstate,
 &modinfo_coresize,
#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
 &modinfo_datasize,
#endif
 &modinfo_initsize,
 &modinfo_taint,
#ifdef CONFIG_MODULE_UNLOAD
 &modinfo_refcnt,
#endif
 NULL,
};

const size_t modinfo_attrs_count = ARRAY_SIZE(modinfo_attrs);

static const char vermagic[] = VERMAGIC_STRING;

int try_to_force_load(struct module *mod, const char *reason)
{
#ifdef CONFIG_MODULE_FORCE_LOAD
 if (!test_taint(TAINT_FORCED_MODULE))
  pr_warn("%s: %s: kernel tainted.\n", mod->name, reason);
 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE);
 return 0;
#else
 return -ENOEXEC;
#endif
}

/* Parse tag=value strings from .modinfo section */
char *module_next_tag_pair(char *string, unsigned long *secsize)
{
 /* Skip non-zero chars */
 while (string[0]) {
  string++;
  if ((*secsize)-- <= 1)
   return NULL;
 }

 /* Skip any zero padding. */
 while (!string[0]) {
  string++;
  if ((*secsize)-- <= 1)
   return NULL;
 }
 return string;
}

static char *get_next_modinfo(const struct load_info *info, const char *tag,
         char *prev)
{
 char *p;
 unsigned int taglen = strlen(tag);
 Elf_Shdr *infosec = &info->sechdrs[info->index.info];
 unsigned long size = infosec->sh_size;

 /*
 * get_modinfo() calls made before rewrite_section_headers()
 * must use sh_offset, as sh_addr isn't set!
 */

 char *modinfo = (char *)info->hdr + infosec->sh_offset;

 if (prev) {
  size -= prev - modinfo;
  modinfo = module_next_tag_pair(prev, &size);
 }

 for (p = modinfo; p; p = module_next_tag_pair(p, &size)) {
  if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
   return p + taglen + 1;
 }
 return NULL;
}

static char *get_modinfo(const struct load_info *info, const char *tag)
{
 return get_next_modinfo(info, tag, NULL);
}

/**
 * verify_module_namespace() - does @modname have access to this symbol's @namespace
 * @namespace: export symbol namespace
 * @modname: module name
 *
 * If @namespace is prefixed with "module:" to indicate it is a module namespace
 * then test if @modname matches any of the comma separated patterns.
 *
 * The patterns only support tail-glob.
 */

static bool verify_module_namespace(const char *namespaceconst char *modname)
{
 size_t len, modlen = strlen(modname);
 const char *prefix = "module:";
 const char *sep;
 bool glob;

 if (!strstarts(namespace, prefix))
  return false;

 for (namespace += strlen(prefix); *namespacenamespace = sep) {
  sep = strchrnul(namespace',');
  len = sep - namespace;

  glob = false;
  if (sep[-1] == '*') {
   len--;
   glob = true;
  }

  if (*sep)
   sep++;

  if (mod_strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
   return true;
 }

 return false;
}

static int verify_namespace_is_imported(const struct load_info *info,
     const struct kernel_symbol *sym,
     struct module *mod)
{
 const char *namespace;
 char *imported_namespace;

 namespace = kernel_symbol_namespace(sym);
 if (namespace && namespace[0]) {

  if (verify_module_namespace(namespace, mod->name))
   return 0;

  for_each_modinfo_entry(imported_namespace, info, "import_ns") {
   if (strcmp(namespace, imported_namespace) == 0)
    return 0;
  }
#ifdef CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS
  pr_warn(
#else
  pr_err(
#endif
   "%s: module uses symbol (%s) from namespace %s, but does not import it.\n",
   mod->name, kernel_symbol_name(sym), namespace);
#ifndef CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS
  return -EINVAL;
#endif
 }
 return 0;
}

static bool inherit_taint(struct module *mod, struct module *owner, const char *name)
{
 if (!owner || !test_bit(TAINT_PROPRIETARY_MODULE, &owner->taints))
  return true;

 if (mod->using_gplonly_symbols) {
  pr_err("%s: module using GPL-only symbols uses symbols %s from proprietary module %s.\n",
   mod->name, name, owner->name);
  return false;
 }

 if (!test_bit(TAINT_PROPRIETARY_MODULE, &mod->taints)) {
  pr_warn("%s: module uses symbols %s from proprietary module %s, inheriting taint.\n",
   mod->name, name, owner->name);
  set_bit(TAINT_PROPRIETARY_MODULE, &mod->taints);
 }
 return true;
}

/* Resolve a symbol for this module.  I.e. if we find one, record usage. */
static const struct kernel_symbol *resolve_symbol(struct module *mod,
        const struct load_info *info,
        const char *name,
        char ownername[])
{
 struct find_symbol_arg fsa = {
  .name = name,
  .gplok = !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)),
  .warn = true,
 };
 int err;

 /*
 * The module_mutex should not be a heavily contended lock;
 * if we get the occasional sleep here, we'll go an extra iteration
 * in the wait_event_interruptible(), which is harmless.
 */

 sched_annotate_sleep();
 mutex_lock(&module_mutex);
 if (!find_symbol(&fsa))
  goto unlock;

 if (fsa.license == GPL_ONLY)
  mod->using_gplonly_symbols = true;

 if (!inherit_taint(mod, fsa.owner, name)) {
  fsa.sym = NULL;
  goto getname;
 }

 if (!check_version(info, name, mod, fsa.crc)) {
  fsa.sym = ERR_PTR(-EINVAL);
  goto getname;
 }

 err = verify_namespace_is_imported(info, fsa.sym, mod);
 if (err) {
  fsa.sym = ERR_PTR(err);
  goto getname;
 }

 err = ref_module(mod, fsa.owner);
 if (err) {
  fsa.sym = ERR_PTR(err);
  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);
unlock:
 mutex_unlock(&module_mutex);
 return fsa.sym;
}

static const struct kernel_symbol *
resolve_symbol_wait(struct module *mod,
      const struct load_info *info,
      const char *name)
{
 const struct kernel_symbol *ksym;
 char owner[MODULE_NAME_LEN];

 if (wait_event_interruptible_timeout(module_wq,
   !IS_ERR(ksym = resolve_symbol(mod, info, name, owner))
   || PTR_ERR(ksym) != -EBUSY,
          30 * HZ) <= 0) {
  pr_warn("%s: gave up waiting for init of module %s.\n",
   mod->name, owner);
 }
 return ksym;
}

void __weak module_arch_cleanup(struct module *mod)
{
}

void __weak module_arch_freeing_init(struct module *mod)
{
}

static int module_memory_alloc(struct module *mod, enum mod_mem_type type)
{
 unsigned int size = PAGE_ALIGN(mod->mem[type].size);
 enum execmem_type execmem_type;
 void *ptr;

 mod->mem[type].size = size;

 if (mod_mem_type_is_data(type))
  execmem_type = EXECMEM_MODULE_DATA;
 else
  execmem_type = EXECMEM_MODULE_TEXT;

 ptr = execmem_alloc_rw(execmem_type, size);
 if (!ptr)
  return -ENOMEM;

 mod->mem[type].is_rox = execmem_is_rox(execmem_type);

 /*
 * The pointer to these blocks of memory are stored on the module
 * structure and we keep that around so long as the module is
 * around. We only free that memory when we unload the module.
 * Just mark them as not being a leak then. The .init* ELF
 * sections *do* get freed after boot so we *could* treat them
 * slightly differently with kmemleak_ignore() and only grey
 * them out as they work as typical memory allocations which
 * *do* eventually get freed, but let's just keep things simple
 * and avoid *any* false positives.
 */

 if (!mod->mem[type].is_rox)
  kmemleak_not_leak(ptr);

 memset(ptr, 0, size);
 mod->mem[type].base = ptr;

 return 0;
}

static void module_memory_restore_rox(struct module *mod)
{
 for_class_mod_mem_type(type, text) {
  struct module_memory *mem = &mod->mem[type];

  if (mem->is_rox)
   execmem_restore_rox(mem->base, mem->size);
 }
}

static void module_memory_free(struct module *mod, enum mod_mem_type type)
{
 struct module_memory *mem = &mod->mem[type];

 execmem_free(mem->base);
}

static void free_mod_mem(struct module *mod)
{
 for_each_mod_mem_type(type) {
  struct module_memory *mod_mem = &mod->mem[type];

  if (type == MOD_DATA)
   continue;

  /* Free lock-classes; relies on the preceding sync_rcu(). */
  lockdep_free_key_range(mod_mem->base, mod_mem->size);
  if (mod_mem->size)
   module_memory_free(mod, type);
 }

 /* MOD_DATA hosts mod, so free it at last */
 lockdep_free_key_range(mod->mem[MOD_DATA].base, mod->mem[MOD_DATA].size);
 module_memory_free(mod, MOD_DATA);
}

/* Free a module, remove from lists, etc. */
static void free_module(struct module *mod)
{
 trace_module_free(mod);

 codetag_unload_module(mod);

 mod_sysfs_teardown(mod);

 /*
 * We leave it in list to prevent duplicate loads, but make sure
 * that noone uses it while it's being deconstructed.
 */

 mutex_lock(&module_mutex);
 mod->state = MODULE_STATE_UNFORMED;
 mutex_unlock(&module_mutex);

 /* Arch-specific cleanup. */
 module_arch_cleanup(mod);

 /* Module unload stuff */
 module_unload_free(mod);

 /* Free any allocated parameters. */
 destroy_params(mod->kp, mod->num_kp);

 if (is_livepatch_module(mod))
  free_module_elf(mod);

 /* Now we can delete it from the lists */
 mutex_lock(&module_mutex);
 /* Unlink carefully: kallsyms could be walking list. */
 list_del_rcu(&mod->list);
 mod_tree_remove(mod);
 /* Remove this module from bug list, this uses list_del_rcu */
 module_bug_cleanup(mod);
 /* Wait for RCU synchronizing before releasing mod->list and buglist. */
 synchronize_rcu();
 if (try_add_tainted_module(mod))
  pr_err("%s: adding tainted module to the unloaded tainted modules list failed.\n",
         mod->name);
 mutex_unlock(&module_mutex);

 /* This may be empty, but that's OK */
 module_arch_freeing_init(mod);
 kfree(mod->args);
 percpu_modfree(mod);

 free_mod_mem(mod);
}

void *__symbol_get(const char *symbol)
{
 struct find_symbol_arg fsa = {
  .name = symbol,
  .gplok = true,
  .warn = true,
 };

 scoped_guard(rcu) {
  if (!find_symbol(&fsa))
   return NULL;
  if (fsa.license != GPL_ONLY) {
   pr_warn("failing symbol_get of non-GPLONLY symbol %s.\n",
    symbol);
   return NULL;
  }
  if (strong_try_module_get(fsa.owner))
   return NULL;
 }
 return (void *)kernel_symbol_value(fsa.sym);
}
EXPORT_SYMBOL_GPL(__symbol_get);

/*
 * Ensure that an exported symbol [global namespace] does not already exist
 * in the kernel or in some other module's exported symbol table.
 *
 * You must hold the module_mutex.
 */

static int verify_exported_symbols(struct module *mod)
{
 unsigned int i;
 const struct kernel_symbol *s;
 struct {
  const struct kernel_symbol *sym;
  unsigned int num;
 } arr[] = {
  { mod->syms, mod->num_syms },
  { mod->gpl_syms, mod->num_gpl_syms },
 };

 for (i = 0; i < ARRAY_SIZE(arr); i++) {
  for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
   struct find_symbol_arg fsa = {
    .name = kernel_symbol_name(s),
    .gplok = true,
   };
   if (find_symbol(&fsa)) {
    pr_err("%s: exports duplicate symbol %s"
           " (owned by %s)\n",
           mod->name, kernel_symbol_name(s),
           module_name(fsa.owner));
    return -ENOEXEC;
   }
  }
 }
 return 0;
}

static bool ignore_undef_symbol(Elf_Half emachine, const char *name)
{
 /*
 * On x86, PIC code and Clang non-PIC code may have call foo@PLT. GNU as
 * before 2.37 produces an unreferenced _GLOBAL_OFFSET_TABLE_ on x86-64.
 * i386 has a similar problem but may not deserve a fix.
 *
 * If we ever have to ignore many symbols, consider refactoring the code to
 * only warn if referenced by a relocation.
 */

 if (emachine == EM_386 || emachine == EM_X86_64)
  return !strcmp(name, "_GLOBAL_OFFSET_TABLE_");
 return false;
}

/* Change all symbols so that st_value encodes the pointer directly. */
static int simplify_symbols(struct module *mod, const struct load_info *info)
{
 Elf_Shdr *symsec = &info->sechdrs[info->index.sym];
 Elf_Sym *sym = (void *)symsec->sh_addr;
 unsigned long secbase;
 unsigned int i;
 int ret = 0;
 const struct kernel_symbol *ksym;

 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
  const char *name = info->strtab + sym[i].st_name;

  switch (sym[i].st_shndx) {
  case SHN_COMMON:
   /* Ignore common symbols */
   if (!strncmp(name, "__gnu_lto", 9))
    break;

   /*
 * We compiled with -fno-common.  These are not
 * supposed to happen.
 */

   pr_debug("Common symbol: %s\n", name);
   pr_warn("%s: please compile with -fno-common\n",
          mod->name);
   ret = -ENOEXEC;
   break;

  case SHN_ABS:
   /* Don't need to do anything */
   pr_debug("Absolute symbol: 0x%08lx %s\n",
     (long)sym[i].st_value, name);
   break;

  case SHN_LIVEPATCH:
   /* Livepatch symbols are resolved by livepatch */
   break;

  case SHN_UNDEF:
   ksym = resolve_symbol_wait(mod, info, name);
   /* Ok if resolved.  */
   if (ksym && !IS_ERR(ksym)) {
    sym[i].st_value = kernel_symbol_value(ksym);
    break;
   }

   /* Ok if weak or ignored.  */
   if (!ksym &&
       (ELF_ST_BIND(sym[i].st_info) == STB_WEAK ||
        ignore_undef_symbol(info->hdr->e_machine, name)))
    break;

   ret = PTR_ERR(ksym) ?: -ENOENT;
   pr_warn("%s: Unknown symbol %s (err %d)\n",
    mod->name, name, ret);
   break;

  default:
   /* Divert to percpu allocation if a percpu var. */
   if (sym[i].st_shndx == info->index.pcpu)
    secbase = (unsigned long)mod_percpu(mod);
   else
    secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
   sym[i].st_value += secbase;
   break;
  }
 }

 return ret;
}

static int apply_relocations(struct module *mod, const struct load_info *info)
{
 unsigned int i;
 int err = 0;

 /* Now do relocations. */
 for (i = 1; i < info->hdr->e_shnum; i++) {
  unsigned int infosec = info->sechdrs[i].sh_info;

  /* Not a valid relocation section? */
  if (infosec >= info->hdr->e_shnum)
   continue;

  /*
 * Don't bother with non-allocated sections.
 * An exception is the percpu section, which has separate allocations
 * for individual CPUs. We relocate the percpu section in the initial
 * ELF template and subsequently copy it to the per-CPU destinations.
 */

  if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC) &&
      (!infosec || infosec != info->index.pcpu))
   continue;

  if (info->sechdrs[i].sh_flags & SHF_RELA_LIVEPATCH)
   err = klp_apply_section_relocs(mod, info->sechdrs,
             info->secstrings,
             info->strtab,
             info->index.sym, i,
             NULL);
  else if (info->sechdrs[i].sh_type == SHT_REL)
   err = apply_relocate(info->sechdrs, info->strtab,
          info->index.sym, i, mod);
  else if (info->sechdrs[i].sh_type == SHT_RELA)
   err = apply_relocate_add(info->sechdrs, info->strtab,
       info->index.sym, i, mod);
  if (err < 0)
   break;
 }
 return err;
}

/* Additional bytes needed by arch in front of individual sections */
unsigned int __weak arch_mod_section_prepend(struct module *mod,
          unsigned int section)
{
 /* default implementation just returns zero */
 return 0;
}

long module_get_offset_and_type(struct module *mod, enum mod_mem_type type,
    Elf_Shdr *sechdr, unsigned int section)
{
 long offset;
 long mask = ((unsigned long)(type) & SH_ENTSIZE_TYPE_MASK) << SH_ENTSIZE_TYPE_SHIFT;

 mod->mem[type].size += arch_mod_section_prepend(mod, section);
 offset = ALIGN(mod->mem[type].size, sechdr->sh_addralign ?: 1);
 mod->mem[type].size = offset + sechdr->sh_size;

 WARN_ON_ONCE(offset & mask);
 return offset | mask;
}

bool module_init_layout_section(const char *sname)
{
#ifndef CONFIG_MODULE_UNLOAD
 if (module_exit_section(sname))
  return true;
#endif
 return module_init_section(sname);
}

static void __layout_sections(struct module *mod, struct load_info *info, bool is_init)
{
 unsigned int m, i;

 /*
 * { Mask of required section header flags,
 *   Mask of excluded section header flags }
 */

 static const unsigned long masks[][2] = {
  { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL },
  { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL },
  { SHF_RO_AFTER_INIT | SHF_ALLOC, ARCH_SHF_SMALL },
  { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL },
  { ARCH_SHF_SMALL | SHF_ALLOC, 0 }
 };
 static const int core_m_to_mem_type[] = {
  MOD_TEXT,
  MOD_RODATA,
  MOD_RO_AFTER_INIT,
  MOD_DATA,
  MOD_DATA,
 };
 static const int init_m_to_mem_type[] = {
  MOD_INIT_TEXT,
  MOD_INIT_RODATA,
  MOD_INVALID,
  MOD_INIT_DATA,
  MOD_INIT_DATA,
 };

 for (m = 0; m < ARRAY_SIZE(masks); ++m) {
  enum mod_mem_type type = is_init ? init_m_to_mem_type[m] : core_m_to_mem_type[m];

  for (i = 0; i < info->hdr->e_shnum; ++i) {
   Elf_Shdr *s = &info->sechdrs[i];
   const char *sname = info->secstrings + s->sh_name;

   if ((s->sh_flags & masks[m][0]) != masks[m][0]
       || (s->sh_flags & masks[m][1])
       || s->sh_entsize != ~0UL
       || is_init != module_init_layout_section(sname))
    continue;

   if (WARN_ON_ONCE(type == MOD_INVALID))
    continue;

   /*
 * Do not allocate codetag memory as we load it into
 * preallocated contiguous memory.
 */

   if (codetag_needs_module_section(mod, sname, s->sh_size)) {
    /*
 * s->sh_entsize won't be used but populate the
 * type field to avoid confusion.
 */

    s->sh_entsize = ((unsigned long)(type) & SH_ENTSIZE_TYPE_MASK)
      << SH_ENTSIZE_TYPE_SHIFT;
    continue;
   }

   s->sh_entsize = module_get_offset_and_type(mod, type, s, i);
   pr_debug("\t%s\n", sname);
  }
 }
}

/*
 * Lay out the SHF_ALLOC sections in a way not dissimilar to how ld
 * might -- code, read-only data, read-write data, small data.  Tally
 * sizes, and place the offsets into sh_entsize fields: high bit means it
 * belongs in init.
 */

static void layout_sections(struct module *mod, struct load_info *info)
{
 unsigned int i;

 for (i = 0; i < info->hdr->e_shnum; i++)
  info->sechdrs[i].sh_entsize = ~0UL;

 pr_debug("Core section allocation order for %s:\n", mod->name);
 __layout_sections(mod, info, false);

 pr_debug("Init section allocation order for %s:\n", mod->name);
 __layout_sections(mod, info, true);
}

static void module_license_taint_check(struct module *mod, const char *license)
{
 if (!license)
  license = "unspecified";

 if (!license_is_gpl_compatible(license)) {
  if (!test_taint(TAINT_PROPRIETARY_MODULE))
   pr_warn("%s: module license '%s' taints kernel.\n",
    mod->name, license);
  add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
     LOCKDEP_NOW_UNRELIABLE);
 }
}

static int setup_modinfo(struct module *mod, struct load_info *info)
{
 const struct module_attribute *attr;
 char *imported_namespace;
 int i;

 for (i = 0; (attr = modinfo_attrs[i]); i++) {
  if (attr->setup)
   attr->setup(mod, get_modinfo(info, attr->attr.name));
 }

 for_each_modinfo_entry(imported_namespace, info, "import_ns") {
  /*
 * 'module:' prefixed namespaces are implicit, disallow
 * explicit imports.
 */

  if (strstarts(imported_namespace, "module:")) {
   pr_err("%s: module tries to import module namespace: %s\n",
          mod->name, imported_namespace);
   return -EPERM;
  }
 }

 return 0;
}

static void free_modinfo(struct module *mod)
{
 const struct module_attribute *attr;
 int i;

 for (i = 0; (attr = modinfo_attrs[i]); i++) {
  if (attr->free)
   attr->free(mod);
 }
}

bool __weak module_init_section(const char *name)
{
 return strstarts(name, ".init");
}

bool __weak module_exit_section(const char *name)
{
 return strstarts(name, ".exit");
}

static int validate_section_offset(const struct load_info *info, Elf_Shdr *shdr)
{
#if defined(CONFIG_64BIT)
 unsigned long long secend;
#else
 unsigned long secend;
#endif

 /*
 * Check for both overflow and offset/size being
 * too large.
 */

 secend = shdr->sh_offset + shdr->sh_size;
 if (secend < shdr->sh_offset || secend > info->len)
  return -ENOEXEC;

 return 0;
}

/**
 * elf_validity_ehdr() - Checks an ELF header for module validity
 * @info: Load info containing the ELF header to check
 *
 * Checks whether an ELF header could belong to a valid module. Checks:
 *
 * * ELF header is within the data the user provided
 * * ELF magic is present
 * * It is relocatable (not final linked, not core file, etc.)
 * * The header's machine type matches what the architecture expects.
 * * Optional arch-specific hook for other properties
 *   - module_elf_check_arch() is currently only used by PPC to check
 *   ELF ABI version, but may be used by others in the future.
 *
 * Return: %0 if valid, %-ENOEXEC on failure.
 */

static int elf_validity_ehdr(const struct load_info *info)
{
 if (info->len < sizeof(*(info->hdr))) {
  pr_err("Invalid ELF header len %lu\n", info->len);
  return -ENOEXEC;
 }
 if (memcmp(info->hdr->e_ident, ELFMAG, SELFMAG) != 0) {
  pr_err("Invalid ELF header magic: != %s\n", ELFMAG);
  return -ENOEXEC;
 }
 if (info->hdr->e_type != ET_REL) {
  pr_err("Invalid ELF header type: %u != %u\n",
         info->hdr->e_type, ET_REL);
  return -ENOEXEC;
 }
 if (!elf_check_arch(info->hdr)) {
  pr_err("Invalid architecture in ELF header: %u\n",
         info->hdr->e_machine);
  return -ENOEXEC;
 }
 if (!module_elf_check_arch(info->hdr)) {
  pr_err("Invalid module architecture in ELF header: %u\n",
         info->hdr->e_machine);
  return -ENOEXEC;
 }
 return 0;
}

/**
 * elf_validity_cache_sechdrs() - Cache section headers if valid
 * @info: Load info to compute section headers from
 *
 * Checks:
 *
 * * ELF header is valid (see elf_validity_ehdr())
 * * Section headers are the size we expect
 * * Section array fits in the user provided data
 * * Section index 0 is NULL
 * * Section contents are inbounds
 *
 * Then updates @info with a &load_info->sechdrs pointer if valid.
 *
 * Return: %0 if valid, negative error code if validation failed.
 */

static int elf_validity_cache_sechdrs(struct load_info *info)
{
 Elf_Shdr *sechdrs;
 Elf_Shdr *shdr;
 int i;
 int err;

 err = elf_validity_ehdr(info);
 if (err < 0)
  return err;

 if (info->hdr->e_shentsize != sizeof(Elf_Shdr)) {
  pr_err("Invalid ELF section header size\n");
  return -ENOEXEC;
 }

 /*
 * e_shnum is 16 bits, and sizeof(Elf_Shdr) is
 * known and small. So e_shnum * sizeof(Elf_Shdr)
 * will not overflow unsigned long on any platform.
 */

 if (info->hdr->e_shoff >= info->len
     || (info->hdr->e_shnum * sizeof(Elf_Shdr) >
  info->len - info->hdr->e_shoff)) {
  pr_err("Invalid ELF section header overflow\n");
  return -ENOEXEC;
 }

 sechdrs = (void *)info->hdr + info->hdr->e_shoff;

 /*
 * The code assumes that section 0 has a length of zero and
 * an addr of zero, so check for it.
 */

 if (sechdrs[0].sh_type != SHT_NULL
     || sechdrs[0].sh_size != 0
     || sechdrs[0].sh_addr != 0) {
  pr_err("ELF Spec violation: section 0 type(%d)!=SH_NULL or non-zero len or addr\n",
         sechdrs[0].sh_type);
  return -ENOEXEC;
 }

 /* Validate contents are inbounds */
 for (i = 1; i < info->hdr->e_shnum; i++) {
  shdr = &sechdrs[i];
  switch (shdr->sh_type) {
  case SHT_NULL:
  case SHT_NOBITS:
   /* No contents, offset/size don't mean anything */
   continue;
  default:
   err = validate_section_offset(info, shdr);
   if (err < 0) {
    pr_err("Invalid ELF section in module (section %u type %u)\n",
           i, shdr->sh_type);
    return err;
   }
  }
 }

 info->sechdrs = sechdrs;

 return 0;
}

/**
 * elf_validity_cache_secstrings() - Caches section names if valid
 * @info: Load info to cache section names from. Must have valid sechdrs.
 *
 * Specifically checks:
 *
 * * Section name table index is inbounds of section headers
 * * Section name table is not empty
 * * Section name table is NUL terminated
 * * All section name offsets are inbounds of the section
 *
 * Then updates @info with a &load_info->secstrings pointer if valid.
 *
 * Return: %0 if valid, negative error code if validation failed.
 */

static int elf_validity_cache_secstrings(struct load_info *info)
{
 Elf_Shdr *strhdr, *shdr;
 char *secstrings;
 int i;

 /*
 * Verify if the section name table index is valid.
 */

 if (info->hdr->e_shstrndx == SHN_UNDEF
     || info->hdr->e_shstrndx >= info->hdr->e_shnum) {
  pr_err("Invalid ELF section name index: %d || e_shstrndx (%d) >= e_shnum (%d)\n",
         info->hdr->e_shstrndx, info->hdr->e_shstrndx,
         info->hdr->e_shnum);
  return -ENOEXEC;
 }

 strhdr = &info->sechdrs[info->hdr->e_shstrndx];

 /*
 * The section name table must be NUL-terminated, as required
 * by the spec. This makes strcmp and pr_* calls that access
 * strings in the section safe.
 */

 secstrings = (void *)info->hdr + strhdr->sh_offset;
 if (strhdr->sh_size == 0) {
  pr_err("empty section name table\n");
  return -ENOEXEC;
 }
 if (secstrings[strhdr->sh_size - 1] != '\0') {
  pr_err("ELF Spec violation: section name table isn't null terminated\n");
  return -ENOEXEC;
 }

 for (i = 0; i < info->hdr->e_shnum; i++) {
  shdr = &info->sechdrs[i];
  /* SHT_NULL means sh_name has an undefined value */
  if (shdr->sh_type == SHT_NULL)
   continue;
  if (shdr->sh_name >= strhdr->sh_size) {
   pr_err("Invalid ELF section name in module (section %u type %u)\n",
          i, shdr->sh_type);
   return -ENOEXEC;
  }
 }

 info->secstrings = secstrings;
 return 0;
}

/**
 * elf_validity_cache_index_info() - Validate and cache modinfo section
 * @info: Load info to populate the modinfo index on.
 *        Must have &load_info->sechdrs and &load_info->secstrings populated
 *
 * Checks that if there is a .modinfo section, it is unique.
 * Then, it caches its index in &load_info->index.info.
 * Finally, it tries to populate the name to improve error messages.
 *
 * Return: %0 if valid, %-ENOEXEC if multiple modinfo sections were found.
 */

static int elf_validity_cache_index_info(struct load_info *info)
{
 int info_idx;

 info_idx = find_any_unique_sec(info, ".modinfo");

 if (info_idx == 0)
  /* Early return, no .modinfo */
  return 0;

 if (info_idx < 0) {
  pr_err("Only one .modinfo section must exist.\n");
  return -ENOEXEC;
 }

 info->index.info = info_idx;
 /* Try to find a name early so we can log errors with a module name */
 info->name = get_modinfo(info, "name");

 return 0;
}

/**
 * elf_validity_cache_index_mod() - Validates and caches this_module section
 * @info: Load info to cache this_module on.
 *        Must have &load_info->sechdrs and &load_info->secstrings populated
 *
 * The ".gnu.linkonce.this_module" ELF section is special. It is what modpost
 * uses to refer to __this_module and let's use rely on THIS_MODULE to point
 * to &__this_module properly. The kernel's modpost declares it on each
 * modules's *.mod.c file. If the struct module of the kernel changes a full
 * kernel rebuild is required.
 *
 * We have a few expectations for this special section, this function
 * validates all this for us:
 *
 * * The section has contents
 * * The section is unique
 * * We expect the kernel to always have to allocate it: SHF_ALLOC
 * * The section size must match the kernel's run time's struct module
 *   size
 *
 * If all checks pass, the index will be cached in &load_info->index.mod
 *
 * Return: %0 on validation success, %-ENOEXEC on failure
 */

static int elf_validity_cache_index_mod(struct load_info *info)
{
 Elf_Shdr *shdr;
 int mod_idx;

 mod_idx = find_any_unique_sec(info, ".gnu.linkonce.this_module");
 if (mod_idx <= 0) {
  pr_err("module %s: Exactly one .gnu.linkonce.this_module section must exist.\n",
         info->name ?: "(missing .modinfo section or name field)");
  return -ENOEXEC;
 }

 shdr = &info->sechdrs[mod_idx];

 if (shdr->sh_type == SHT_NOBITS) {
  pr_err("module %s: .gnu.linkonce.this_module section must have a size set\n",
         info->name ?: "(missing .modinfo section or name field)");
  return -ENOEXEC;
 }

 if (!(shdr->sh_flags & SHF_ALLOC)) {
  pr_err("module %s: .gnu.linkonce.this_module must occupy memory during process execution\n",
         info->name ?: "(missing .modinfo section or name field)");
  return -ENOEXEC;
 }

 if (shdr->sh_size != sizeof(struct module)) {
  pr_err("module %s: .gnu.linkonce.this_module section size must match the kernel's built struct module size at run time\n",
         info->name ?: "(missing .modinfo section or name field)");
  return -ENOEXEC;
 }

 info->index.mod = mod_idx;

 return 0;
}

/**
 * elf_validity_cache_index_sym() - Validate and cache symtab index
 * @info: Load info to cache symtab index in.
 *        Must have &load_info->sechdrs and &load_info->secstrings populated.
 *
 * Checks that there is exactly one symbol table, then caches its index in
 * &load_info->index.sym.
 *
 * Return: %0 if valid, %-ENOEXEC on failure.
 */

static int elf_validity_cache_index_sym(struct load_info *info)
{
 unsigned int sym_idx;
 unsigned int num_sym_secs = 0;
 int i;

 for (i = 1; i < info->hdr->e_shnum; i++) {
  if (info->sechdrs[i].sh_type == SHT_SYMTAB) {
   num_sym_secs++;
   sym_idx = i;
  }
 }

 if (num_sym_secs != 1) {
  pr_warn("%s: module has no symbols (stripped?)\n",
   info->name ?: "(missing .modinfo section or name field)");
  return -ENOEXEC;
 }

 info->index.sym = sym_idx;

 return 0;
}

/**
 * elf_validity_cache_index_str() - Validate and cache strtab index
 * @info: Load info to cache strtab index in.
 *        Must have &load_info->sechdrs and &load_info->secstrings populated.
 *        Must have &load_info->index.sym populated.
 *
 * Looks at the symbol table's associated string table, makes sure it is
 * in-bounds, and caches it.
 *
 * Return: %0 if valid, %-ENOEXEC on failure.
 */

static int elf_validity_cache_index_str(struct load_info *info)
{
 unsigned int str_idx = info->sechdrs[info->index.sym].sh_link;

 if (str_idx == SHN_UNDEF || str_idx >= info->hdr->e_shnum) {
  pr_err("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n",
         str_idx, str_idx, info->hdr->e_shnum);
  return -ENOEXEC;
 }

 info->index.str = str_idx;
 return 0;
}

/**
 * elf_validity_cache_index_versions() - Validate and cache version indices
 * @info:  Load info to cache version indices in.
 *         Must have &load_info->sechdrs and &load_info->secstrings populated.
 * @flags: Load flags, relevant to suppress version loading, see
 *         uapi/linux/module.h
 *
 * If we're ignoring modversions based on @flags, zero all version indices
 * and return validity. Othewrise check:
 *
 * * If "__version_ext_crcs" is present, "__version_ext_names" is present
 * * There is a name present for every crc
 *
 * Then populate:
 *
 * * &load_info->index.vers
 * * &load_info->index.vers_ext_crc
 * * &load_info->index.vers_ext_names
 *
 * if present.
 *
 * Return: %0 if valid, %-ENOEXEC on failure.
 */

static int elf_validity_cache_index_versions(struct load_info *info, int flags)
{
 unsigned int vers_ext_crc;
 unsigned int vers_ext_name;
 size_t crc_count;
 size_t remaining_len;
 size_t name_size;
 char *name;

 /* If modversions were suppressed, pretend we didn't find any */
 if (flags & MODULE_INIT_IGNORE_MODVERSIONS) {
  info->index.vers = 0;
  info->index.vers_ext_crc = 0;
  info->index.vers_ext_name = 0;
  return 0;
 }

 vers_ext_crc = find_sec(info, "__version_ext_crcs");
 vers_ext_name = find_sec(info, "__version_ext_names");

 /* If we have one field, we must have the other */
 if (!!vers_ext_crc != !!vers_ext_name) {
  pr_err("extended version crc+name presence does not match");
  return -ENOEXEC;
 }

 /*
 * If we have extended version information, we should have the same
 * number of entries in every section.
 */

 if (vers_ext_crc) {
  crc_count = info->sechdrs[vers_ext_crc].sh_size / sizeof(u32);
  name = (void *)info->hdr +
   info->sechdrs[vers_ext_name].sh_offset;
  remaining_len = info->sechdrs[vers_ext_name].sh_size;

  while (crc_count--) {
   name_size = strnlen(name, remaining_len) + 1;
   if (name_size > remaining_len) {
    pr_err("more extended version crcs than names");
    return -ENOEXEC;
   }
   remaining_len -= name_size;
   name += name_size;
  }
 }

 info->index.vers = find_sec(info, "__versions");
 info->index.vers_ext_crc = vers_ext_crc;
 info->index.vers_ext_name = vers_ext_name;
 return 0;
}

/**
 * elf_validity_cache_index() - Resolve, validate, cache section indices
 * @info:  Load info to read from and update.
 *         &load_info->sechdrs and &load_info->secstrings must be populated.
 * @flags: Load flags, relevant to suppress version loading, see
 *         uapi/linux/module.h
 *
 * Populates &load_info->index, validating as it goes.
 * See child functions for per-field validation:
 *
 * * elf_validity_cache_index_info()
 * * elf_validity_cache_index_mod()
 * * elf_validity_cache_index_sym()
 * * elf_validity_cache_index_str()
 * * elf_validity_cache_index_versions()
 *
 * If CONFIG_SMP is enabled, load the percpu section by name with no
 * validation.
 *
 * Return: 0 on success, negative error code if an index failed validation.
 */

static int elf_validity_cache_index(struct load_info *info, int flags)
{
 int err;

 err = elf_validity_cache_index_info(info);
 if (err < 0)
  return err;
 err = elf_validity_cache_index_mod(info);
 if (err < 0)
  return err;
 err = elf_validity_cache_index_sym(info);
 if (err < 0)
  return err;
 err = elf_validity_cache_index_str(info);
 if (err < 0)
  return err;
 err = elf_validity_cache_index_versions(info, flags);
 if (err < 0)
  return err;

 info->index.pcpu = find_pcpusec(info);

 return 0;
}

/**
 * elf_validity_cache_strtab() - Validate and cache symbol string table
 * @info: Load info to read from and update.
 *        Must have &load_info->sechdrs and &load_info->secstrings populated.
 *        Must have &load_info->index populated.
 *
 * Checks:
 *
 * * The string table is not empty.
 * * The string table starts and ends with NUL (required by ELF spec).
 * * Every &Elf_Sym->st_name offset in the symbol table is inbounds of the
 *   string table.
 *
 * And caches the pointer as &load_info->strtab in @info.
 *
 * Return: 0 on success, negative error code if a check failed.
 */

static int elf_validity_cache_strtab(struct load_info *info)
{
 Elf_Shdr *str_shdr = &info->sechdrs[info->index.str];
 Elf_Shdr *sym_shdr = &info->sechdrs[info->index.sym];
 char *strtab = (char *)info->hdr + str_shdr->sh_offset;
 Elf_Sym *syms = (void *)info->hdr + sym_shdr->sh_offset;
 int i;

 if (str_shdr->sh_size == 0) {
  pr_err("empty symbol string table\n");
  return -ENOEXEC;
 }
 if (strtab[0] != '\0') {
  pr_err("symbol string table missing leading NUL\n");
  return -ENOEXEC;
 }
 if (strtab[str_shdr->sh_size - 1] != '\0') {
  pr_err("symbol string table isn't NUL terminated\n");
  return -ENOEXEC;
 }

 /*
 * Now that we know strtab is correctly structured, check symbol
 * starts are inbounds before they're used later.
 */

 for (i = 0; i < sym_shdr->sh_size / sizeof(*syms); i++) {
  if (syms[i].st_name >= str_shdr->sh_size) {
   pr_err("symbol name out of bounds in string table");
   return -ENOEXEC;
  }
 }

 info->strtab = strtab;
 return 0;
}

/*
 * Check userspace passed ELF module against our expectations, and cache
 * useful variables for further processing as we go.
 *
 * This does basic validity checks against section offsets and sizes, the
 * section name string table, and the indices used for it (sh_name).
 *
 * As a last step, since we're already checking the ELF sections we cache
 * useful variables which will be used later for our convenience:
 *
 *  o pointers to section headers
 *  o cache the modinfo symbol section
 *  o cache the string symbol section
 *  o cache the module section
 *
 * As a last step we set info->mod to the temporary copy of the module in
 * info->hdr. The final one will be allocated in move_module(). Any
 * modifications we make to our copy of the module will be carried over
 * to the final minted module.
 */

static int elf_validity_cache_copy(struct load_info *info, int flags)
{
 int err;

 err = elf_validity_cache_sechdrs(info);
 if (err < 0)
  return err;
 err = elf_validity_cache_secstrings(info);
 if (err < 0)
  return err;
 err = elf_validity_cache_index(info, flags);
 if (err < 0)
  return err;
 err = elf_validity_cache_strtab(info);
 if (err < 0)
  return err;

 /* This is temporary: point mod into copy of data. */
 info->mod = (void *)info->hdr + info->sechdrs[info->index.mod].sh_offset;

 /*
 * If we didn't load the .modinfo 'name' field earlier, fall back to
 * on-disk struct mod 'name' field.
 */

 if (!info->name)
  info->name = info->mod->name;

 return 0;
}

#define COPY_CHUNK_SIZE (16*PAGE_SIZE)

static int copy_chunked_from_user(void *dst, const void __user *usrc, unsigned long len)
{
 do {
  unsigned long n = min(len, COPY_CHUNK_SIZE);

  if (copy_from_user(dst, usrc, n) != 0)
   return -EFAULT;
  cond_resched();
  dst += n;
  usrc += n;
  len -= n;
 } while (len);
 return 0;
}

static int check_modinfo_livepatch(struct module *mod, struct load_info *info)
{
 if (!get_modinfo(info, "livepatch"))
  /* Nothing more to do */
  return 0;

 if (set_livepatch_module(mod))
  return 0;

 pr_err("%s: module is marked as livepatch module, but livepatch support is disabled",
        mod->name);
 return -ENOEXEC;
}

static void check_modinfo_retpoline(struct module *mod, struct load_info *info)
{
 if (retpoline_module_ok(get_modinfo(info, "retpoline")))
  return;

 pr_warn("%s: loading module not compiled with retpoline compiler.\n",
  mod->name);
}

/* Sets info->hdr and info->len. */
static int copy_module_from_user(const void __user *umod, unsigned long len,
      struct load_info *info)
{
 int err;

 info->len = len;
 if (info->len < sizeof(*(info->hdr)))
  return -ENOEXEC;

 err = security_kernel_load_data(LOADING_MODULE, true);
 if (err)
  return err;

 /* Suck in entire file: we'll want most of it. */
 info->hdr = __vmalloc(info->len, GFP_KERNEL | __GFP_NOWARN);
 if (!info->hdr)
  return -ENOMEM;

 if (copy_chunked_from_user(info->hdr, umod, info->len) != 0) {
  err = -EFAULT;
  goto out;
 }

 err = security_kernel_post_load_data((char *)info->hdr, info->len,
          LOADING_MODULE, "init_module");
out:
 if (err)
  vfree(info->hdr);

 return err;
}

static void free_copy(struct load_info *info, int flags)
{
 if (flags & MODULE_INIT_COMPRESSED_FILE)
  module_decompress_cleanup(info);
 else
  vfree(info->hdr);
}

static int rewrite_section_headers(struct load_info *info, int flags)
{
 unsigned int i;

 /* This should always be true, but let's be sure. */
 info->sechdrs[0].sh_addr = 0;

 for (i = 1; i < info->hdr->e_shnum; i++) {
  Elf_Shdr *shdr = &info->sechdrs[i];

  /*
 * Mark all sections sh_addr with their address in the
 * temporary image.
 */

  shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset;

 }

 /* Track but don't keep modinfo and version sections. */
 info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC;
 info->sechdrs[info->index.vers_ext_crc].sh_flags &=
  ~(unsigned long)SHF_ALLOC;
 info->sechdrs[info->index.vers_ext_name].sh_flags &=
  ~(unsigned long)SHF_ALLOC;
 info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC;

 return 0;
}

static const char *const module_license_offenders[] = {
 /* driverloader was caught wrongly pretending to be under GPL */
 "driverloader",

 /* lve claims to be GPL but upstream won't provide source */
 "lve",
};

/*
 * These calls taint the kernel depending certain module circumstances */

static void module_augment_kernel_taints(struct module *mod, struct load_info *info)
{
 int prev_taint = test_taint(TAINT_PROPRIETARY_MODULE);
 size_t i;

 if (!get_modinfo(info, "intree")) {
  if (!test_taint(TAINT_OOT_MODULE))
   pr_warn("%s: loading out-of-tree module taints kernel.\n",
    mod->name);
  add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK);
 }

 check_modinfo_retpoline(mod, info);

 if (get_modinfo(info, "staging")) {
--> --------------------

--> maximum size reached

--> --------------------

Messung V0.5
C=95 H=94 G=94

¤ Dauer der Verarbeitung: 0.26 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.