Intel Wired LAN Driver Updates 2021-09-27
Subsystems (3)
Tony Nguyen
maintainerThis series contains updates to e100 driver only.
Jake corrects under allocation of register buffer due to incorrect calculations and fixes buffer overrun of register dump.
The following are changes since commit 3b1b6e82fb5e08e2cb355d7b2ee8644ec289de66:
net: phy: enhance GPY115 loopback disable function
and are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue 1GbE
Jacob Keller (2):
e100: fix length calculation in e100_get_regs_len
e100: fix buffer overrun in e100_get_regs
drivers/net/ethernet/intel/e100.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
Signature · 1 line
2.26.2
Tony Nguyen
maintainerPATCH 1/2 e100: fix length calculation in e100_get_regs_len
From: Jacob Keller <[email protected]>
commit abf9b902059f ("e100: cleanup unneeded math") tried to simplify e100_get_regs_len and remove a double 'divide and then multiply' calculation that the e100_reg_regs_len function did.
This change broke the size calculation entirely as it failed to account for the fact that the numbered registers are actually 4 bytes wide and not 1 byte. This resulted in a significant under allocation of the register buffer used by e100_get_regs.
Fix this by properly multiplying the register count by u32 first before adding the size of the dump buffer.
--- drivers/net/ethernet/intel/e100.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/e100.c +5 -1
@@ -2441,7 +2441,11 @@ static void e100_get_drvinfo(struct net_device *netdev,static int e100_get_regs_len (struct net_device *netdev) {struct nic *nic =netdev_priv (netdev); -return 1 +E100_PHY_REGS +sizeof (nic->mem->dump_buf); + +/* We know the number of registers, and the size of the dump buffer. +* Calculate the total size in bytes. +*/ +return (1 +E100_PHY_REGS ) *sizeof (u32) +sizeof (nic->mem->dump_buf); } static void e100_get_regs(struct net_device *netdev,
Signature · 1 line
2.26.2
Tony Nguyen
maintainerPATCH 2/2 e100: fix buffer overrun in e100_get_regs
In reply to Tony NguyenFrom: Jacob Keller <[email protected]>
The e100_get_regs function is used to implement a simple register dump for the e100 device. The data is broken into a couple of MAC control registers, and then a series of PHY registers, followed by a memory dump buffer.
The total length of the register dump is defined as (1 + E100_PHY_REGS)
* sizeof(u32) + sizeof(nic->mem->dump_buf).
The logic for filling in the PHY registers uses a convoluted inverted count for loop which counts from E100_PHY_REGS (0x1C) down to 0, and assigns the slots 1 + E100_PHY_REGS - i. The first loop iteration will fill in [1] and the final loop iteration will fill in [1 + 0x1C]. This is actually one more than the supposed number of PHY registers.
The memory dump buffer is then filled into the space at
[2 + E100_PHY_REGS] which will cause that memcpy to assign 4 bytes past the total size.
The end result is that we overrun the total buffer size allocated by the kernel, which could lead to a panic or other issues due to memory corruption.
It is difficult to determine the actual total number of registers here. The only 8255x datasheet I could find indicates there are 28 total MDI registers. However, we're reading 29 here, and reading them in reverse!
In addition, the ethtool e100 register dump interface appears to read the first PHY register to determine if the device is in MDI or MDIx mode. This doesn't appear to be documented anywhere within the 8255x datasheet. I can only assume it must be in register 28 (the extra register we're reading here).
Lets not change any of the intended meaning of what we copy here. Just extend the space by 4 bytes to account for the extra register and continue copying the data out in the same order.
Change the E100_PHY_REGS value to be the correct total (29) so that the total register dump size is calculated properly. Fix the offset for where we copy the dump buffer so that it doesn't overrun the total size.
Re-write the for loop to use counting up instead of the convoluted down-counting. Correct the mdio_read offset to use the 0-based register offsets, but maintain the bizarre reverse ordering so that we have the ABI expected by applications like ethtool. This requires and additional subtraction of 1. It seems a bit odd but it makes the flow of assignment into the register buffer easier to follow.
--- drivers/net/ethernet/intel/e100.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/e100.c +10 -6
@@ -2437,7 +2437,7 @@ static void e100_get_drvinfo(struct net_device *netdev, sizeof(info->bus_info)); } -#define E100_PHY_REGS 0x1C +#define E100_PHY_REGS 0x1Dstatic int e100_get_regs_len (struct net_device *netdev) {struct nic *nic =netdev_priv (netdev);
@@ -2459,14 +2459,18 @@ static void e100_get_regs(struct net_device *netdev, buff[0 ] =ioread8 (&nic->csr->scb.cmd_hi) <<24 |ioread8 (&nic->csr->scb.cmd_lo) <<16 |ioread16 (&nic->csr->scb.status); -for (i =E100_PHY_REGS ; i >=0 ; i--) - buff[1 +E100_PHY_REGS - i] = -mdio_read (netdev, nic->mii.phy_id, i); +for (i =0 ; i <E100_PHY_REGS ; i++) +/* Note that we read the registers in reverse order. This +* ordering is the ABI apparently used by ethtool and other +* applications. +*/ + buff[1 + i] =mdio_read (netdev, nic->mii.phy_id, +E100_PHY_REGS -1 - i);memset (nic->mem->dump_buf,0 ,sizeof (nic->mem->dump_buf));e100_exec_cb (nic,NULL , e100_dump);msleep (10 ); -memcpy (&buff[2 +E100_PHY_REGS ], nic->mem->dump_buf, -sizeof (nic->mem->dump_buf)); +memcpy (&buff[1 +E100_PHY_REGS ], nic->mem->dump_buf, +sizeof (nic->mem->dump_buf)); }static void e100_get_wol (struct net_device *netdev,struct ethtool_wolinfo *wol)
Signature · 1 line
2.26.2
This series was applied to netdev/net.git (refs/heads/master):
Hello:
This series was applied to netdev/net.git (refs/heads/master):
Quoted 11 lines · On Mon, 27 Sep 2021 10:16:38 -0700 you wrote:
This series contains updates to e100 driver only.
Jake corrects under allocation of register buffer due to incorrect calculations and fixes buffer overrun of register dump.
The following are changes since commit
3b1b6e82fb5e08e2cb355d7b2ee8644ec289de66:
net: phy: enhance GPY115 loopback disable function
and are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue1GbE[...]
Here is the summary with links:
- [net,1/2] e100: fix length calculation in e100_get_regs_len
https://git.kernel.org/netdev/net/c/4329c8dc110b - [net,2/2] e100: fix buffer overrun in e100_get_regs https://git.kernel.org/netdev/net/c/51032e6f17ce
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html