Skip to contentSkip to conversation

cxl: Fix oversized LSA write payload due to header

PATCH In review Jonathan Cameron 2 participants 7 messages Aug 15, 2022 – Oct 21, 2022 CXL

lore
Share & tools
lore
#0 lore raw

cover cxl: Fix oversized LSA write payload due to header

Fix the bug by claiming the payload is smaller by 8 bytes for both reads and writes. Also add a defensive check to aid catching similar bugs in future.

Note that two issues also found in QEMU code whilst looking at this bug. I'll send out fixes for those shortly.

Note that even with these
ndctl create-namespace fails. More debugging underway.

Jonathan Cameron (2):
cxl/mbox: Add a check on input payload size
cxl/pmem: Fix failure to account for 8 byte header for writes to the
device LSA.

 drivers/cxl/core/mbox.c | 2 +-
 drivers/cxl/pmem.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/2 cxl/mbox: Add a check on input payload size

A bug in the LSA code resulted in transfers slightly larger than the mailbox size. Let us make it easier to catch similar issues in future by adding a low level check.

---
 drivers/cxl/core/mbox.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/mbox.c +1 -1
index 16176b9278b4..0c90f13870a4 100644
@@ -174,7 +174,7 @@ int cxl_mbox_send_cmd(struct cxl_dev_state *cxlds, u16 opcode, void *in,
 	};
 	int rc;
 
-	if (out_size > cxlds->payload_size)
+	if (in_size > cxlds->payload_size || out_size > cxlds->payload_size)
 		return -E2BIG;
 
 	rc = cxlds->mbox_send(cxlds, &mbox_cmd);
Signature · 1 line
2.32.0
#2 lore raw

PATCH 2/2 cxl/pmem: Fix failure to account for 8 byte header for writes to the device LSA.

In reply to Jonathan Cameron

Writes to the device must include an offset and size as defined in CXL 2.0 8.2.9.5.2.4 Set LSA (Opcode 4103h)

Fixes tag is non obvious as this code has been through several reworks and variable names + wasn't in use until the addition of the region code.

Due to a bug in QEMU CXL emulation this overrun resulted in QEMU crashing.

---
 drivers/cxl/pmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/pmem.c +1 -1
index 7dc0a2fa1a6b..115a7b79f343 100644
@@ -107,7 +107,7 @@ static int cxl_pmem_get_config_size(struct cxl_dev_state *cxlds,
 
 	*cmd = (struct nd_cmd_get_config_size) {
 		 .config_size = cxlds->lsa_size,
-		 .max_xfer = cxlds->payload_size,
+		 .max_xfer = cxlds->payload_size - sizeof(struct cxl_mbox_set_lsa),
 	};
 
 	return 0;
Signature · 1 line
2.32.0
#3 lore raw

RE: [PATCH 2/2] cxl/pmem: Fix failure to account for 8 byte header for writes to the device LSA.

[ apologies if this is a duplicate response ]

Quoted 6 lines · Jonathan Cameron

Writes to the device must include an offset and size as defined in CXL 2.0 8.2.9.5.2.4 Set LSA (Opcode 4103h)

Fixes tag is non obvious as this code has been through several reworks and variable names + wasn't in use until the addition of the region code.

Looks like:

Fixes 60b8f17215de ("cxl/pmem: Translate NVDIMM label commands to CXL label commands")

...to me since any transfer that got within 8 bytes of the payload_size would fail.

I notice that cxl_test worked around this bug simply because the mocking does not attempt to emulate the actual mailbox transfer, just the logical data transfer. I apprecitate having QEMU to back up the unit testing.

#4 lore raw

Re: [PATCH 2/2] cxl/pmem: Fix failure to account for 8 byte header for writes to the device LSA.

Quoted 10 lines · On Mon, 15 Aug 2022 14:55:42 -0700 Dan Williams <[email protected]>…

[ apologies if this is a duplicate response ]

Quoted 6 lines · Jonathan Cameron

Writes to the device must include an offset and size as defined in CXL 2.0 8.2.9.5.2.4 Set LSA (Opcode 4103h)

Fixes tag is non obvious as this code has been through several reworks and variable names + wasn't in use until the addition of the region code.

Quoted 6 lines

Looks like:

Fixes 60b8f17215de ("cxl/pmem: Translate NVDIMM label commands to CXL label commands")

...to me since any transfer that got within 8 bytes of the payload_size would fail.

Makes sense - go with that one.

Quoted 6 lines

I notice that cxl_test worked around this bug simply because the mocking does not attempt to emulate the actual mailbox transfer, just the logical data transfer. I apprecitate having QEMU to back up the unit testing.

#5 lore raw

Re: [PATCH 2/2] cxl/pmem: Fix failure to account for 8 byte header for writes to the device LSA.

Quoted 13 lines · On Wed, 17 Aug 2022 12:29:30 +0100 Jonathan Cameron…
Quoted 10 lines · On Mon, 15 Aug 2022 14:55:42 -0700 Dan Williams <[email protected]>…

[ apologies if this is a duplicate response ]

Quoted 6 lines · Jonathan Cameron

Writes to the device must include an offset and size as defined in CXL 2.0 8.2.9.5.2.4 Set LSA (Opcode 4103h)

Fixes tag is non obvious as this code has been through several reworks and variable names + wasn't in use until the addition of the region code.

Quoted 8 lines
Quoted 6 lines

Looks like:

Fixes 60b8f17215de ("cxl/pmem: Translate NVDIMM label commands to CXL label commands")

...to me since any transfer that got within 8 bytes of the payload_size would fail.

Makes sense - go with that one.

Hi Dan,

I was assuming you'd pick this up as b4 will happily pick the fixes tag out of the thread and there weren't any other comments.

Let me know if you want me to resend with the tag in place.

Thanks,

Jonathan

Quoted 8 lines
Quoted 7 lines

I notice that cxl_test worked around this bug simply because the mocking does not attempt to emulate the actual mailbox transfer, just the logical data transfer. I apprecitate having QEMU to back up the unit testing.

#6 lore raw

Re: [PATCH 2/2] cxl/pmem: Fix failure to account for 8 byte header for writes to the device LSA.

Quoted 23 lines · Jonathan Cameron
Quoted 20 lines · On Wed, 17 Aug 2022 12:29:30 +0100 Jonathan Cameron…
Quoted 16 lines · On Mon, 15 Aug 2022 14:55:42 -0700 Dan Williams <[email protected]>…

[ apologies if this is a duplicate response ]

Quoted 6 lines · Jonathan Cameron

Writes to the device must include an offset and size as defined in CXL 2.0 8.2.9.5.2.4 Set LSA (Opcode 4103h)

Fixes tag is non obvious as this code has been through several reworks and variable names + wasn't in use until the addition of the region code.

Looks like:

Fixes 60b8f17215de ("cxl/pmem: Translate NVDIMM label commands to CXL label commands")

...to me since any transfer that got within 8 bytes of the payload_size would fail.

Quoted 8 lines
Quoted 1 line

Makes sense - go with that one.

Hi Dan,

I was assuming you'd pick this up as b4 will happily pick the fixes tag out of the thread and there weren't any other comments.

Let me know if you want me to resend with the tag in place.

I believe you should have gotten a notice from patchwork, but I have this queued up for v6.1-rc fixes.