Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Asias He and committed by
Nicholas Bellinger
8f27d487 f002a243

+8 -3
+8 -3
drivers/target/target_core_pscsi.c
··· 883 883 pr_debug("PSCSI: i: %d page: %p len: %d off: %d\n", i, 884 884 page, len, off); 885 885 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) { 887 894 bytes = min_t(unsigned int, len, PAGE_SIZE - off); 888 895 bytes = min(bytes, data_len); 889 896 ··· 947 940 bio = NULL; 948 941 } 949 942 950 - len -= bytes; 951 943 data_len -= bytes; 952 - off = 0; 953 944 } 954 945 } 955 946