mirror-linux/drivers/target
Alexandru Hossu 85db739131 scsi: target: iscsi: Validate CHAP_R length before base64 decode
chap_server_compute_hash() allocates client_digest as
kzalloc(chap->digest_size) and then, for BASE64-encoded responses,
passes chap_r directly to chap_base64_decode() without checking whether
the input length could produce more than digest_size bytes of output.

chap_base64_decode() writes to the destination unconditionally as long
as there is input to consume. With MAX_RESPONSE_LENGTH set to 128 and
the "0b" prefix stripped by extract_param(), up to 127 base64 characters
can reach the decoder. 127 characters decode to 95 bytes. For SHA-256
(digest_size=32) this overflows client_digest by 63 bytes; for MD5
(digest_size=16) the overflow is 79 bytes.

The length check at line 344 fires after the write has already happened.

The HEX branch in the same switch statement already validates the length
up front. Apply the same approach to the BASE64 branch: strip trailing
base64 padding characters, then reject any input whose data length
exceeds DIV_ROUND_UP(digest_size * 4, 3) before calling the decoder.

Stripping trailing '=' before the comparison handles both padded and
unpadded encodings. chap_base64_decode() already returns early on '=',
so the full original string is still passed to the decoder unchanged.

The mutual CHAP path decodes CHAP_C into initiatorchg_binhex, which is
kzalloc(CHAP_CHALLENGE_STR_LEN). extract_param() caps initiatorchg at
CHAP_CHALLENGE_STR_LEN characters, so at most CHAP_CHALLENGE_STR_LEN-1
base64 characters reach the decoder. The maximum decoded size,
DIV_ROUND_UP((CHAP_CHALLENGE_STR_LEN-1) * 3, 4), is less than
CHAP_CHALLENGE_STR_LEN, so no overflow is possible there. A comment is
added at the call site to document this.

Fixes: 1e57338834 ("scsi: target: iscsi: Support base64 in CHAP")
Cc: stable@vger.kernel.org
Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com>
Reviewed-by: David Disseldorp <ddiss@suse.de>
Link: https://patch.msgid.link/20260521151121.808477-1-hossu.alexandru@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2026-05-22 23:06:00 -04:00
..
iscsi scsi: target: iscsi: Validate CHAP_R length before base64 decode 2026-05-22 23:06:00 -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