[1/2] common/sfc_efx/base: limit reported MCDI response length

Message ID 20210518151012.14277-1-ivan.malov@oktetlabs.ru (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [1/2] common/sfc_efx/base: limit reported MCDI response length |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ivan Malov May 18, 2021, 3:10 p.m. UTC
  From: Andy Moreton <amoreton@xilinx.com>

MCDI helper routines in libefx include length checks for response
messages, to ensure that short replies and optional fields are
handled correctly.

If the MCDI response message from the firmware is larger than the
caller's buffer then the response length reported to the caller
should be limited to the buffer size. Otherwise length checks in
the caller may allow reading past the end of the buffer.

Fixes: 6f619653b9b1 ("net/sfc/base: import MCDI implementation")
Cc: stable@dpdk.org

Signed-off-by: Andy Moreton <amoreton@xilinx.com>
Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/common/sfc_efx/base/efx_mcdi.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Ferruh Yigit May 18, 2021, 4:41 p.m. UTC | #1
On 5/18/2021 4:10 PM, Ivan Malov wrote:
> From: Andy Moreton <amoreton@xilinx.com>
> 
> MCDI helper routines in libefx include length checks for response
> messages, to ensure that short replies and optional fields are
> handled correctly.
> 
> If the MCDI response message from the firmware is larger than the
> caller's buffer then the response length reported to the caller
> should be limited to the buffer size. Otherwise length checks in
> the caller may allow reading past the end of the buffer.
> 
> Fixes: 6f619653b9b1 ("net/sfc/base: import MCDI implementation")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Andy Moreton <amoreton@xilinx.com>
> Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

Series applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/drivers/common/sfc_efx/base/efx_mcdi.c b/drivers/common/sfc_efx/base/efx_mcdi.c
index ff676f8a0..f4e1384d0 100644
--- a/drivers/common/sfc_efx/base/efx_mcdi.c
+++ b/drivers/common/sfc_efx/base/efx_mcdi.c
@@ -516,6 +516,9 @@  efx_mcdi_finish_response(
 	bytes = MIN(emrp->emr_out_length_used, emrp->emr_out_length);
 	efx_mcdi_read_response(enp, emrp->emr_out_buf, resp_off, bytes);
 
+	/* Report bytes copied to caller (response message may be larger) */
+	emrp->emr_out_length_used = bytes;
+
 #if EFSYS_OPT_MCDI_LOGGING
 	if (emtp->emt_logger != NULL) {
 		emtp->emt_logger(emtp->emt_context,