Reorder structure for compatibility with linux-6.0 - #346
Conversation
|
@fduwjj has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
How can this be correct? the order (req first, the buffer after in the struct) is indeed to make space for a zero-sized array at the end of req. If you put req at the end then there is not enough memory and buffer might overflow? |
fix: PR pytorch#346 is incorrect
This change is indeed wrong. However it doesn't overflow the buffer (the size is still the same & |
The `SIOCETHTOOL` IOCTL expects a pointer to an instance of `ethtool_link_settings`. E.g. it will read the `cmd` member to determine what to do. However pytorch#346 reordered the memory layout of the pointer such that actually and array of `__32` values (zeroed out) is passed. Hence the IOCTL will either fail because an invalid command (`cmd=0`) is passed or the values read later by e.g. `ecmd.req.link_mode_masks_nwords` are something completely different. So `ethtool_link_settings` has to come before the (stack) memory used in the flexible array at the end of this struct. To avoid GCC warnigns/errors (see pytorch#345) an union is used that provides the current struct (i.e. with wrong order) and an access the actually used `struct ethtool_link_settings` at the top.
Fixes: #345
See also: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1022319