aeon_ipc_send_msg() intends to skip reading the IPC reply when the
caller passes no buffer for it, but the check tests the input buffer
(data) rather than the output buffer (ret_data). A caller supplying
a payload but a NULL ret_data would have the reply written through a
NULL pointer.
Check ret_data before copying the reply. While at it, validate the
input buffer at function entry, rejecting a NULL data pointer with a
non-zero data_len.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cris…@collabora.com>
---
drivers/net/phy/as21xxx.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 8d46fdfc279a..592b4b7a7869 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -464,6 +464,9 @@ static int aeon_ipc_send_msg(struct phy_device *phydev,
int ret;
int i;
+ if (data_len && !data)
+ return -EINVAL;
+
/* IPC have a max of 8 register to transfer data,
* make sure we never exceed this.
*/
@@ -486,14 +489,14 @@ static int aeon_ipc_send_msg(struct phy_device *phydev,
goto out;
}
- if (!data)
- goto out;
-
if ((ret_sts & AEON_IPC_STS_STATUS) == AEON_IPC_STS_STATUS_ERROR) {
ret = -EINVAL;
goto out;
}
+ if (!ret_data)
+ goto out;
+
/* Prevent IPC from stack smashing the kernel.
* We can't trust IPC to return a good value and we always
* preallocate space for 16 Bytes.
--
2.56.0