Skip to content

Commit

Permalink
target/pscsi: Reject cross page boundary case in pscsi_map_sg
Browse files Browse the repository at this point in the history
We can only have one page of data in each sg element, so we can not
cross a page boundary. Fail this case.

The 'while (len > 0 && data_len > 0) {}' loop is not necessary. The loop
can only be executed once.

Signed-off-by: Asias He <asias@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
  • Loading branch information
Asias He authored and Nicholas Bellinger committed Mar 20, 2013
1 parent f002a24 commit 8f27d48
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/target/target_core_pscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,14 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
pr_debug("PSCSI: i: %d page: %p len: %d off: %d\n", i,
page, len, off);

while (len > 0 && data_len > 0) {
/*
* We only have one page of data in each sg element,
* we can not cross a page boundary.
*/
if (off + len > PAGE_SIZE)
goto fail;

if (len > 0 && data_len > 0) {
bytes = min_t(unsigned int, len, PAGE_SIZE - off);
bytes = min(bytes, data_len);

Expand Down Expand Up @@ -940,9 +947,7 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
bio = NULL;
}

len -= bytes;
data_len -= bytes;
off = 0;
}
}

Expand Down

0 comments on commit 8f27d48

Please sign in to comment.