All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: vishal.l.verma@intel.com
Cc: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev
Subject: [ndctl PATCH 07/10] cxl/memdev: Fix bus_invalidate() crash
Date: Thu, 28 Apr 2022 15:10:37 -0700	[thread overview]
Message-ID: <165118383756.1676208.5717187278816036969.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <165118380037.1676208.7644295506592461996.stgit@dwillia2-desk3.amr.corp.intel.com>

bus_invalidate() attempts to limit the invalidation of memdevs to a single
bus scope. However, the ordering of bus_invalidate() leads to a use after
free. Unconditionally invalidate memdevs (disconnect memdevs from their
endpoints) and resotre on next lookup. Otherwise the following command
results in the following backtrace with cxl_test:

    cxl disable-memdev 5,1 --force

#2  0x00007ffff7fb97d4 in snprintf (__fmt=0x7ffff7fbc3ed "%s/driver", __n=98,
    __s=0x574d545619f7bae2 <error: Cannot access memory at address 0x574d545619f7bae2>)
    at /usr/include/bits/stdio2.h:71
#3  cxl_port_is_enabled (port=port@entry=0x422eb0) at ../cxl/lib/libcxl.c:1379
#4  0x00007ffff7fb99a9 in cxl_port_get_bus (port=0x422eb0) at ../cxl/lib/libcxl.c:1339
#5  0x00007ffff7fba3d0 in bus_invalidate (bus=bus@entry=0x421740) at ../cxl/lib/libcxl.c:549
#6  0x00007ffff7fba4e7 in cxl_memdev_disable_invalidate (memdev=0x416fd0) at ../cxl/lib/libcxl.c:596
#7  0x000000000040624e in memdev_action (argc=<optimized out>, argv=<optimized out>, ctx=0x4152a0,
    action=action@entry=0x406b70 <action_disable>, options=options@entry=0x40fca0 <disable_options>,
    usage=usage@entry=0x40f4b0 "cxl disable-memdev <mem0> [<mem1>..<memN>] [<options>]")
    at ../cxl/memdev.c:506
#8  0x0000000000406d57 in cmd_disable_memdev (argc=<optimized out>, argv=<optimized out>,

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 cxl/lib/libcxl.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index 0e8dd20e3c47..374b0f13905a 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -546,8 +546,7 @@ static void bus_invalidate(struct cxl_bus *bus)
 	 * indeterminate, delete them all and start over.
 	 */
 	cxl_memdev_foreach(ctx, memdev)
-		if (cxl_memdev_get_bus(memdev) == bus)
-			memdev->endpoint = NULL;
+		memdev->endpoint = NULL;
 
 	bus_port = cxl_bus_get_port(bus);
 	list_for_each_safe(&bus_port->child_ports, port, _p, list)


  parent reply	other threads:[~2022-04-28 22:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28 22:10 [ndctl PATCH 00/10] CXL topology unit test Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 01/10] build: Move utility helpers to libutil.a Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 02/10] util: Use SZ_ size macros in display size Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 03/10] util: Pretty print terabytes Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 04/10] cxl/port: Fix disable-port man page Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 05/10] cxl/bus: Add bus disable support Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 06/10] cxl/list: Auto-enable 'single' mode for port listings Dan Williams
2022-04-28 22:10 ` Dan Williams [this message]
2022-04-28 22:10 ` [ndctl PATCH 08/10] cxl/list: Add support for filtering by host identifiers Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 09/10] cxl/port: Relax port identifier validation Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 10/10] cxl/test: Add topology enumeration and hotplug test Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=165118383756.1676208.5717187278816036969.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.