Skip to content

modpost: work around unaligned data access

Masahiro Yamada linux-arm-kernel linux-kbuild lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3modpost: fix the missed iteration for the max bit in do_input()scripts/mod/file2alias.c+1 -10 replies
2/3modpost: refactor do_vmbus_entry()scripts/mod/file2alias.c+3 -50 replies
3/3modpost: work around unaligned data access errorscripts/mod/file2alias.c scripts/mod/modpost.c scripts/mod/modpost.h+39 -250 replies

Reviews trailers per patch

None of the 3 patches has a Reviewed-by or Acked-by.

PatchJohn Paul Adrian Glaubitz
SeriesT-b T-b
1/3
2/3
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/3] modpost: work around unaligned data access

The latest binutils stopped aligning section data in relocatable ELF. It saves small number of bytes that were previously inserted between sections. However, modpost crashes due to unaligned access:
https://sourceware.org/bugzilla/show_bug.cgi?id=32435
https://sourceware.org/bugzilla/show_bug.cgi?id=32493

Similar to kernel space, unaligned data access in userspace can be problematic on some architectures.

Simple example on ARM:

 $ CC=arm-linux-gnueabihf-gcc
 $ echo 'int foo(int *p) { return *p + *(p + 1); }' | ${CC} -O2 -x c - -c -o foo.o
 $ echo 'int foo(int *p); int main(void) { char str[16] = "helloworld"; return foo((int *)(str + 1)); }' | ${CC} -x c - -c -o main.o
 $ ${CC} -static -o unalign-test main.o foo.o
 $ qemu-armhf unalign-test
 qemu: uncaught target signal 7 (Bus error) - core dumped
 Bus error (core dumped)

In this case, the 'ldrd' instruction causes a bus error due to an unaligned access. If the -O2 flag is omitted, this issue does not occur.

To avoid potential unaligned access, use the get_unaligned() approach as seen in the kernel space.

Masahiro Yamada (3):
modpost: fix the missed iteration for the max bit in do_input()
modpost: refactor do_vmbus_entry()
modpost: work around unaligned data access error

 scripts/mod/file2alias.c | 36 +++++++++++++++++-------------------
 scripts/mod/modpost.c    | 24 ++++++++++++------------
 scripts/mod/modpost.h    | 14 ++++++++++++++
 3 files changed, 43 insertions(+), 31 deletions(-)
Signature · 1 line
2.43.0