public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] modpost: work around unaligned data access
@ 2024-12-25 15:33 Masahiro Yamada
  2024-12-25 15:33 ` [PATCH 1/3] modpost: fix the missed iteration for the max bit in do_input() Masahiro Yamada
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Masahiro Yamada @ 2024-12-25 15:33 UTC (permalink / raw)
  To: linux-kbuild
  Cc: linux-arm-kernel, linux-kernel, Masahiro Yamada,
	Greg Kroah-Hartman, Nathan Chancellor, Nicolas Schier,
	Rusty Russell

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(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-12-27 13:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-25 15:33 [PATCH 0/3] modpost: work around unaligned data access Masahiro Yamada
2024-12-25 15:33 ` [PATCH 1/3] modpost: fix the missed iteration for the max bit in do_input() Masahiro Yamada
2024-12-25 15:33 ` [PATCH 2/3] modpost: refactor do_vmbus_entry() Masahiro Yamada
2024-12-25 15:33 ` [PATCH 3/3] modpost: work around unaligned data access error Masahiro Yamada
2024-12-25 16:26 ` [PATCH 0/3] modpost: work around unaligned data access John Paul Adrian Glaubitz
2024-12-26 13:55   ` Masahiro Yamada
2024-12-27 13:31     ` John Paul Adrian Glaubitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox