From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793734370; b=zXg1zyWeymj6HSlcN+7IaYA9We5IU9IKuk6p3CncLf/hkWQLDM2Ov2NzjNof0zrtEAWW da/q7kZE6FEDfSAMCNKDgtSyh+KDOr0gqSbu4OMGbQ8bHmP8Y2L8CHT8uBA2uYttl6vW7 djejZK7v5sVncm2Wi7K/1jetSY10IqCVkw2jbosvMee2E85RI5j6X86PoP77RWAjgvHqT n9yFjJWjgMT1/Pe44bwsvULhtHDkWsiV7gTzhyzm5MjZ74d1zpe6oZZ6GnuknQKQJpfdE r+22yGvXje1yrY0aCUXEtKd0uLR02HZcDVJaFgQcR8y1xz5BjumCm2zYlidWDV9p76g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793734370; 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=TIgU+Ph3TU3fSxrpE5w9RHNSxCs4sGelZ3NDiZdAMQo=; b=ZmRY+/JR7UjY4RQ3oiENrTrVtfykg6Rqi4M5ARu7/XY2JlIsLec2n0ij+qjaPt4hInN9 h5LTjmgEzl+KfG7kP7/Yun3QqP+zkaOQoL4K6gRIv30fMQT6q47fQYc8Izdn4seRe/eBH z3QknYujd+uKaV7WRufHMVdynwmubXjphatdoelTlrn42WX2FoJ7XDf7ASnPiTqgoHsE4 BVaZNurnpLork9YGaiKpG3uaKcHgSoObmGESqkImUbKJrLGzDCnPh+oVNZAyWBfY6ZCIL pUb9zSGMJhnCi/9nV0vY/lFD/scE2YEm6SIl0T+ZLsH9zXgD04vXlPDnZ/oNjKmQWkA== 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=iEjmP4zR; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 2C76C606A326 for ; Tue, 3 Nov 2026 19:32:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2C76C606A326 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=iEjmP4zR DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793734369; 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=TIgU+Ph3TU3fSxrpE5w9RHNSxCs4sGelZ3NDiZdAMQo=; b=iEjmP4zRp9c61IT5EDBLy7p3jkrFhLfmC+bPzxct9roBYjcgMJw5CArMHCEPm6HLNiRJNZ X+/J8rv+m0gBGibYEgfn48biVftLvtnLVUmeLCI3SPDdK8wjtq/yb5rnBIVZ5sge2yDKS3 qRFVShJb2lneiH5yp3ikeCNrAQmPE6g= Received: from mx-prod-mc-01.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-440-Bqcr0AShMuyZGg5nbjr7Eg-1; Tue, 03 Nov 2026 14:32:45 -0500 X-MC-Unique: Bqcr0AShMuyZGg5nbjr7Eg-1 X-Mimecast-MFC-AGG-ID: Bqcr0AShMuyZGg5nbjr7Eg_1793734363 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5FB6D19560AE; Tue, 3 Nov 2026 19:32:42 +0000 (UTC) Received: from loberman-thinkpadp16gen3.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCAE51800586; Tue, 3 Nov 2026 19:32:38 +0000 (UTC) From: Laurence Oberman To: linux-scsi@vger.kernel.org, "Martin K . Petersen" Cc: "James E . J . Bottomley" , Hannes Reinecke , Bart Van Assche , Wenchao Hao , Wenchao Hao , Catalin Marinas , Ming Lei , Will Deacon , cki-project@redhat.com, jmoyer@redhat.com, bgoncalv@redhat.com, mpatalan@redhat.com, ftjahjad@redhat.com, fsuba@redhat.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/2] scsi: fix scsi_debug module-exit panic and pseudo target leak Date: Tue, 3 Nov 2026 14:32:33 -0500 Message-ID: <20261103193235.1564898-1-loberman@redhat.com> In-Reply-To: <8e4ba1820a7c56867bf7fff07bd52ff3f79573a1.camel@redhat.com> References: <8e4ba1820a7c56867bf7fff07bd52ff3f79573a1.camel@redhat.com> X-Mailing-List: linux-kernel@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.93 CKI reported a NULL pointer dereference in debugfs_remove() from sdebug_tartget_cleanup_async() while blktests throtl/001 unloaded scsi_debug on 7.4.0-rc1 (arm64). The bug is not arm64 specific. It reproduces on x86_64 with KASAN as a slab-use-after-free of the per-target debugfs dentry. While fixing it, instrumenting target alloc/destroy in scsi_debug showed a second, independent problem in the SCSI core: the pseudo SCSI device's target is never destroyed, because scsi_get_pseudo_sdev() leaks a reap_ref. With add_host=4 num_tgts=16, ->target_alloc() was called 68 times and ->target_destroy() only 64; the missing four were the pseudo-device targets at id max_id. Any LLD that sets nr_reserved_cmds leaks its pseudo target. Patch 1 fixes the core leak. Patch 2 makes scsi_debug_exit() wait for the deferred per-target debugfs cleanup before removing the debugfs root and unloading. Patch 1 was found while testing patch 2, and patch 2 was tested on top of it. Testing (x86_64 VM, KASAN, 7.4.0-rc1): loop "modprobe scsi_debug add_host=4 num_tgts=16; rmmod scsi_debug", with an msleep(200) temporarily added to sdebug_tartget_cleanup_async() to force the race window. - unpatched: KASAN slab-use-after-free / oops on the first rmmod - patch 1: 68 target_alloc / 68 target_destroy, pseudo targets destroyed during scsi_remove_host() - patches 1+2: 50 iterations clean with the msleep I had assistatnce from LLM for both of these and ran a local sashiko which was clean other than a pre-existing issue Laurence Oberman (2): scsi: core: Fix target reap_ref leak in scsi_get_pseudo_sdev() scsi: scsi_debug: Wait for async target cleanup on module exit drivers/scsi/scsi_debug.c | 2 ++ drivers/scsi/scsi_scan.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) -- 2.43.0