Page MenuHome

Cycles: Fix undefined behavior which can causes crashes with a misaligned address error
ClosedPublic

Authored by Patrick Mours (pmoursnv) on Sep 24 2019, 11:55 AM.

Details

Summary

Cycles casts a pointer from ShaderDataTinyStorage to ShaderData, these structs by default had different alignments however (the former was 1-byte aligned, the latter 16-byte). This caused undefined behavior on at least the CUDA platform. Forcing both structs to use the same alignment fixes this.

CUDA toolkits newer than 10.1 run into this because of a compiler optimization.

See also kernel_path.h:

ShaderDataTinyStorage emission_sd_storage;
ShaderData *emission_sd = AS_SHADER_DATA(&emission_sd_storage);

Diff Detail

Repository
rB Blender

Event Timeline

Patrick Mours (pmoursnv) retitled this revision from Fix undefined behavior which causes Cycles to crash with a misaligned address error with newer CUDA toolkits due to a compiler optimization to Cycles: Fix undefined behavior which can causes crashes with a misaligned address error.Sep 24 2019, 11:57 AM
Patrick Mours (pmoursnv) edited the summary of this revision. (Show Details)

Great find.

intern/cycles/kernel/kernel_types.h
1017–1020

I suggest to add a comment here explaining that it must be aligned the same as ShaderData.

This revision is now accepted and ready to land.Sep 24 2019, 12:26 PM

Added comment explaining the alignment change

Patrick Mours (pmoursnv) marked an inline comment as done.Sep 24 2019, 1:19 PM

Forgot to run kernel_types.h through clang-format again.