Re: [PATCH v2] ubsan: don't handle misaligned address when support unaligned access
From: Andrey Ryabinin
Date: Fri Dec 08 2017 - 06:41:58 EST
On 12/08/2017 02:14 PM, David Laight wrote:
> From: Andrey Ryabinin
>> Sent: 08 December 2017 10:49
> ...
>> CONFIG_UBSAN_ALIGNMENT is already disabled by default for HAVE_EFFICIENT_UNALIGNED_ACCESS=y because it's noisy,
>> but we still allow users to enable it if they want to.
>>
>> I don't think we should completely forbid enabling it for HAVE_EFFICIENT_UNALIGNED_ACCESS=y.
>> Unaligned access is still a bug in non-arch code and outside of sections like #ifdef HAVE_EFFICIENT_UNALIGNED_ACCESS .. #endif .
>
> Don't think so.
> Code that knows that unaligned accesses don't fault can set up pointers
> that non-arch code dereferences.
> Happens all the time in the networking stack.
>
Ok, *could* be a bug.
> ...
>> And one day, GCC might start doing optimizations based on this, e.g.:
>>
>> u64 *ptr;
>> ...
>> x = *ptr;
>> ...
>> if (ptr & 7) // Compiler can assume that this statement is always false, because 'ptr' was deferenced, so it must be aligned
>> do_something();
>
> Ugg - shoot the gcc developers :-)
The gcc developers must have good self-preservation instinct, that's why they usually provide switch off for optimizations like this.