OSDN Git Service

modpost: fix potential segmentation fault for addend_i386_rel()
authorMasahiro Yamada <masahiroy@kernel.org>
Mon, 25 May 2020 05:47:04 +0000 (14:47 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Thu, 28 May 2020 18:08:49 +0000 (03:08 +0900)
commitd2e4d05cf1a1f8bfe168ea29b217355be7a4e9ec
tree373da7abf7f2cd1b0f16b19003349f9c430c0461
parente9e81b634303b215e83beced03f04f02f7893442
modpost: fix potential segmentation fault for addend_i386_rel()

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: Masahiro Yamada <masahiroy@kernel.org>
scripts/mod/modpost.c