mlx4: Fix information leak on failure to read module EEPROM
Subsystems (4)
PATCH 1/1 mlx4: Fix information leak on failure to read module EEPROM
mlx4_en_get_module_eeprom() returns 0 even if it fails. This results in copying an uninitialised (or partly initialised) buffer back to user-space.
Change it so that:
* In the special case that the DOM turns out not to be readable, the remaining part of the buffer is cleared. This should avoid a regression when reading modules with this problem.
* In other error cases, the error code is propagated.
References: https://bugs.debian.org/960702
---
This is compile-tested only. It should go to stable, if it is a correct fix.
Ben.
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +5 -2
@@ -2078,14 +2078,17 @@ static int mlx4_en_get_module_eeprom(struct net_device *dev, ret =mlx4_get_module_info (mdev->dev, priv->port, offset, ee->len - i, data + i); -if (!ret)/* Done reading */ +if (!ret) { +/* DOM was not readable after all */ +memset (data + i,0 , ee->len - i);return 0 ; + }if (ret <0 ) {en_err (priv,"mlx4_get_module_info i(%d) offset(%d) bytes_to_read(%d) - FAILED (0x%x)\n" , i, offset, ee->len - i, ret); -return 0 ; +return ret; } i += ret;
Quoted 32 lines · Ben Hutchings
mlx4_en_get_module_eeprom()returns 0 even if it fails. This results in copying an uninitialised (or partly initialised) buffer back to user-space.Change it so that:
* In the special case that the DOM turns out not to be readable, the remaining part of the buffer is cleared. This should avoid a regression when reading modules with this problem.
* In other error cases, the error code is propagated.
Reported-by Yannis Aribaud <[email protected]>References: https://bugs.debian.org/960702
Fixes 7202da8b7f71 ("ethtool, net/mlx4_en: Cable info,get_module_info/...")
Signed-off-by Ben Hutchings <[email protected]>---
This is compile-tested only. It should go to stable, if it is a correct fix.Ben.
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +0
-0
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c static int mlx4_en_get_module_eeprom(struct · line 2082
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +0
-0@@ -2078,14 +2078,17 @@ static int mlx4_en_get_module_eeprom(structnet_device *dev, ret =mlx4_get_module_info (mdev->dev, priv->port, offset, ee->len - i, data + i);
I am not sure i see the issue in here, and why we need the partial memset ?
first thing in this function we do:memset(data, 0, ee->len);
and then mlx4_get_module_info() will only copy valid data only on success.
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c static int mlx4_en_get_module_eeprom(struct net_device *dev, · line 2082
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +2
-1-if (!ret)/* Done reading */ +if (!ret) { +/* DOM was not readable after all */
actually if mlx4_get_module_info() returns any non-negative value it means how much data was read, so if it returns 0, it means that this was the last iteration and we are done reading the eeprom..
so i would remove the above comment and the memset below is redundant since we already memset the whole buffer before the while loop.
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c static int mlx4_en_get_module_eeprom(struct net_device *dev, · line 2091
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +3
-1+memset (data + i,0 , ee->len - i);return 0 ; + }if (ret <0 ) {en_err (priv, "mlx4_get_module_info i(%d) offset(%d) bytes_to_read(%d) - FAILED (0x%x)\n", i, offset, ee->len - i, ret); -return 0 ; +return ret;
I think returning error in here was the actual solution for your problem. you can verify by looking in the kernel log and verify you see the log message.
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +0
-0} i += ret;
Quoted 4 lines · Saeed Mahameed
Quoted 3 lines · Ben Hutchings
mlx4_en_get_module_eeprom()returns 0 even if it fails. This results in copying an uninitialised (or partly initialised) buffer back to user-space.
[...]
Quoted 7 lines
I am not sure i see the issue in here, and why we need the partial memset ?
first thing in this function we do:memset(data, 0, ee->len);and then
mlx4_get_module_info()will only copy valid data only on success.
Wow, sorry, I don't know how I missed that. So this is not the bug I was looking for.
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c static int mlx4_en_get_module_eeprom(struct net_device *dev, · line 2082
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +2
-1-if (!ret)/* Done reading */ +if (!ret) { +/* DOM was not readable after all */ actually if
mlx4_get_module_info()returns any non-negative value it means how much data was read, so if it returns 0, it means that this was the last iteration and we are done reading the eeprom..so i would remove the above comment and the memset below is redundant since we already memset the whole buffer before the while loop.
Right.
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +2
-0+memset (data + i,0 , ee->len - i);return 0 ; + }
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c static int mlx4_en_get_module_eeprom(struct net_device *dev, · line 2091
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +0
-0if (ret <0 ) { en_err(priv, "mlx4_get_module_info i(%d) offset(%d)
bytes_to_read(%d)- FAILED (0x%x)\n",drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +1
-1i, offset, ee->len - i, ret); -return 0 ; +return ret;I think returning error in here was the actual solution for your problem. you can verify by looking in the kernel log and verify you see the log message.
The original bug report (https://bugs.debian.org/960702) says that ethtool reports different values depending on whether its output is redirected. Although returning all-zeroes for the unreadable part might be wrong, it doesn't explain that behaviour.
Perhaps if the timing of the I²C reads is marginal, varying numbers of bytes of DOM information might be readable? But I don't see how redirection of ethtool's output would affect that. It uses a single ioctl to read everything, and the kernel controls timing within that.
So I am mystified about what is going on here. Maybe there is a bug in ethtool, but I'm not seeing it.
Ben.
Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +0
-0} i += ret;
Signature · 2 lines
Ben Hutchings The two most common things in the universe are hydrogen and stupidity.