From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BA33350A38; Wed, 3 Dec 2025 16:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764780050; cv=none; b=ngTnpbnsT6joVHHi663G5k+SS18o0BpllXVM1Kr1GbZhYJ/qp5Y2qe8yye5wGeufBgrWM2gw8HV58Z5rd0dLHOfRi/sn7OUhqKKHEjESY+1h3usSlZk1F194O3M6m6SKkgG6LaMetwRzbw0Yf3dQ1Ak1sJaLG2mdJHfc8VNGfIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764780050; c=relaxed/simple; bh=TZvCw87iZ03au+RYzatvffGOK7QdEHSAfxtxSqiCIQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s1ES9WfPCTZ7ZKyVhBwP8gNRGon8ZPy2AcXSInpwADifbEjI4rLP9yYgJ2Oz5ZgvAmfoVdRgs7ty9TajJXfvAc+RGaAv9P6rmnAwvHjtJkzXoCyKkZqEpqYzYhs9A//bCYBW4CR/C+13DEL3g9kwhMfYOglZHQXUx2/7lkO+g/I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UZNxCWII; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="UZNxCWII" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96D5EC116C6; Wed, 3 Dec 2025 16:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1764780050; bh=TZvCw87iZ03au+RYzatvffGOK7QdEHSAfxtxSqiCIQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UZNxCWIIMJMo4vFEJyzDXrFK/hNvxm6VgEyP91TGJGsONsHP7yDn+pVexNF6JzNLR MzZ2cfbHFO+i3PTa74rhZDF9ETu3cCBWAQBwkhLicEnBz1/78HXu5pfA83qqQMScSU Pj/xe0FtL3zNn44BY0QJESJwkXrsNn5TyuR5RFGQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hamza Mahfooz , Chaitanya Kulkarni , Allen Pais , "Martin K. Petersen" Subject: [PATCH 6.1 441/568] scsi: target: tcm_loop: Fix segfault in tcm_loop_tpg_address_show() Date: Wed, 3 Dec 2025 16:27:23 +0100 Message-ID: <20251203152456.847759729@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251203152440.645416925@linuxfoundation.org> References: <20251203152440.645416925@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hamza Mahfooz commit e6965188f84a7883e6a0d3448e86b0cf29b24dfc upstream. If the allocation of tl_hba->sh fails in tcm_loop_driver_probe() and we attempt to dereference it in tcm_loop_tpg_address_show() we will get a segfault, see below for an example. So, check tl_hba->sh before dereferencing it. Unable to allocate struct scsi_host BUG: kernel NULL pointer dereference, address: 0000000000000194 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP NOPTI CPU: 1 PID: 8356 Comm: tokio-runtime-w Not tainted 6.6.104.2-4.azl3 #1 Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS Hyper-V UEFI Release v4.1 09/28/2024 RIP: 0010:tcm_loop_tpg_address_show+0x2e/0x50 [tcm_loop] ... Call Trace: configfs_read_iter+0x12d/0x1d0 [configfs] vfs_read+0x1b5/0x300 ksys_read+0x6f/0xf0 ... Cc: stable@vger.kernel.org Fixes: 2628b352c3d4 ("tcm_loop: Show address of tpg in configfs") Signed-off-by: Hamza Mahfooz Reviewed-by: Chaitanya Kulkarni Reviewed-by: Allen Pais Link: https://patch.msgid.link/1762370746-6304-1-git-send-email-hamzamahfooz@linux.microsoft.com Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/target/loopback/tcm_loop.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/target/loopback/tcm_loop.c +++ b/drivers/target/loopback/tcm_loop.c @@ -934,6 +934,9 @@ static ssize_t tcm_loop_tpg_address_show struct tcm_loop_tpg, tl_se_tpg); struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; + if (!tl_hba->sh) + return -ENODEV; + return snprintf(page, PAGE_SIZE, "%d:0:%d\n", tl_hba->sh->host_no, tl_tpg->tl_tpgt); }