This is an archive of the discontinued LLVM Phabricator instance.

[KernelAddressSanitizer] Ensure global array size remains multiple of type-size
AbandonedPublic

Authored by melver on Jun 7 2020, 10:11 AM.

Details

Summary

The kernel expects certain global arrays' size to remain a multiple of
the array type. In particular, for kernel modules some arrays of structs
shared with userspace are sanity-checked by modpost to have a size that
is a multiple of that type:

https://elixir.bootlin.com/linux/latest/source/scripts/mod/file2alias.c#L132

Since the AddressSanitizer takes a global and replaces it with a new one
that has the redzone appended to it, any information about the global as
well as the section size is increased. Therefore, to ensure we retain
the array-size-property required for globals, calculate the redzone size
to be a multiple of the original global's size.

To improve readability, the existing redzone size calculation is
refactored into its own function; no other functional change intended.

Report: https://github.com/ClangBuiltLinux/linux/issues/1045

Diff Detail

Event Timeline

melver created this revision.Jun 7 2020, 10:11 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
melver updated this revision to Diff 269078.Jun 7 2020, 2:59 PM

Add 0-size array to test to check redzone calculation does not divide by 0.

melver abandoned this revision.Jun 8 2020, 1:37 AM

With an allmodconfig, mostpost still isn't happy because it expects the device_id info to be a certain size. Revert everything while we figure out how to make modpost happy.