From nobody Wed Dec 15 11:43:17 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 2084D18F1640; Wed, 15 Dec 2021 11:43:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JDYKK631Bz3FfH; Wed, 15 Dec 2021 11:43:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B0B001B983; Wed, 15 Dec 2021 11:43:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BFBhHES021921; Wed, 15 Dec 2021 11:43:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BFBhHuj021920; Wed, 15 Dec 2021 11:43:17 GMT (envelope-from git) Date: Wed, 15 Dec 2021 11:43:17 GMT Message-Id: <202112151143.1BFBhHuj021920@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andriy Gapon Subject: git: 18679ab1c065 - main - mmc_sim: fix setting of the mutex name List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 18679ab1c06575517df9df2509564dbf038d4720 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639568597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hMwZ8VTu7SjO8429HFuOid7GvAfF4EKjrn1fRxSm8xQ=; b=PAUcgAFTYcec5el1d3a9aUk2Hvpag5khHGgpY7NONXyb1BoeJo8wAlN8HiJNuEeKdSZJ28 Td4YZMIdsuR1feyAxA9wYSjRMjkAuplJHbAKYwDlHD4TSKfYxbkfMZPRJhBLo67ySViHNC VmhQG0SrQkNrf9vogOXZT+os8SgHhrahb7a6/3tekqTlNgaR+x/eUdsa2FPR2XhVtWZTbz kERjkWnUfUZ5774RIRiNmV+9TwWhT2N2zgD+RJRpUYo3NjRLBEXBiFYubp071QmH8Zcr/r Bdz/F+CEmjb+D4XWp2VALMIZ0CfFtJ9NprduPIfWStLz72XWonOiPCBRHRflYg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639568597; a=rsa-sha256; cv=none; b=Jo2RRZ5wA0cXKIbfRTPIrsr2SkikWij2rl3X/D51EiLS5dK1yO/adwFBnka7Ry4++ljdYn 1+pSzY2O8YvqxVI1ESzbz6a69BqtOdmhOEYvC8/7+VkAIpy5T2lZpCkf4rXqJj1Z7GVGG5 ux8YJiXAYqtRjyuYZKM0WTV+pH2+6PZrHw44idOMG3688nzhMuEE1EOG9LGvB5mazY+FWH fVY7dK+E6cmzp3kna2YHeKw3getZZVIXP0bVPBAWZtokP0oqZkxaw/8EFpPjw8/ajONmqJ g4gWR58h+OWuunop7eBcBgBthrUihrGJCo8rCoZhkUy5zihwY/Qe0ZWKUlmnhw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=18679ab1c06575517df9df2509564dbf038d4720 commit 18679ab1c06575517df9df2509564dbf038d4720 Author: Andriy Gapon AuthorDate: 2021-12-15 11:37:59 +0000 Commit: Andriy Gapon CommitDate: 2021-12-15 11:42:02 +0000 mmc_sim: fix setting of the mutex name To quote the manual: The pointer passed in as name and type is saved rather than the data it points to. The data pointed to must remain stable until the mutex is destroyed. It seems that the type is actually copied, but the name is stored as a pointer indeed. mmc_cam_sim_alloc used a name stored on stack. So, a corrupt mutex name would be reported. For example: lock order reversal: (sleepable after non-sleepable) 1st 0xd7285b20 <8A>P@P@^D^A (aw_mmc_sim, sleep mutex) @ sys/cam/cam_xpt.c:2804 This change moves the name to struct mmc_sim. Also, that name is used as the sim name as well. Unused mtx_name variable is removed too. The name buffer is reduced to 16 characters. Reviewed by: manu, bz MFC after: 10 days Differential Revision: https://reviews.freebsd.org/D33412 --- sys/cam/mmc/mmc_sim.c | 9 +++------ sys/cam/mmc/mmc_sim.h | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sys/cam/mmc/mmc_sim.c b/sys/cam/mmc/mmc_sim.c index 45d706f61d0a..792551a93511 100644 --- a/sys/cam/mmc/mmc_sim.c +++ b/sys/cam/mmc/mmc_sim.c @@ -191,7 +191,6 @@ mmc_cam_sim_default_action(struct cam_sim *sim, union ccb *ccb) int mmc_cam_sim_alloc(device_t dev, const char *name, struct mmc_sim *mmc_sim) { - char sim_name[64], mtx_name[64]; mmc_sim->dev = dev; @@ -199,13 +198,11 @@ mmc_cam_sim_alloc(device_t dev, const char *name, struct mmc_sim *mmc_sim) goto fail; } - snprintf(sim_name, sizeof(sim_name), "%s_sim", name); - snprintf(mtx_name, sizeof(mtx_name), "%s_mtx", name); - - mtx_init(&mmc_sim->mtx, sim_name, NULL, MTX_DEF); + snprintf(mmc_sim->name, sizeof(mmc_sim->name), "%s_sim", name); + mtx_init(&mmc_sim->mtx, mmc_sim->name, NULL, MTX_DEF); mmc_sim->sim = cam_sim_alloc(mmc_cam_sim_default_action, mmc_cam_default_poll, - name, mmc_sim, device_get_unit(dev), + mmc_sim->name, mmc_sim, device_get_unit(dev), &mmc_sim->mtx, 1, 1, mmc_sim->devq); if (mmc_sim->sim == NULL) { diff --git a/sys/cam/mmc/mmc_sim.h b/sys/cam/mmc/mmc_sim.h index 2b1159a9758e..10bd183c307d 100644 --- a/sys/cam/mmc/mmc_sim.h +++ b/sys/cam/mmc/mmc_sim.h @@ -33,6 +33,7 @@ struct mmc_sim { struct mmc_cam_sim_softc *sc; struct mtx mtx; + char name[64]; struct cam_devq *devq; struct cam_sim *sim; device_t dev;