]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
scsi: target: iscsi: reject invalid size Extended CDB AHS
authorCarlos Bilbao <carlos.bilbao@kernel.org>
Wed, 15 Apr 2026 04:07:28 +0000 (21:07 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 22 Apr 2026 01:08:25 +0000 (21:08 -0400)
commit2f3835771dff512750205aa5f5f61aec0f2b8cb7
treeb525790dcadedc9edca3c88e0e7a62e314badd90
parentb06cf63d83d3b3744d3aefdd2f3ced25e99d7ec1
scsi: target: iscsi: reject invalid size Extended CDB AHS

If ecdb_ahdr->ahslength is zero, two bugs follow:

  kmalloc(be16_to_cpu(ecdb_ahdr->ahslength) + 15, ...)

allocates 15 bytes, but the immediately following memcpy writes
ISCSI_CDB_SIZE (16) bytes into it, a one-byte heap overflow. Also:

  memcpy(cdb + ISCSI_CDB_SIZE, ecdb_ahdr->ecdb,
           be16_to_cpu(ecdb_ahdr->ahslength) - 1);

(u16)0 - 1 promotes to (int)-1 which converts to SIZE_MAX as size_t,
causing a massive out-of-bounds write.

Reject ahslength == 0 with ISCSI_REASON_PROTOCOL_ERROR before the kmalloc.
Also reject ahslength values that exceed the actual AHS buffer advertised.

Fixes: 8f1f7d297bce ("scsi: target: iscsi: Add support for extended CDB AHS")
Signed-off-by: Carlos Bilbao <carlos.bilbao@kernel.org>
Reviewed-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
Link: https://patch.msgid.link/20260415040728.187680-1-carlos.bilbao@kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/target/iscsi/iscsi_target.c