From nobody Fri Feb 9 15:41:25 2024 X-Original-To: dev-commits-src-branches@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 4TWdPL2nWLz59tFH; Fri, 9 Feb 2024 15:41:26 +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 4TWdPL0wBwz4KwC; Fri, 9 Feb 2024 15:41:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707493286; 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=9botpiX5XSEvhryup1WJgI2dLaNFxUqPdAE7cwQY7L8=; b=lhhMVUTlq42SpmAOy4URkl4+hoak/SSvj+FszVhNa7Qk4p1EpP1lnXhh4vQK61bv0+kibn E6XY+zZpI2vGt4lsbiTMdk0pYLJGf7qQvRY2XZ90uJmVv/wxP4oGT5FblmEewjbhnozWXZ xKFu5LZNohqM+PH7MPQKGAvC2IbRfpGe6rXKSW2HpbAAhtOCtLVTMJDKakThDw/HjvGhnd Q3pzyXP33WyO07O6Nx5zvL5aKLcYkhafLTptc3WmiebbcX6VATB5bDwZ8GONz0P8N87XlR rl0J7u5BEWKdV7/qxOCveRPYhM69SiZO6LhTuiogR/c7wWFOYjvaIIn7bocmFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707493286; 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=9botpiX5XSEvhryup1WJgI2dLaNFxUqPdAE7cwQY7L8=; b=PUpfyuv/1/AOrvDxJOqbj/g/mTV2eY+p2OYNRuQ9N8l1paiu0SCpQ2hNqRPuB7GTbbA5sv 51po7OBeuiJxvfIeDGE4TdqG+pq7aCxvF0/j5oh15EBkXCOUONbaD123eJ3gfMPEpE4cfU hPlbVDPpynjq3rizVXl0cH/3TkP8aWBHR1nx8sHnQW7PWgm597vpQ3V3XZZkUer+TPY7Dp OFNzCeckomt8TtvXafHxqoZNpgpRrQJ2v2rZW6uElIKeDDQw9eZ+XcHu+seoKE//E+rARh RMsLfLS1YDchyVzGRRQ6fKwIxt3iDxuWWMZmhe3pfh+cdaJ5Ylw0aCh+hAC8dg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707493286; a=rsa-sha256; cv=none; b=NoNbNm6/UZ0jG0cLg4n1VRxuylOiFnK5gzv9zZJKv+szzlVyyl2WmGz14EaqNLXpdLlxCy 0WT+cIGV02VN/VXMAlpguD/8LSJpM8C/EioAhAALSX+XzZpaijNRnepi7jf29FsCmafBWs aBRaixXVIEVVXfIM1dSPH3wrCWzEFM93HFKk2I8aTPJKKCr983jm/8z0NoiuwfF7rNJY8c WQPYOTrdR6UkVIX07REcY7ZFnTdcrsqTtgu5VwvESeAos1crJiAoSZ07YPDu8iqvSvrQTm AcbBR8FZA4usXa18QU/cnzvSK52BYW6FZ4sMdGCDh1g8qjl8aoJftVqgTrrORQ== 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 4TWdPK74kvzfJG; Fri, 9 Feb 2024 15:41:25 +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 419FfPln048891; Fri, 9 Feb 2024 15:41:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 419FfPEp048888; Fri, 9 Feb 2024 15:41:25 GMT (envelope-from git) Date: Fri, 9 Feb 2024 15:41:25 GMT Message-Id: <202402091541.419FfPEp048888@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: 979e15bbf0cb - stable/13 - scsi_cd: Maintain a periph reference during media checks List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/13 X-Git-Reftype: branch X-Git-Commit: 979e15bbf0cb35d6ef0b329507b2ef9507cfc6eb Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=979e15bbf0cb35d6ef0b329507b2ef9507cfc6eb commit 979e15bbf0cb35d6ef0b329507b2ef9507cfc6eb Author: Mark Johnston AuthorDate: 2024-01-30 01:01:12 +0000 Commit: Mark Johnston CommitDate: 2024-02-09 15:38:19 +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 76e413064781..d5406dc76f6f 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); }