Skip to contentSkip to conversation

common/cnxk: fix mailbox message size underflow

PATCH Applied Harman Kalra 2 participants 2 messages Sep 1 – Sep 15

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/cnxk: fix mailbox message size underflow

When the PF forwards a VF mailbox message to the AF, it computes the message size from an offset supplied by the VF without validating it. A malicious VF can pick a small offset that wraps the size to a huge value used as the copy length, so the copy overruns the mailbox region and crashes the PF. Validate the size before use, as other paths already do.

Bugzilla ID: 2024

Fixes 585bb3e538f9 ("common/cnxk: add VF support to base device class")
---
 drivers/common/cnxk/roc_dev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/common/cnxk/roc_dev.c +11 -0
index 61aa4b3075..433aca1dd3 100644
@@ -286,6 +286,17 @@ vf_pf_process_msgs(struct dev *dev, uint16_t vf)
 		msg = (struct mbox_msghdr *)((uintptr_t)mdev->mbase + offset);
 		size = mbox->rx_start + msg->next_msgoff - offset;
 
+		/*
+		 * next_msgoff is VF-controlled. Reject a message whose size is
+		 * smaller than the header or larger than the maximum request so
+		 * an underflowed size cannot be used as the copy length below.
+		 */
+		if (size < sizeof(struct mbox_msghdr) ||
+		    (size - sizeof(struct mbox_msghdr)) > MBOX_MSG_REQ_SIZE_MAX) {
+			plt_err("VF%d: invalid mbox msg size %zu", vf, size);
+			break;
+		}
+
 		/* RVU_PF_FUNC_S */
 		msg->pcifunc = dev_pf_func(dev->pf, vf);
 
Signature · 1 line
2.43.0
Applied
#1 lore raw
Quoted 7 lines · Harman Kalra

When the PF forwards a VF mailbox message to the AF, it computes the message size from an offset supplied by the VF without validating it. A malicious VF can pick a small offset that wraps the size to a huge value used as the copy length, so the copy overruns the mailbox region and crashes the PF. Validate the size before use, as other paths already do.

Quoted 5 lines

Bugzilla ID: 2024

Fixes 585bb3e538f9 ("common/cnxk: add VF support to base device class")

Applied to dpdk-next-net-mrvl/for-main. Thanks

Quoted 29 lines
---
 drivers/common/cnxk/roc_dev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/common/cnxk/roc_dev.c +11 -1
index 61aa4b3075..433aca1dd3 100644
@@ -286,6 +286,17 @@ vf_pf_process_msgs(struct dev *dev, uint16_t vf)
                msg = (struct mbox_msghdr *)((uintptr_t)mdev->mbase + offset);
                size = mbox->rx_start + msg->next_msgoff - offset;
 
+               /*
+                * next_msgoff is VF-controlled. Reject a message whose size is
+                * smaller than the header or larger than the maximum request so
+                * an underflowed size cannot be used as the copy length below.
+                */
+               if (size < sizeof(struct mbox_msghdr) ||
+                   (size - sizeof(struct mbox_msghdr)) > MBOX_MSG_REQ_SIZE_MAX) {
+                       plt_err("VF%d: invalid mbox msg size %zu", vf, size);
+                       break;
+               }
+
                /* RVU_PF_FUNC_S */
                msg->pcifunc = dev_pf_func(dev->pf, vf);
 
--

2.43.0