mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	Summary of modules changes for the 5.12 merge window:
 
 - Retire EXPORT_UNUSED_SYMBOL() and EXPORT_SYMBOL_GPL_FUTURE(). These export
   types were introduced between 2006 - 2008. All the of the unused symbols have
   been long removed and gpl future symbols were converted to gpl quite a long
   time ago, and I don't believe these export types have been used ever since.
   So, I think it should be safe to retire those export types now. (Christoph Hellwig)
 
 - Refactor and clean up some aged code cruft in the module loader (Christoph Hellwig)
 
 - Build {,module_}kallsyms_on_each_symbol only when livepatching is enabled, as
   it is the only caller (Christoph Hellwig)
 
 - Unexport find_module() and module_mutex and fix the last module
   callers to not rely on these anymore. Make module_mutex internal to
   the module loader. (Christoph Hellwig)
 
 - Harden ELF checks on module load and validate ELF structures before checking
   the module signature (Frank van der Linden)
 
 - Fix undefined symbol warning for clang (Fangrui Song)
 
 - Fix smatch warning (Dan Carpenter)
 
 Signed-off-by: Jessica Yu <jeyu@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iQJEBAABCAAuFiEEVrp26glSWYuDNrCUwEV+OM47wXIFAmA0/KMQHGpleXVAa2Vy
 bmVsLm9yZwAKCRDARX44zjvBcu0uD/4nmRp18EKAtdUZivsZHat0aEWGlkmrVueY
 5huYw6iwM8b/wIAl3xwLki1Iv0/l0a83WXZhLG4ekl0/Nj8kgllA+jtBrZWpoLMH
 CZusN5dS9YwwyD2vu3ak83ARcehcDEPeA9thvc3uRFGis6Hi4bt1rkzGdrzsgqR4
 tybfN4qaQx4ZAKFxA8bnS58l7QTFwUzTxJfM6WWzl1Q+mLZDr/WP+loJ/f1/oFFg
 ufN31KrqqFpdQY5UKq5P4H8FVq/eXE1Mwl8vo3HsnAj598fznyPUmA3D/j+N4GuR
 sTGBVZ9CSehUj7uZRs+Qgg6Bd+y3o44N29BrdZWA6K3ieTeQQpA+VgPUNrDBjGhP
 J/9Y4ms4PnuNEWWRaa73m9qsVqAsjh9+T2xp9PYn9uWLCM8BvQFtWcY7tw4/nB0/
 INmyiP/tIRpwWkkBl47u1TPR09FzBBGDZjBiSn3lm3VX+zCYtHoma5jWyejG11cf
 ybDrTsci9ANyHNP2zFQsUOQJkph78PIal0i3k4ODqGJvaC0iEIH3Xjv+0dmE14rq
 kGRrG/HN6HhMZPjashudVUktyTZ63+PJpfFlQbcUzdvjQQIkzW0vrCHMWx9vD1xl
 Na7vZLl4Nb03WSJp6saY6j2YSRKL0poGETzGqrsUAHEhpEOPHduaiCVlAr/EmeMk
 p6SrWv8+UQ==
 =T29Q
 -----END PGP SIGNATURE-----
Merge tag 'modules-for-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux
Pull module updates from Jessica Yu:
 - Retire EXPORT_UNUSED_SYMBOL() and EXPORT_SYMBOL_GPL_FUTURE(). These
   export types were introduced between 2006 - 2008. All the of the
   unused symbols have been long removed and gpl future symbols were
   converted to gpl quite a long time ago, and I don't believe these
   export types have been used ever since. So, I think it should be safe
   to retire those export types now (Christoph Hellwig)
 - Refactor and clean up some aged code cruft in the module loader
   (Christoph Hellwig)
 - Build {,module_}kallsyms_on_each_symbol only when livepatching is
   enabled, as it is the only caller (Christoph Hellwig)
 - Unexport find_module() and module_mutex and fix the last module
   callers to not rely on these anymore. Make module_mutex internal to
   the module loader (Christoph Hellwig)
 - Harden ELF checks on module load and validate ELF structures before
   checking the module signature (Frank van der Linden)
 - Fix undefined symbol warning for clang (Fangrui Song)
 - Fix smatch warning (Dan Carpenter)
* tag 'modules-for-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux:
  module: potential uninitialized return in module_kallsyms_on_each_symbol()
  module: remove EXPORT_UNUSED_SYMBOL*
  module: remove EXPORT_SYMBOL_GPL_FUTURE
  module: move struct symsearch to module.c
  module: pass struct find_symbol_args to find_symbol
  module: merge each_symbol_section into find_symbol
  module: remove each_symbol_in_section
  module: mark module_mutex static
  kallsyms: only build {,module_}kallsyms_on_each_symbol when required
  kallsyms: refactor {,module_}kallsyms_on_each_symbol
  module: use RCU to synchronize find_module
  module: unexport find_module and module_mutex
  drm: remove drm_fb_helper_modinit
  powerpc/powernv: remove get_cxl_module
  module: harden ELF info handling
  module: Ignore _GLOBAL_OFFSET_TABLE_ when warning for undefined symbols
		
	
			
		
			
				
	
	
		
			225 lines
		
	
	
	
		
			5.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			225 lines
		
	
	
	
		
			5.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/* SPDX-License-Identifier: GPL-2.0 */
 | 
						|
#include <stdio.h>
 | 
						|
#include <stdlib.h>
 | 
						|
#include <stdarg.h>
 | 
						|
#include <stdbool.h>
 | 
						|
#include <string.h>
 | 
						|
#include <sys/types.h>
 | 
						|
#include <sys/stat.h>
 | 
						|
#include <sys/mman.h>
 | 
						|
#include <fcntl.h>
 | 
						|
#include <unistd.h>
 | 
						|
#include <elf.h>
 | 
						|
 | 
						|
#include "elfconfig.h"
 | 
						|
 | 
						|
/* On BSD-alike OSes elf.h defines these according to host's word size */
 | 
						|
#undef ELF_ST_BIND
 | 
						|
#undef ELF_ST_TYPE
 | 
						|
#undef ELF_R_SYM
 | 
						|
#undef ELF_R_TYPE
 | 
						|
 | 
						|
#if KERNEL_ELFCLASS == ELFCLASS32
 | 
						|
 | 
						|
#define Elf_Ehdr    Elf32_Ehdr
 | 
						|
#define Elf_Shdr    Elf32_Shdr
 | 
						|
#define Elf_Sym     Elf32_Sym
 | 
						|
#define Elf_Addr    Elf32_Addr
 | 
						|
#define Elf_Sword   Elf64_Sword
 | 
						|
#define Elf_Section Elf32_Half
 | 
						|
#define ELF_ST_BIND ELF32_ST_BIND
 | 
						|
#define ELF_ST_TYPE ELF32_ST_TYPE
 | 
						|
 | 
						|
#define Elf_Rel     Elf32_Rel
 | 
						|
#define Elf_Rela    Elf32_Rela
 | 
						|
#define ELF_R_SYM   ELF32_R_SYM
 | 
						|
#define ELF_R_TYPE  ELF32_R_TYPE
 | 
						|
#else
 | 
						|
 | 
						|
#define Elf_Ehdr    Elf64_Ehdr
 | 
						|
#define Elf_Shdr    Elf64_Shdr
 | 
						|
#define Elf_Sym     Elf64_Sym
 | 
						|
#define Elf_Addr    Elf64_Addr
 | 
						|
#define Elf_Sword   Elf64_Sxword
 | 
						|
#define Elf_Section Elf64_Half
 | 
						|
#define ELF_ST_BIND ELF64_ST_BIND
 | 
						|
#define ELF_ST_TYPE ELF64_ST_TYPE
 | 
						|
 | 
						|
#define Elf_Rel     Elf64_Rel
 | 
						|
#define Elf_Rela    Elf64_Rela
 | 
						|
#define ELF_R_SYM   ELF64_R_SYM
 | 
						|
#define ELF_R_TYPE  ELF64_R_TYPE
 | 
						|
#endif
 | 
						|
 | 
						|
/* The 64-bit MIPS ELF ABI uses an unusual reloc format. */
 | 
						|
typedef struct
 | 
						|
{
 | 
						|
	Elf32_Word    r_sym;	/* Symbol index */
 | 
						|
	unsigned char r_ssym;	/* Special symbol for 2nd relocation */
 | 
						|
	unsigned char r_type3;	/* 3rd relocation type */
 | 
						|
	unsigned char r_type2;	/* 2nd relocation type */
 | 
						|
	unsigned char r_type1;	/* 1st relocation type */
 | 
						|
} _Elf64_Mips_R_Info;
 | 
						|
 | 
						|
typedef union
 | 
						|
{
 | 
						|
	Elf64_Xword		r_info_number;
 | 
						|
	_Elf64_Mips_R_Info	r_info_fields;
 | 
						|
} _Elf64_Mips_R_Info_union;
 | 
						|
 | 
						|
#define ELF64_MIPS_R_SYM(i) \
 | 
						|
  ((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_sym)
 | 
						|
 | 
						|
#define ELF64_MIPS_R_TYPE(i) \
 | 
						|
  ((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_type1)
 | 
						|
 | 
						|
#if KERNEL_ELFDATA != HOST_ELFDATA
 | 
						|
 | 
						|
static inline void __endian(const void *src, void *dest, unsigned int size)
 | 
						|
{
 | 
						|
	unsigned int i;
 | 
						|
	for (i = 0; i < size; i++)
 | 
						|
		((unsigned char*)dest)[i] = ((unsigned char*)src)[size - i-1];
 | 
						|
}
 | 
						|
 | 
						|
#define TO_NATIVE(x)						\
 | 
						|
({								\
 | 
						|
	typeof(x) __x;						\
 | 
						|
	__endian(&(x), &(__x), sizeof(__x));			\
 | 
						|
	__x;							\
 | 
						|
})
 | 
						|
 | 
						|
#else /* endianness matches */
 | 
						|
 | 
						|
#define TO_NATIVE(x) (x)
 | 
						|
 | 
						|
#endif
 | 
						|
 | 
						|
#define NOFAIL(ptr)   do_nofail((ptr), #ptr)
 | 
						|
void *do_nofail(void *ptr, const char *expr);
 | 
						|
 | 
						|
struct buffer {
 | 
						|
	char *p;
 | 
						|
	int pos;
 | 
						|
	int size;
 | 
						|
};
 | 
						|
 | 
						|
void __attribute__((format(printf, 2, 3)))
 | 
						|
buf_printf(struct buffer *buf, const char *fmt, ...);
 | 
						|
 | 
						|
void
 | 
						|
buf_write(struct buffer *buf, const char *s, int len);
 | 
						|
 | 
						|
struct namespace_list {
 | 
						|
	struct namespace_list *next;
 | 
						|
	char namespace[];
 | 
						|
};
 | 
						|
 | 
						|
struct module {
 | 
						|
	struct module *next;
 | 
						|
	int gpl_compatible;
 | 
						|
	struct symbol *unres;
 | 
						|
	int from_dump;  /* 1 if module was loaded from *.symvers */
 | 
						|
	int is_vmlinux;
 | 
						|
	int seen;
 | 
						|
	int has_init;
 | 
						|
	int has_cleanup;
 | 
						|
	struct buffer dev_table_buf;
 | 
						|
	char	     srcversion[25];
 | 
						|
	// Missing namespace dependencies
 | 
						|
	struct namespace_list *missing_namespaces;
 | 
						|
	// Actual imported namespaces
 | 
						|
	struct namespace_list *imported_namespaces;
 | 
						|
	char name[];
 | 
						|
};
 | 
						|
 | 
						|
struct elf_info {
 | 
						|
	size_t size;
 | 
						|
	Elf_Ehdr     *hdr;
 | 
						|
	Elf_Shdr     *sechdrs;
 | 
						|
	Elf_Sym      *symtab_start;
 | 
						|
	Elf_Sym      *symtab_stop;
 | 
						|
	Elf_Section  export_sec;
 | 
						|
	Elf_Section  export_gpl_sec;
 | 
						|
	char         *strtab;
 | 
						|
	char	     *modinfo;
 | 
						|
	unsigned int modinfo_len;
 | 
						|
 | 
						|
	/* support for 32bit section numbers */
 | 
						|
 | 
						|
	unsigned int num_sections; /* max_secindex + 1 */
 | 
						|
	unsigned int secindex_strings;
 | 
						|
	/* if Nth symbol table entry has .st_shndx = SHN_XINDEX,
 | 
						|
	 * take shndx from symtab_shndx_start[N] instead */
 | 
						|
	Elf32_Word   *symtab_shndx_start;
 | 
						|
	Elf32_Word   *symtab_shndx_stop;
 | 
						|
};
 | 
						|
 | 
						|
static inline int is_shndx_special(unsigned int i)
 | 
						|
{
 | 
						|
	return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE;
 | 
						|
}
 | 
						|
 | 
						|
/*
 | 
						|
 * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of
 | 
						|
 * the way to -256..-1, to avoid conflicting with real section
 | 
						|
 * indices.
 | 
						|
 */
 | 
						|
#define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1))
 | 
						|
 | 
						|
/* Accessor for sym->st_shndx, hides ugliness of "64k sections" */
 | 
						|
static inline unsigned int get_secindex(const struct elf_info *info,
 | 
						|
					const Elf_Sym *sym)
 | 
						|
{
 | 
						|
	if (is_shndx_special(sym->st_shndx))
 | 
						|
		return SPECIAL(sym->st_shndx);
 | 
						|
	if (sym->st_shndx != SHN_XINDEX)
 | 
						|
		return sym->st_shndx;
 | 
						|
	return info->symtab_shndx_start[sym - info->symtab_start];
 | 
						|
}
 | 
						|
 | 
						|
static inline bool strends(const char *str, const char *postfix)
 | 
						|
{
 | 
						|
	if (strlen(str) < strlen(postfix))
 | 
						|
		return false;
 | 
						|
 | 
						|
	return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
 | 
						|
}
 | 
						|
 | 
						|
/* file2alias.c */
 | 
						|
extern unsigned int cross_build;
 | 
						|
void handle_moddevtable(struct module *mod, struct elf_info *info,
 | 
						|
			Elf_Sym *sym, const char *symname);
 | 
						|
void add_moddevtable(struct buffer *buf, struct module *mod);
 | 
						|
 | 
						|
/* sumversion.c */
 | 
						|
void get_src_version(const char *modname, char sum[], unsigned sumlen);
 | 
						|
 | 
						|
/* from modpost.c */
 | 
						|
char *read_text_file(const char *filename);
 | 
						|
char *get_line(char **stringp);
 | 
						|
 | 
						|
enum loglevel {
 | 
						|
	LOG_WARN,
 | 
						|
	LOG_ERROR,
 | 
						|
	LOG_FATAL
 | 
						|
};
 | 
						|
 | 
						|
void modpost_log(enum loglevel loglevel, const char *fmt, ...);
 | 
						|
 | 
						|
/*
 | 
						|
 * warn - show the given message, then let modpost continue running, still
 | 
						|
 *        allowing modpost to exit successfully. This should be used when
 | 
						|
 *        we still allow to generate vmlinux and modules.
 | 
						|
 *
 | 
						|
 * error - show the given message, then let modpost continue running, but fail
 | 
						|
 *         in the end. This should be used when we should stop building vmlinux
 | 
						|
 *         or modules, but we can continue running modpost to catch as many
 | 
						|
 *         issues as possible.
 | 
						|
 *
 | 
						|
 * fatal - show the given message, and bail out immediately. This should be
 | 
						|
 *         used when there is no point to continue running modpost.
 | 
						|
 */
 | 
						|
#define warn(fmt, args...)	modpost_log(LOG_WARN, fmt, ##args)
 | 
						|
#define error(fmt, args...)	modpost_log(LOG_ERROR, fmt, ##args)
 | 
						|
#define fatal(fmt, args...)	modpost_log(LOG_FATAL, fmt, ##args)
 |