1. 03 6月, 2020 1 次提交
  2. 29 5月, 2020 2 次提交
    • M
      modpost: refactor sech_name() · 565587d8
      Masahiro Yamada 提交于
      Use sym_get_data_by_offset() helper to get access to the .shstrtab
      section data. No functional change is intended because
      elf->sechdrs[elf->secindex_strings].sh_addr is 0 for both ET_REL
      and ET_EXEC object types.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      565587d8
    • M
      modpost: fix potential segmentation fault for addend_i386_rel() · d2e4d05c
      Masahiro Yamada 提交于
      This may not be a practical problem, but the second pass of ARCH=i386
      modpost causes segmentation fault if the -s option is not passed.
      
          MODPOST 12 modules
        Segmentation fault (core dumped)
        make[2]: *** [scripts/Makefile.modpost:94: __modpost] Error 139
        make[1]: *** [Makefile:1339: modules] Error 2
        make[1]: *** Waiting for unfinished jobs....
      
      The segmentation fault occurs when section_rel() is called for vmlinux,
      which is untested in regular builds. The cause of the problem is
      reloc_location() returning a wrong pointer for ET_EXEC object type.
      In this case, you need to subtract sechdr->sh_addr, otherwise it would
      get access beyond the mmap'ed memory.
      
      Add sym_get_data_by_offset() helper to avoid code duplication.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      d2e4d05c
  3. 25 5月, 2020 1 次提交
    • G
      modpost,fixdep: Replace zero-length array with flexible-array · 859c8175
      Gustavo A. R. Silva 提交于
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      sizeof(flexible-array-member) triggers a warning because flexible array
      members have incomplete type[1]. There are some instances of code in
      which the sizeof operator is being incorrectly/erroneously applied to
      zero-length arrays and the result is zero. Such instances may be hiding
      some bugs. So, this work (flexible-array member conversions) will also
      help to get completely rid of those sorts of issues.
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: NGustavo A. R. Silva <gustavoars@kernel.org>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      859c8175
  4. 21 3月, 2020 1 次提交
  5. 19 3月, 2020 1 次提交
  6. 17 3月, 2020 1 次提交
    • J
      modpost: move the namespace field in Module.symvers last · 5190044c
      Jessica Yu 提交于
      In order to preserve backwards compatability with kmod tools, we have to
      move the namespace field in Module.symvers last, as the depmod -e -E
      option looks at the first three fields in Module.symvers to check symbol
      versions (and it's expected they stay in the original order of crc,
      symbol, module).
      
      In addition, update an ancient comment above read_dump() in modpost that
      suggested that the export type field in Module.symvers was optional. I
      suspect that there were historical reasons behind that comment that are
      no longer accurate. We have been unconditionally printing the export
      type since 2.6.18 (commit bd5cbced), which is over a decade ago now.
      
      Fix up read_dump() to treat each field as non-optional. I suspect the
      original read_dump() code treated the export field as optional in order
      to support pre <= 2.6.18 Module.symvers (which did not have the export
      type field). Note that although symbol namespaces are optional, the
      field will not be omitted from Module.symvers if a symbol does not have
      a namespace. In this case, the field will simply be empty and the next
      delimiter or end of line will follow.
      
      Cc: stable@vger.kernel.org
      Fixes: cb9b55d2 ("modpost: add support for symbol namespaces")
      Tested-by: NMatthias Maennich <maennich@google.com>
      Reviewed-by: NMatthias Maennich <maennich@google.com>
      Reviewed-by: NLucas De Marchi <lucas.demarchi@intel.com>
      Signed-off-by: NJessica Yu <jeyu@kernel.org>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      5190044c
  7. 13 3月, 2020 2 次提交
  8. 15 1月, 2020 1 次提交
  9. 23 11月, 2019 6 次提交
    • M
      modpost: respect the previous export when 'exported twice' is warned · 7ef9ab3b
      Masahiro Yamada 提交于
      When 'exported twice' is warned, let sym_add_exported() return without
      updating the symbol info. This respects the previous export, which is
      ordered first in modules.order
      
      This simplifies the code too.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      7ef9ab3b
    • M
      modpost: do not set ->preloaded for symbols from Module.symvers · e4b26c9f
      Masahiro Yamada 提交于
      Now that there is no overwrap between symbols from ELF files and
      ones from Module.symvers.
      
      So, the 'exported twice' warning should be reported irrespective
      of where the symbol in question came from.
      
      The exceptional case is external module; in some cases, we build
      an external module to provide a different version/variant of the
      corresponding in-kernel module, overriding the same set of exported
      symbols.
      
      You can see this use-case in upstream; tools/testing/nvdimm/libnvdimm.ko
      replaces drivers/nvdimm/libnvdimm.ko in order to link it against mocked
      version of core kernel symbols.
      
      So, let's relax the 'exported twice' warning when building external
      modules. The multiple export from external modules is warned only
      when the previous one is from vmlinux or itself.
      
      With this refactoring, the ugly preloading goes away.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      e4b26c9f
    • M
      modpost: stop symbol preloading for modversion CRC · 1743694e
      Masahiro Yamada 提交于
      It is complicated to add mocked-up symbols for pre-handling CRC.
      Handle CRC after all the export symbols in the relevant module
      are registered.
      
      Call handle_modversion() after the handle_symbol() iteration.
      
      In some cases, I see atand-alone __crc_* without __ksymtab_*.
      For example, ARCH=arm allyesconfig produces __crc_ccitt_veneer and
      __crc_itu_t_veneer. I guess they come from crc_ccitt, crc_itu_t,
      respectively. Since __*_veneer are auto-generated symbols, just
      ignore them.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      1743694e
    • M
      modpost: rename handle_modversions() to handle_symbol() · 9bd2a099
      Masahiro Yamada 提交于
      This function handles not only modversions, but also unresolved
      symbols, export symbols, etc.
      
      Rename it to a more proper function name.
      
      While I was here, I also added the 'const' qualifier to *sym.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      9bd2a099
    • M
      modpost: refactor namespace_from_kstrtabns() to not hard-code section name · e84f9fbb
      Masahiro Yamada 提交于
      Currently, namespace_from_kstrtabns() relies on the fact that
      namespace strings are recorded in the __ksymtab_strings section.
      Actually, it is coded in include/linux/export.h, but modpost does
      not need to hard-code the section name.
      
      Elf_Sym::st_shndx holds the index of the relevant section. Using it is
      a more portable way to get the namespace string.
      
      Make namespace_from_kstrtabns() simply call sym_get_data(), and delete
      the info->ksymtab_strings .
      
      While I was here, I added more 'const' qualifiers to pointers.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      e84f9fbb
    • M
      modpost: add a helper to get data pointed by a symbol · afa0459d
      Masahiro Yamada 提交于
      When CONFIG_MODULE_REL_CRCS is enabled, the value of __crc_* is not
      an absolute value, but the address to the CRC data embedded in the
      .rodata section.
      
      Getting the data pointed by the symbol value is somewhat complex.
      Split it out into a new helper, sym_get_data().
      
      I will reuse it to refactor namespace_from_kstrtabns() in the next
      commit.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      afa0459d
  10. 11 11月, 2019 5 次提交
  11. 18 10月, 2019 3 次提交
  12. 08 10月, 2019 2 次提交
    • M
      modpost: fix broken sym->namespace for external module builds · 389eb3f5
      Masahiro Yamada 提交于
      Currently, external module builds produce tons of false-positives:
      
        WARNING: module <mod> uses symbol <sym> from namespace <ns>, but does not import it.
      
      Here, the <ns> part shows a random string.
      
      When you build external modules, the symbol info of vmlinux and
      in-kernel modules are read from $(objtree)/Module.symvers, but
      read_dump() is buggy in multiple ways:
      
      [1] When the modpost is run for vmlinux and in-kernel modules,
      sym_extract_namespace() allocates memory for the namespace. On the
      other hand, read_dump() does not, then sym->namespace will point to
      somewhere in the line buffer of get_next_line(). The data in the
      buffer will be replaced soon, and sym->namespace will end up with
      pointing to unrelated data. As a result, check_exports() will show
      random strings in the warning messages.
      
      [2] When there is no namespace, sym_extract_namespace() returns NULL.
      On the other hand, read_dump() sets namespace to an empty string "".
      (but, it will be later replaced with unrelated data due to bug [1].)
      The check_exports() shows a warning unless exp->namespace is NULL,
      so every symbol read from read_dump() emits the warning, which is
      mostly false positive.
      
      To address [1], sym_add_exported() calls strdup() for s->namespace.
      The namespace from sym_extract_namespace() must be freed to avoid
      memory leak.
      
      For [2], I changed the if-conditional in check_exports().
      
      This commit also fixes sym_add_exported() to set s->namespace correctly
      when the symbol is preloaded.
      Reviewed-by: NMatthias Maennich <maennich@google.com>
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: NJessica Yu <jeyu@kernel.org>
      389eb3f5
    • M
      module: swap the order of symbol.namespace · bf70b050
      Masahiro Yamada 提交于
      Currently, EXPORT_SYMBOL_NS(_GPL) constructs the kernel symbol as
      follows:
      
        __ksymtab_SYMBOL.NAMESPACE
      
      The sym_extract_namespace() in modpost allocates memory for the part
      SYMBOL.NAMESPACE when '.' is contained. One problem is that the pointer
      returned by strdup() is lost because the symbol name will be copied to
      malloc'ed memory by alloc_symbol(). No one will keep track of the
      pointer of strdup'ed memory.
      
      sym->namespace still points to the NAMESPACE part. So, you can free it
      with complicated code like this:
      
         free(sym->namespace - strlen(sym->name) - 1);
      
      It complicates memory free.
      
      To fix it elegantly, I swapped the order of the symbol and the
      namespace as follows:
      
        __ksymtab_NAMESPACE.SYMBOL
      
      then, simplified sym_extract_namespace() so that it allocates memory
      only for the NAMESPACE part.
      
      I prefer this order because it is intuitive and also matches to major
      languages. For example, NAMESPACE::NAME in C++, MODULE.NAME in Python.
      Reviewed-by: NMatthias Maennich <maennich@google.com>
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: NJessica Yu <jeyu@kernel.org>
      bf70b050
  13. 01 10月, 2019 1 次提交
    • M
      modpost: fix static EXPORT_SYMBOL warnings for UML build · 47346e96
      Masahiro Yamada 提交于
      Johannes Berg reports lots of modpost warnings on ARCH=um builds:
      
      WARNING: "rename" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "lseek" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "ftruncate64" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "getuid" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "lseek64" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "unlink" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "pwrite64" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "close" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "opendir" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "pread64" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "syscall" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "readdir" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "readdir64" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "futimes" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "__lxstat" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "write" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "closedir" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "__xstat" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "fsync" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "__lxstat64" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "__fxstat64" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "telldir" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "printf" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "readlink" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "__sprintf_chk" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "link" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "rmdir" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "fdatasync" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "truncate" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "statfs" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "__errno_location" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "__xmknod" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "open64" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "truncate64" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "open" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "read" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "chown" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "chmod" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "utime" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "fchmod" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "seekdir" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "ioctl" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "dup2" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "statfs64" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "utimes" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "mkdir" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "fchown" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "__guard" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "symlink" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "access" [vmlinux] is a static EXPORT_SYMBOL
      WARNING: "__stack_smash_handler" [vmlinux] is a static EXPORT_SYMBOL
      
      When you run "make", the modpost is run twice; before linking vmlinux,
      and before building modules. All the warnings above are from the second
      modpost.
      
      The offending symbols are defined not in vmlinux, but in the C library.
      The first modpost is run against the relocatable vmlinux.o, and those
      warnings are nicely suppressed because the SH_UNDEF entries from the
      symbol table clear the ->is_static flag.
      
      The second modpost is run against the executable vmlinux (+ modules),
      where those symbols have been resolved, but the definitions do not
      exist.
      
      This commit fixes it in a straightforward way; suppress the static
      EXPORT_SYMBOL warnings from "vmlinux".
      
      Without this commit, we see valid warnings twice anyway. For example,
      ARCH=arm64 defconfig shows the following warning twice:
      
      WARNING: "HYPERVISOR_platform_op" [vmlinux] is a static EXPORT_SYMBOL_GPL
      
      So, it is reasonable to suppress the second one.
      
      Fixes: 15bfc234 ("modpost: check for static EXPORT_SYMBOL* functions")
      Reported-by: NJohannes Berg <johannes@sipsolutions.net>
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Tested-by: NJohannes Berg <johannes@sipsolutions.net>
      Tested-by: NDenis Efremov <efremov@linux.com>
      47346e96
  14. 14 9月, 2019 2 次提交
  15. 10 9月, 2019 2 次提交
  16. 04 9月, 2019 1 次提交
  17. 14 8月, 2019 1 次提交
    • D
      modpost: check for static EXPORT_SYMBOL* functions · 15bfc234
      Denis Efremov 提交于
      This patch adds a check to warn about static EXPORT_SYMBOL* functions
      during the modpost. In most of the cases, a static symbol marked for
      exporting is an odd combination that should be fixed either by deleting
      the exporting mark or by removing the static attribute and adding the
      appropriate declaration to headers.
      
      This check could help to detect the following problems:
      1. 550113d4 ("i2c: add newly exported functions to the header, too")
      2. 54638c6e ("net: phy: make exported variables non-static")
      3. 98ef2046 ("mm: remove the exporting of totalram_pages")
      4. 73df167c ("s390/zcrypt: remove the exporting of ap_query_configuration")
      5. a57caf8c ("sunrpc/cache: remove the exporting of cache_seq_next")
      6. e4e47306 ("crypto: skcipher - remove the exporting of skcipher_walk_next")
      7. 14b4c48b ("gve: Remove the exporting of gve_probe")
      8. 9b79ee97 ("scsi: libsas: remove the exporting of sas_wait_eh")
      9. ...
      
      The build time impact is very limited and is almost at the unnoticeable
      level (< 1 sec).
      Acked-by: NEmil Velikov <emil.l.velikov@gmail.com>
      Signed-off-by: NDenis Efremov <efremov@linux.com>
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      15bfc234
  18. 28 3月, 2019 1 次提交
    • F
      kbuild: modversions: Fix relative CRC byte order interpretation · 54a7151b
      Fredrik Noring 提交于
      Fix commit 56067812 ("kbuild: modversions: add infrastructure for
      emitting relative CRCs") where CRCs are interpreted in host byte order
      rather than proper kernel byte order. The bug is conditional on
      CONFIG_MODULE_REL_CRCS.
      
      For example, when loading a BE module into a BE kernel compiled with a LE
      system, the error "disagrees about version of symbol module_layout" is
      produced. A message such as "Found checksum D7FA6856 vs module 5668FAD7"
      will be given with debug enabled, which indicates an obvious endian
      problem within __kcrctab within the kernel image.
      
      The general solution is to use the macro TO_NATIVE, as is done in
      similar cases throughout modpost.c. With this correction it has been
      verified that a BE kernel compiled with a LE system accepts BE modules.
      
      This change has also been verified with a LE kernel compiled with a LE
      system, in which case TO_NATIVE returns its value unmodified since the
      byte orders match. This is by far the common case.
      
      Fixes: 56067812 ("kbuild: modversions: add infrastructure for emitting relative CRCs")
      Signed-off-by: NFredrik Noring <noring@nocrew.org>
      Cc: stable@vger.kernel.org
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      54a7151b
  19. 14 3月, 2019 1 次提交
  20. 09 1月, 2019 1 次提交
    • W
      x86, modpost: Replace last remnants of RETPOLINE with CONFIG_RETPOLINE · e4f35891
      WANG Chao 提交于
      Commit
      
        4cd24de3 ("x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support")
      
      replaced the RETPOLINE define with CONFIG_RETPOLINE checks. Remove the
      remaining pieces.
      
       [ bp: Massage commit message. ]
      
      Fixes: 4cd24de3 ("x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support")
      Signed-off-by: NWANG Chao <chao.wang@ucloud.cn>
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Reviewed-by: NZhenzhong Duan <zhenzhong.duan@oracle.com>
      Reviewed-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: David Woodhouse <dwmw@amazon.co.uk>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Jessica Yu <jeyu@kernel.org>
      Cc: Jiri Kosina <jkosina@suse.cz>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
      Cc: Michal Marek <michal.lkml@markovi.net>
      Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Tim Chen <tim.c.chen@linux.intel.com>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: linux-kbuild@vger.kernel.org
      Cc: srinivas.eeda@oracle.com
      Cc: stable <stable@vger.kernel.org>
      Cc: x86-ml <x86@kernel.org>
      Link: https://lkml.kernel.org/r/20181210163725.95977-1-chao.wang@ucloud.cn
      e4f35891
  21. 01 12月, 2018 4 次提交