Fix wrong struct layout in getInterfaceSpeedGLinkSettings#382
Open
Flamefire wants to merge 3 commits intopytorch:mainfrom
Open
Fix wrong struct layout in getInterfaceSpeedGLinkSettings#382Flamefire wants to merge 3 commits intopytorch:mainfrom
Flamefire wants to merge 3 commits intopytorch:mainfrom
Conversation
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.
Author
|
@kumpera Would you be able to review and merge this? CI seems to be broken/unusable right now. @cdluminate If you want/can take a look if this works for you too? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
SIOCETHTOOLIOCTL expects a pointer to an instance ofethtool_link_settings.E.g. it will read the
cmdmember to determine what to do. However #346 reordered the memory layout of the pointer such that actually and array of__32values (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_nwordsare something completely different.So
ethtool_link_settingshas to come before the (stack) memory used in the flexible array at the end of this struct.To avoid GCC warnigns/errors (see #345) an union is used that provides the current struct (i.e. with wrong order) and an access the actually used
struct ethtool_link_settingsat the top.Alternative approach to #348 likely avoiding any undefined behavior (union based type punning is usually supported by compilers, so this should work to get the required memory)