From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792596013; b=m+D/GTrwEGxBg9zMsHasdxozZzFenmAjvi0FjzqZtldX/Sql3/9PAfim0c8Rz51hbhc4 U5xZXhZsbvQzqP0KgjgS2saQVFl0YI6nSJDU10SzwiIokbeDYP4m4smWALVMV7mCMILpl UXtxe45vUKXFBoCXLUgSAG1SMi9jSAewp+SQxuZ7D/ndYBY4WHNkg0xV8AwLWyUwuj1c4 lz0zaDZD1roltl77+CQGt33IrFIrdd9axFt9tTBDNoY5HvufaF0UZPkqyA4oHiy9FDyvG ztU0wojZs2J+jBGWUTy1j868vRxCrDOGe6y9utVc+QBa4L+zzcE0L3cMHMucPqB1MwQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792596013; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=mbBENTXqepL7LUfgcbRpiPCGqe2Pd2M1BZZD2l4TBaw=; b=QRESreodRrlZr+D+F161oQH3xKjeBQwgtetv9goKBzXmYjcHkGPVZeTY3GR6AjCX1+2i aieC8ijQswQrVHbysjwHEuCcGG8GiQRIQMGbPDsoSGqel+FLE/fX/T2w/lKFOC3eFfPVs +E0LBYeEkMHdGzyK3tkyc2eBzAvIHuL2tbjduqFqUUtsA5aTLFxqDsBqCKTcb2ptN/Ak9 TOhV01/EioGEU+5cSIWDFljI2f4EpCt3d7hYT6LnQBVN+e8Q8RwHT60tSzxEqldq1trbT TQNs7m/puZD4IUS/HQYvAkWFH3BHuFSpsSddOsJHV8zwAYcOhcZRFxovlFDabBgTo+w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PEf3OgdH; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4742606A320 for ; Wed, 21 Oct 2026 15:20:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B4742606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PEf3OgdH DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792596011; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mbBENTXqepL7LUfgcbRpiPCGqe2Pd2M1BZZD2l4TBaw=; b=PEf3OgdHrnEsp3lmrYMOuDYDaC0si2DT3wNzueNsXneaolC3uOi9f64YRgVZWbLBX1PfJ+ GGuMpTWQG9Dqgdn51JOAWBMflEZ7bVu1sgVNaJ1/jI2qb5c4/LKmzdoLa8mbcki3Ad8hnz 5WbzTMuuChjaAP0NoaMb4MKnAArwqts= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-AcjwfS6CNISyl-FSmPhbhw-1; Wed, 21 Oct 2026 15:19:50 +0000 X-MC-Unique: AcjwfS6CNISyl-FSmPhbhw-1 X-Mimecast-MFC-AGG-ID: AcjwfS6CNISyl-FSmPhbhw_1792595990 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CC8EF195604E; Wed, 21 Oct 2026 15:19:49 +0000 (UTC) Received: from loberman-thinkpadp16gen3.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 33AF418004D2; Wed, 21 Oct 2026 15:19:49 +0000 (UTC) From: Laurence Oberman To: stable@vger.kernel.org Cc: Dingisoul , "Martin K. Petersen (Oracle)" Subject: [PATCH 6.18.y] scsi: st: Fix use-after-free race between st_remove() and st_open() Date: Wed, 21 Oct 2026 11:19:45 -0400 Message-ID: <20261021151945.2663045-1-loberman@redhat.com> In-Reply-To: <2026102128-conjoined-uncoiled-3c92@gregkh> References: <2026102128-conjoined-uncoiled-3c92@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 commit 71caf7f84bd62a4bf91cc95abd2de690afb8d15f upstream. st_remove() drops the probe reference on the scsi_tape with kref_put() and only afterwards removes its index from st_index_idr. If that was the last reference, scsi_tape_release() frees the structure while it is still published in the idr. scsi_tape_get(), called from st_open(), looks up the tape in st_index_idr and takes a reference under st_ref_mutex and st_index_lock. remove_cdevs() does not wait for opens that are already past chrdev_open(), so an open that is blocked on st_ref_mutex while st_remove() holds it can take the mutex as soon as st_remove() drops it, find the freed tpnt in the idr and call kref_get() on it: BUG: KASAN: slab-use-after-free in st_open Write of size 4 ... st_open (drivers/scsi/st.c:254 drivers/scsi/st.c:1291) chrdev_open ... Freed by task ...: kfree st_remove (drivers/scsi/st.c:4512) Remove the index from the idr before dropping the reference, all under st_ref_mutex. A concurrent scsi_tape_get() now either runs first and holds a valid reference that keeps the tape alive, or runs afterwards and finds nothing, so st_open() fails with -ENXIO. This restores the ordering st_remove() had before the conversion to st_index_idr, where the tape was unpublished from scsi_tapes[] before the final kref_put(). Fixes: 6c648d95a6af ("[SCSI] st: get rid of scsi_tapes array") Cc: stable@vger.kernel.org Reported-by: Dingisoul Closes: https://lore.kernel.org/linux-scsi/20261007211520.1428497-1-dingiso.kernel@gmail.com/ Tested-by: Dingisoul Signed-off-by: Laurence Oberman Link: https://patch.msgid.link/20261013202548.249628-1-loberman@redhat.com Signed-off-by: Martin K. Petersen (Oracle) [ loberman: st_remove() still returns int in 6.18; context adjusted ] Signed-off-by: Laurence Oberman --- drivers/scsi/st.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index 74a6830b7ed8..0fbc274f8fe8 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -4465,11 +4465,11 @@ static int st_remove(struct device *dev) remove_cdevs(tpnt); mutex_lock(&st_ref_mutex); - kref_put(&tpnt->kref, scsi_tape_release); - mutex_unlock(&st_ref_mutex); spin_lock(&st_index_lock); idr_remove(&st_index_idr, index); spin_unlock(&st_index_lock); + kref_put(&tpnt->kref, scsi_tape_release); + mutex_unlock(&st_ref_mutex); return 0; } -- 2.56.0