Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong struct layout in getInterfaceSpeedGLinkSettings #382

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Flamefire
Copy link

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 #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 #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.

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)

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 facebookincubator#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 facebookincubator#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.
@Flamefire
Copy link
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants