Linux CXL
 help / color / mirror / Atom feed
* [PATCH] cxl/region: Keep a decoder staged when its auto attach fails
@ 2026-11-20 18:12 Dave Jiang
  2026-11-20 18:39 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Jiang @ 2026-11-20 18:12 UTC (permalink / raw)
  To: linux-cxl; +Cc: dave, jic23, alison.schofield, vishal.l.verma

An auto region lists each arriving endpoint decoder as a target in the
AUTO_STAGED state. Once all targets are there, cxl_region_attach_position()
attaches each one port by port. Attaching at the endpoint port sets
cxld->region and moves the decoder to AUTO. If a later port fails, the
unwind clears cxld->region again, but the decoder stays in AUTO and stays
listed as a target.

When that endpoint goes away, __cxl_decoder_detach() finds no region and
calls cxl_cancel_auto_attach(), which only removes AUTO_STAGED decoders.
The freed decoder is left in the region's target list, and the next
teardown of the region reads it:

  BUG: KASAN: slab-use-after-free in __cxl_decoder_detach+0xa6/0x3b0 [cxl_core]
   cxl_decoder_detach+0x6c/0xf0 [cxl_core]
   unregister_region+0xcb/0x470 [cxl_core]
   kill_regions+0x9f/0x100 [cxl_core]

Put the decoder back in AUTO_STAGED when the unwind leaves it with no
region.

Fixes: 87805c32e6ad ("cxl/region: Fix use-after-free from auto assembly failure")
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/cxl/core/region.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index a048bd5c06cb..f1083976592f 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -1830,6 +1830,14 @@ static int cxl_region_attach_position(struct cxl_region *cxlr,
 	for (iter = cxled_to_port(cxled); !is_cxl_root(iter);
 	     iter = to_cxl_port(iter->dev.parent))
 		cxl_port_detach_region(iter, cxlr, cxled);
+
+	/*
+	 * Attaching at the endpoint port moved a staged decoder to AUTO, and
+	 * the unwind above cleared its region again. It is still listed as a
+	 * target, so keep it staged for cxl_cancel_auto_attach() to find.
+	 */
+	if (cxled->state == CXL_DECODER_STATE_AUTO && !cxled->cxld.region)
+		cxled->state = CXL_DECODER_STATE_AUTO_STAGED;
 	return rc;
 }
 

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-20 20:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 18:12 [PATCH] cxl/region: Keep a decoder staged when its auto attach fails Dave Jiang
2026-11-20 18:39 ` sashiko-bot
2026-11-20 20:32   ` Alison Schofield

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox