From nobody Tue Jan 30 14:31:32 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 4TPSKJ5swVz58x6G; Tue, 30 Jan 2024 14:31:32 +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 4TPSKJ3Hv8z4mJq; Tue, 30 Jan 2024 14:31:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706625092; 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=xsrsyQORDeVEjXB5hbMAGrTc7c3lUs1PdL2t6CRMsck=; b=MZ8FzoSlpQSz2GolYqybRZiXf5AOvEJY0POSM3+iZrq6S715kUSpOX6ivqaUlxyqnH/Nqh jQ6iUnZTNjKitTkoqz2Z3N0ik7P+FprHhG9wlA0USe9WogHs2Zx4gu8zaKcaX2h4UvdEUV UGaACCZJTSEjf4j9915pfqXzRHeZIMZ35iHdlRPAOntG+qigit9YD7Ua5fp+gi7En+a/Xw 5dT4Ze4bzuEdVMoWCIfAIt1zScS0qSmRzmSLiliMEOJxyK3wUWsoo9rCE2/vKDK51Z2xOM SgwqkLXPKXYPPBe52N0HMWeC0qmaly/QKq7qiowckqWaOnzpIUUC/FOXoNljbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706625092; 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=xsrsyQORDeVEjXB5hbMAGrTc7c3lUs1PdL2t6CRMsck=; b=Z6mmM5Izx8dEFmW+LZbamjaejSNRilIqlse2ymjLA82OyqHugfIItQktJD8F4UwcVzXvp6 xxG1vzobgPv8cisKgmUGmqsugvPp18SfXU08AiBRD+kT/jGCivUUKjv+//EEzpfWiRHflQ zeilUGK80MK7SnvTYzk248Lpn4Jh3c2AOkt9GKj8+z5rO4iwjTodeEhRkLykSfkUftROqF EefzSqVjseb55q3mo5yI0UrY+qcgtKnwZFrNNgFC8LxPA/irQe5vt68XTa1by1bM+apoc3 djcCxvbyOXwudXna1NMx4XOdL8QvNoe+eiz2pOrEWGH9KxMMzg3PbKdzXe1psQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706625092; a=rsa-sha256; cv=none; b=RbJOQWXXqDLqd/YMsUd4YXC+/GtcD+dpbl9Q28NOew99EDNR3V1lyumkwFeObDLAYxpZJT lSJdWcqNHLP0jVBQepE0WeHvZYO9GtNbsgu15/T50YmyuxweZ5+kgx1XJIfWCYA+A0HMi7 8g05yp5ca+5cWqQWvZmn/D6Bju+BOBH9xDTntccNwLbuq0EG9Vort4SXQZDISRvwl9f0+s wGGvShDJMe9MzxbRgrlO587IzWpwj0Drb1kCxchcYWFsFPbYZtGJzWr5n6Gbv3wVEWhLpl XNdvsylNPFXSq2uXZp3rshfiwXaveWlnm53pXWoVHJLnRID+PpxFyH1bLNkjKQ== 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 4TPSKJ2NXlzflg; Tue, 30 Jan 2024 14:31:32 +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 40UEVW5M025472; Tue, 30 Jan 2024 14:31:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40UEVW1s025468; Tue, 30 Jan 2024 14:31:32 GMT (envelope-from git) Date: Tue, 30 Jan 2024 14:31:32 GMT Message-Id: <202401301431.40UEVW1s025468@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: c961afe82596 - main - 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/main X-Git-Reftype: branch X-Git-Commit: c961afe82596bdeb7e6a8626f02ddb181c8a24b6 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c961afe82596bdeb7e6a8626f02ddb181c8a24b6 commit c961afe82596bdeb7e6a8626f02ddb181c8a24b6 Author: Mark Johnston AuthorDate: 2024-01-30 01:01:12 +0000 Commit: Mark Johnston CommitDate: 2024-01-30 14:24:55 +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 --- 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 350b7f053ffd..6254596e75d3 100644 --- a/sys/cam/scsi/scsi_cd.c +++ b/sys/cam/scsi/scsi_cd.c @@ -2674,6 +2674,7 @@ cdmediaprobedone(struct cam_periph *periph) softc->flags &= ~CD_FLAG_MEDIA_WAIT; wakeup(&softc->toc); } + cam_periph_release_locked(periph); } /* @@ -2691,31 +2692,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); }