fsl/fman: Validate cell-index value obtained from Device Tree
Subsystems (3)
PATCH v4 1/1 fsl/fman: Validate cell-index value obtained from Device Tree
Cell-index value is obtained from Device Tree and then used to calculate the index for accessing arrays port_mfl[], mac_mfl[] and intr_mng[]. In case of broken DT due to any error cell-index can contain any value and it is possible to go beyond the array boundaries which can lead at least to memory corruption.
Validate cell-index value obtained from Device Tree.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
---
v4:
- Update patch after refcount leaks fix
(https://lore.kernel.org/all/[email protected]/) as suggested by Jakub (https://lore.kernel.org/all/[email protected]/) v3: https://lore.kernel.org/all/[email protected]/ - Add Reviewed-by: Sean Anderson <[email protected]> (https://lore.kernel.org/all/[email protected]/)
v2: https://lore.kernel.org/all/[email protected]/
- Move check to mac.c to avoid allmodconfig build errors and reference leaks
v1: https://lore.kernel.org/all/[email protected]/
drivers/net/ethernet/freescale/fman/fman.c | 1 - drivers/net/ethernet/freescale/fman/fman.h | 3 +++ drivers/net/ethernet/freescale/fman/mac.c | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/fman/fman.c +0 -1
@@ -24,7 +24,6 @@/* General defines */ #define FMAN_LIODN_TBL 64/* size of LIODN table */ -#define MAX_NUM_OF_MACS 10#define FM_NUM_OF_FMAN_CTRL_EVENT_REGS 4#define BASE_RX_PORTID 0x08#define BASE_TX_PORTID 0x28
drivers/net/ethernet/freescale/fman/fman.h +3 -0
@@ -74,6 +74,9 @@#define BM_MAX_NUM_OF_POOLS 64/* Buffers pools */ #define FMAN_PORT_MAX_EXT_POOLS_NUM 8/* External BM pools per Rx port */ +/* General defines */ +#define MAX_NUM_OF_MACS 10 +struct fman ;/* FMan data */ /* Enum for defining port types */
drivers/net/ethernet/freescale/fman/mac.c +5 -0
@@ -259,6 +259,11 @@ static int mac_probe(struct platform_device *_of_dev) err = -EINVAL ; goto _return_dev_put; } +if (val >=MAX_NUM_OF_MACS ) { +dev_err (dev,"cell-index value is too big for %pOF\n" , mac_node); + err = -EINVAL ; + goto _return_dev_put; + } priv->cell_index = (u8 )val;/* Get the MAC address */
Signature · 1 line
2.30.2
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 28 Oct 2024 09:58:24 +0300 you wrote:
Cell-index value is obtained from Device Tree and then used to calculate the index for accessing arrays port_mfl[], mac_mfl[] and intr_mng[]. In case of broken DT due to any error cell-index can contain any value and it is possible to go beyond the array boundaries which can lead at least to memory corruption.
Validate cell-index value obtained from Device Tree.
[...]
Here is the summary with links:
- [net,v4] fsl/fman: Validate cell-index value obtained from Device Tree
https://git.kernel.org/netdev/net-next/c/bd50c4125c98
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html