Skip to content

Commit 8f27d48

Browse files
Asias HeNicholas Bellinger
authored andcommitted
target/pscsi: Reject cross page boundary case in pscsi_map_sg
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>
1 parent f002a24 commit 8f27d48

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎drivers/target/target_core_pscsi.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,14 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
883883
pr_debug("PSCSI: i: %d page: %p len: %d off: %d\n", i,
884884
page, len, off);
885885

886-
while (len > 0 && data_len > 0) {
886+
/*
887+
* We only have one page of data in each sg element,
888+
* we can not cross a page boundary.
889+
*/
890+
if (off + len > PAGE_SIZE)
891+
goto fail;
892+
893+
if (len > 0 && data_len > 0) {
887894
bytes = min_t(unsigned int, len, PAGE_SIZE - off);
888895
bytes = min(bytes, data_len);
889896

@@ -940,9 +947,7 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
940947
bio = NULL;
941948
}
942949

943-
len -= bytes;
944950
data_len -= bytes;
945-
off = 0;
946951
}
947952
}
948953

0 commit comments

Comments
 (0)