From nobody Fri Feb 9 15:04:24 2024 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 4TWcZd2wd5z59qkF; Fri, 9 Feb 2024 15:04:25 +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 4TWcZd0KCWz4Fjr; Fri, 9 Feb 2024 15:04:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707491065; 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=SktiGVXUU59CmcQJfVh3K+6yIaVAAle4RclAWLQf4fg=; b=HltDEme7UW48PN2z4X1FiLsnzq5RJSNgTHK7EEmXbgxlBKDs88F5AadHwmEJnGr1f4JWWR X7Kb1zOgL63QLJtBQ+yJtoNCcNj8k4Ttm+QwDf/O2zx0O/7FqkJlEq4Dow61NDN72qdewi IM22jJEpTlCqSzgVeC/wwbkRqierefoL+391aXE0xE8zCx+eofM9fQqiQHAVt5iWIia2wf euK89PB/M5mjXWs5d/I7LoVSd3sfCq7mRABkAr+O9S3VwykW7UugY5JLR0oKweu6VyYFSK uK8OOcnJmWZOgFFAMqx5EhNUdOcgIZKtCuEEhK6MFPWnXydmzOAgiJGDPyM/DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707491065; 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=SktiGVXUU59CmcQJfVh3K+6yIaVAAle4RclAWLQf4fg=; b=Wn0Qpf/tJYnq8J1a8+ix4FvQrDRtOaKITz0rj/gf9WYV86x1tpPqa/IvLI/ULP9QHdct+y 4uZUYNWWq8Ya6/pWDVHcVfxHIWsZx/UtIWLeMB3wL0JB6phptT2CHZw3GDwqHfo5aEwirb bWktz0f1y/0p1ceXBAQeyW1g8N+ysBBpmqi6wragQyw6zGKjyzZTQfBCiQOfp025CHzxV7 qfhqSbcamrijpnsgpXR3gXzcQ+876/7DQeZPtlcPu+kfo2pvYJSczAmh6HFodp7B03914+ aUYmooenXn5iAZL3pIDpvavsuOIhtuLzzkB2fgtXfNDr7AopU5XJCaTyfGikKQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707491065; a=rsa-sha256; cv=none; b=sXrUTaz4zK75QqhK3Kcm5J3hJY7IJxept8v4KoSAqsCplViYkW/T+VUlQ8bzKqq03PffKw 0S7lOZPcgcFTvGIwxTnp8a1IXpsNsmt6HTwD3CCPY4hwrEIXSCYqebfRKYk3rM2R7fIr3H POUit+/kcICaSRbTXXVuv73+DOc+93/VtOTU/h+EB1TLtrWXgEcp1GAV+rhkLUQ1ZLuUkG zdoNVnbnN1Qc+kowO4VuktaXCqZ+qbJLiWH6bcvZFUZKgplzD7bbRhmXkzGoIuwjoM+YUZ Tr4xkgzPCMsBmyJppZkzQj0o/4r2mI6kg0AQyewmq27wT+SevNHwg+fyAuRNmg== 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 4TWcZc6XX9zdGX; Fri, 9 Feb 2024 15:04:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 419F4ObR085463; Fri, 9 Feb 2024 15:04:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 419F4OwA085461; Fri, 9 Feb 2024 15:04:24 GMT (envelope-from git) Date: Fri, 9 Feb 2024 15:04:24 GMT Message-Id: <202402091504.419F4OwA085461@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 212af7b6133a - stable/14 - scsi_cd: Maintain a periph reference during media checks 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 212af7b6133a60382e62237bb3e99cf63342d157 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=212af7b6133a60382e62237bb3e99cf63342d157 commit 212af7b6133a60382e62237bb3e99cf63342d157 Author: Mark Johnston AuthorDate: 2024-01-30 01:01:12 +0000 Commit: Mark Johnston CommitDate: 2024-02-09 14:55:45 +0000 scsi_cd: Maintain a periph reference during media checks Otherwise nothing prevents the asynchronous media check state machine from running after the periph has been destroyed, which can result in a double free. Acquire the reference even when performing a synchronous check, since that doesn't hurt and keeps things simpler. PR: 276251 Reviewed by: imp Fixes: dd78f43259ef ("scsi_cd: make the media check asynchronous") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D43525 (cherry picked from commit c961afe82596bdeb7e6a8626f02ddb181c8a24b6) --- sys/cam/scsi/scsi_cd.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/sys/cam/scsi/scsi_cd.c b/sys/cam/scsi/scsi_cd.c index d3299486ac2d..bfc91fad6390 100644 --- a/sys/cam/scsi/scsi_cd.c +++ b/sys/cam/scsi/scsi_cd.c @@ -2675,6 +2675,7 @@ cdmediaprobedone(struct cam_periph *periph) softc->flags &= ~CD_FLAG_MEDIA_WAIT; wakeup(&softc->toc); } + cam_periph_release_locked(periph); } /* @@ -2692,31 +2693,29 @@ cdcheckmedia(struct cam_periph *periph, bool do_wait) softc = (struct cd_softc *)periph->softc; error = 0; - if ((do_wait != 0) - && ((softc->flags & CD_FLAG_MEDIA_WAIT) == 0)) { + /* Released by cdmediaprobedone(). */ + error = cam_periph_acquire(periph); + if (error != 0) + return (error); + + if (do_wait) softc->flags |= CD_FLAG_MEDIA_WAIT; - } if ((softc->flags & CD_FLAG_MEDIA_SCAN_ACT) == 0) { softc->state = CD_STATE_MEDIA_PREVENT; softc->flags |= CD_FLAG_MEDIA_SCAN_ACT; xpt_schedule(periph, CAM_PRIORITY_NORMAL); } - - if (do_wait == 0) - goto bailout; + if (!do_wait) + return (0); error = msleep(&softc->toc, cam_periph_mtx(periph), PRIBIO,"cdmedia",0); - if (error != 0) - goto bailout; - /* * Check to see whether we have a valid size from the media. We * may or may not have a valid TOC. */ - if ((softc->flags & CD_FLAG_VALID_MEDIA) == 0) + if (error == 0 && (softc->flags & CD_FLAG_VALID_MEDIA) == 0) error = EINVAL; -bailout: return (error); }