mirror-linux/drivers/target
Guixin Liu b71cb088b2 scsi: target: tcm_loop: Fix NULL ptr dereference
The TCM_LOOP LUN creation process calls device_register() to create the
device, which in turn invokes tcm_loop_driver_probe() registered with
the TCM_LOOP bus to create and register the scsi_host.  However, if the
scsi_host memory allocation fails or scsi_add_host() fails, the
device_register() process still returns success.  Subsequently, when the
user binds the LUN to a specific backend device, it accesses the NULL or
freed scsi_host.

Crash Call Trace:
  RIP: 0010:scsi_is_host_device+0x7/0x20
  scsi_alloc_target+0x32/0x2c0
  __scsi_add_device+0x41/0xf0
  scsi_add_device+0xd/0x30
  tcm_loop_port_link+0x25/0x50 [tcm_loop]
  target_fabric_port_link+0x9c/0xb0 [target_core_mod]
  ...

This issue is fixed by:

 1. Setting the tcm_loop_hba's scsi_host to NULL, if scsi_add_host()
    fails.

 2. Checking the tcm_loop_hba's scsi_host after device_register().

 3. Checking the tcm_loop_hba's scsi_host in tcm_loop_driver_remove().

Fixes: 3703b2c5d0 ("[SCSI] tcm_loop: Add multi-fabric Linux/SCSI LLD fabric module")
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Link: https://patch.msgid.link/20260424013923.25998-1-kanie@linux.alibaba.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2026-05-14 22:21:01 -04:00
..
iscsi scsi: target: iscsi: reject invalid size Extended CDB AHS 2026-04-21 21:08:25 -04:00
loopback scsi: target: tcm_loop: Fix NULL ptr dereference 2026-05-14 22:21:01 -04:00
sbp scsi: target: Use driver completion preference by default 2026-02-28 21:04:02 -05:00
tcm_fc scsi: target: Use driver completion preference by default 2026-02-28 21:04:02 -05:00
tcm_remote Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
Kconfig
Makefile
target_core_alua.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
target_core_alua.h
target_core_configfs.c scsi: target: configfs: Bound snprintf() return in tg_pt_gp_members_show() 2026-04-13 22:43:56 -04:00
target_core_device.c scsi: target: core: Fix complete_type use 2026-03-10 21:32:01 -04:00
target_core_fabric_configfs.c scsi: target: Allow userspace to set the completion type 2026-02-28 21:04:03 -05:00
target_core_fabric_lib.c kernel.h: drop hex.h and update all hex.h users 2026-01-20 19:44:19 -08:00
target_core_file.c for-7.1/block-20260411 2026-04-13 15:51:31 -07:00
target_core_file.h
target_core_hba.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
target_core_iblock.c block: remove bdev_nonrot() 2026-03-09 14:30:00 -06:00
target_core_iblock.h scsi: target: iblock: Allow iblock devices to be shared 2025-07-24 21:39:01 -04:00
target_core_internal.h scsi: target: Move LUN stats to per-CPU 2025-11-02 22:06:12 -05:00
target_core_pr.c scsi: target: Don't validate ignored fields in PROUT PREEMPT 2026-04-08 22:38:18 -04:00
target_core_pr.h
target_core_pscsi.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
target_core_pscsi.h target: port block device access to file 2024-02-25 12:05:25 +01:00
target_core_rd.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
target_core_rd.h
target_core_sbc.c scsi: target: core: Fix integer overflow in UNMAP bounds check 2026-03-10 21:56:39 -04:00
target_core_spc.c SCSI misc on 20260212 2026-02-12 15:43:02 -08:00
target_core_stat.c scsi: target: Move LUN stats to per-CPU 2025-11-02 22:06:12 -05:00
target_core_tmr.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
target_core_tpg.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
target_core_transport.c scsi: target: Replace strncpy() with strscpy() in VPD dump functions 2026-03-27 16:32:44 -04:00
target_core_ua.c
target_core_ua.h
target_core_user.c uio: replace deprecated mmap hook with mmap_prepare in uio_info 2026-04-05 13:53:44 -07:00
target_core_xcopy.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
target_core_xcopy.h