Skip to content

Commit c6908e4

Browse files
committed
Fix wrong struct layout in getInterfaceSpeedGLinkSettings
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.
1 parent 2565674 commit c6908e4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

gloo/common/linux.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,12 @@ const std::string& infinibandToBusID(const std::string& name) {
192192
static int getInterfaceSpeedGLinkSettings(int sock, struct ifreq* ifr) {
193193
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
194194
constexpr auto link_mode_data_nwords = 3 * 127;
195-
struct {
196-
__u32 link_mode_data[link_mode_data_nwords];
195+
union {
197196
struct ethtool_link_settings req;
197+
struct { // Only to provide the memory
198+
__u32 link_mode_data[link_mode_data_nwords];
199+
struct ethtool_link_settings dummy;
200+
};
198201
} ecmd;
199202
int rv;
200203

0 commit comments

Comments
 (0)