Skip to content

Commit

Permalink
target_core_rd: break out unterminated loop during copy
Browse files Browse the repository at this point in the history
The loop in rd_execute_rw() will never terminate if the
sg element has a zero size. Or it'll spill over into
outer space if the sg element is larger than the available
space.
So we need to add some safety catches here.

Cc: Nic Bellinger <nab@risingtidesystems.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
  • Loading branch information
Hannes Reinecke authored and Nicholas Bellinger committed Feb 13, 2013
1 parent 1b7f390 commit bbf344e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions drivers/target/target_core_rd.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,19 @@ rd_execute_rw(struct se_cmd *cmd)
void *rd_addr;

sg_miter_next(&m);
if (!(u32)m.length) {
pr_debug("RD[%u]: invalid sgl %p len %zu\n",
dev->rd_dev_id, m.addr, m.length);
sg_miter_stop(&m);
return TCM_INCORRECT_AMOUNT_OF_DATA;
}
len = min((u32)m.length, src_len);
if (len > rd_size) {
pr_debug("RD[%u]: size underrun page %d offset %d "
"size %d\n", dev->rd_dev_id,
rd_page, rd_offset, rd_size);
len = rd_size;
}
m.consumed = len;

rd_addr = sg_virt(rd_sg) + rd_offset;
Expand Down

0 comments on commit bbf344e

Please sign in to comment.