summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYi Zou <yi.zou@intel.com>2012-08-14 16:06:43 -0700
committerNicholas Bellinger <nab@linux-iscsi.org>2012-08-16 17:33:46 -0700
commitd0e27c88d795fb9647153063ec48051fd84e1731 (patch)
treec8b27735e4104bae438aa481d36e91eeb6ee5816
parent1fa8f4504130adc34a071a29170f570102136835 (diff)
downloadlinux-d0e27c88d795fb9647153063ec48051fd84e1731.tar.gz
linux-d0e27c88d795fb9647153063ec48051fd84e1731.tar.bz2
linux-d0e27c88d795fb9647153063ec48051fd84e1731.zip
target: fix NULL pointer dereference bug alloc_page() fails to get memory
I am hitting this bug when the target is low in memory that fails the alloc_page() for the newly submitted command. This is a sort of off-by-one bug causing NULL pointer dereference in __free_page() since 'i' here is really the counter of total pages that have been successfully allocated here. Signed-off-by: Yi Zou <yi.zou@intel.com> Cc: Andy Grover <agrover@redhat.com> Cc: Nicholas Bellinger <nab@linux-iscsi.org> Cc: Open-FCoE.org <devel@open-fcoe.org> Cc: stable@vger.kernel.org Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r--drivers/target/target_core_transport.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 0eaae23d12b5..a7589ccdb6f3 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -2294,9 +2294,9 @@ transport_generic_get_mem(struct se_cmd *cmd)
return 0;
out:
- while (i >= 0) {
- __free_page(sg_page(&cmd->t_data_sg[i]));
+ while (i > 0) {
i--;
+ __free_page(sg_page(&cmd->t_data_sg[i]));
}
kfree(cmd->t_data_sg);
cmd->t_data_sg = NULL;