From b00154f43c01657e4299c486f451ad50891d80f1 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Fri, 29 Jun 2018 06:11:52 +0200 Subject: [PATCH 178/268] iscsi: Don't blindly use designator length in response for memcpy RH-Author: Fam Zheng Message-id: <20180629061153.12687-13-famz@redhat.com> Patchwork-id: 81162 O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH v2 12/13] iscsi: Don't blindly use designator length in response for memcpy Bugzilla: 1482537 RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Max Reitz RH-Acked-by: Kevin Wolf Per SCSI definition the designator_length we receive from INQUIRY is 8, 12 or at most 16, but we should be careful because the remote iscsi target may misbehave, otherwise we could have a buffer overflow. Reported-by: Max Reitz Signed-off-by: Fam Zheng Signed-off-by: Miroslav Rezanina --- block/iscsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/iscsi.c b/block/iscsi.c index fbcd5bb..751884d 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2226,7 +2226,7 @@ static void iscsi_populate_target_desc(unsigned char *desc, IscsiLun *lun) desc[5] = (dd->designator_type & 0xF) | ((dd->association & 3) << 4); desc[7] = dd->designator_length; - memcpy(desc + 8, dd->designator, dd->designator_length); + memcpy(desc + 8, dd->designator, MIN(dd->designator_length, 20)); desc[28] = 0; desc[29] = (lun->block_size >> 16) & 0xFF; -- 1.8.3.1