You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I compiled for target_os="linux" target_cpu="arm". My system has many kernel network interfaces, some of which have MAC addresses longer than 8 bytes. I am on an older commit, 796ba98, however this bug still appears to be present in the code as of 00e3dfb.
Problem
Expected Behaviour
During commissioning the node receives its NOC and then begins its operational advertisement by calling AdvertiseOperational. This function allocates a buffer of kPrimaryMACAddressLength (8) bytes in its stack frame, and then it calls GetPrimaryMACAddress, which calls GetPrimaryWiFiMACAddress. GetPrimaryWiFiMACAddress then populates the 8-byte buffer with the MAC address of a network interface.
Actual Behaviour
When an interface's MAC address length is greater than 8 bytes, and it is chosen in GetPrimaryWiFiMACAddress, then memcpy will write past the end of AdvertiseOperational's stack frame. This can result in a segmentation fault or, when stack protection is enabled, stack smashing:
The problem occurs because mac->sll_halen is not checked before the call to memcpy; the destination is 8 bytes, yet more than 8 bytes will be copied from the source when mac->sll_halen is greater than 8.
Proposed Solution
The ifaddrs returned by getifaddrs are filtered by sa_family to obtain a sockaddr_ll. These sockaddr_lls also need to be filtered such that the resulting sockaddr_lls have a MAC address of length 8 bytes or less. The sockaddr_lls can also be filtered such that the resulting sockaddr_lls are WiFi or Ethernet interfaces. Here is what I added to ConfigurationManagerImpl.cpp to solve this issue:
I am not sure what exactly this MAC address is used for, but based on how the interfaces are currently being filtered, a WiFi or Ethernet interface's MAC address may not be needed. In any case, the call to memcpy should occur only after ensuring that mac->sll_halen <= 8.
The text was updated successfully, but these errors were encountered:
My system has many kernel network interfaces, some of which have MAC addresses longer than 8 bytes.
@mchlswyr I'm a little curious about this part. What does man packet on your system say about the definition of struct sockaddr_ll and its sll_addr field? What I've seen in the past is:
Setup
I compiled for
target_os="linux" target_cpu="arm"
. My system has many kernel network interfaces, some of which have MAC addresses longer than 8 bytes. I am on an older commit, 796ba98, however this bug still appears to be present in the code as of 00e3dfb.Problem
Expected Behaviour
During commissioning the node receives its NOC and then begins its operational advertisement by calling
AdvertiseOperational
. This function allocates a buffer ofkPrimaryMACAddressLength
(8) bytes in its stack frame, and then it callsGetPrimaryMACAddress
, which callsGetPrimaryWiFiMACAddress
.GetPrimaryWiFiMACAddress
then populates the 8-byte buffer with the MAC address of a network interface.Actual Behaviour
When an interface's MAC address length is greater than 8 bytes, and it is chosen in
GetPrimaryWiFiMACAddress
, thenmemcpy
will write past the end ofAdvertiseOperational
's stack frame. This can result in a segmentation fault or, when stack protection is enabled, stack smashing:Reason
The problem occurs because
mac->sll_halen
is not checked before the call tomemcpy
; the destination is 8 bytes, yet more than 8 bytes will be copied from the source whenmac->sll_halen
is greater than 8.Proposed Solution
The
ifaddrs
returned bygetifaddrs
are filtered bysa_family
to obtain asockaddr_ll
. Thesesockaddr_ll
s also need to be filtered such that the resultingsockaddr_ll
s have a MAC address of length 8 bytes or less. Thesockaddr_ll
s can also be filtered such that the resultingsockaddr_ll
s are WiFi or Ethernet interfaces. Here is what I added toConfigurationManagerImpl.cpp
to solve this issue:I am not sure what exactly this MAC address is used for, but based on how the interfaces are currently being filtered, a WiFi or Ethernet interface's MAC address may not be needed. In any case, the call to
memcpy
should occur only after ensuring thatmac->sll_halen <= 8
.The text was updated successfully, but these errors were encountered: