Skip to contentSkip to conversation

block/iscsi: fix potential segfault on early callback

PATCH Applied Peter Lieven 2 participants 3 messages Jun 10, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/iscsi: fix potential segfault on early callback

it might happen in the future that a function directly invokes its callback. In this case we end up in a segfault because the iTask is gone when the BH is scheduled.

---
 block/iscsi.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
block/iscsi.c +4 -1
index 019b324..4bf4238 100644
@@ -146,6 +146,7 @@ iscsi_schedule_bh(IscsiAIOCB *acb)
 static void iscsi_co_generic_bh_cb(void *opaque)
 {
     struct IscsiTask *iTask = opaque;
+    iTask->complete = 1;
     qemu_bh_delete(iTask->bh);
     qemu_coroutine_enter(iTask->co, NULL);
 }
@@ -153,6 +154,7 @@ static void iscsi_co_generic_bh_cb(void *opaque)
 static void iscsi_retry_timer_expired(void *opaque)
 {
     struct IscsiTask *iTask = opaque;
+    iTask->complete = 1;
     if (iTask->co) {
         qemu_coroutine_enter(iTask->co, NULL);
     }
@@ -171,7 +173,6 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
     struct IscsiTask *iTask = opaque;
     struct scsi_task *task = command_data;
 
-    iTask->complete = 1;
     iTask->status = status;
     iTask->do_retry = 0;
     iTask->task = task;
@@ -209,6 +210,8 @@ out:
         iTask->bh = aio_bh_new(iTask->iscsilun->aio_context,
                                iscsi_co_generic_bh_cb, iTask);
         qemu_bh_schedule(iTask->bh);
+    } else {
+        iTask->complete = 1;
     }
 }
 
Signature · 1 line
1.7.9.5
#1 lore raw

Il 10/06/2014 09:52, Peter Lieven ha scritto:

Quoted 39 lines

it might happen in the future that a function directly invokes its callback. In this case we end up in a segfault because the iTask is gone when the BH is scheduled.

---
 block/iscsi.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
block/iscsi.c +2 -1
index 019b324..4bf4238 100644
@@ -146,6 +146,7 @@ iscsi_schedule_bh(IscsiAIOCB *acb)
 static void iscsi_co_generic_bh_cb(void *opaque)
 {
     struct IscsiTask *iTask = opaque;
+    iTask->complete = 1;
     qemu_bh_delete(iTask->bh);
     qemu_coroutine_enter(iTask->co, NULL);
 }
@@ -153,6 +154,7 @@ static void iscsi_co_generic_bh_cb(void *opaque)
 static void iscsi_retry_timer_expired(void *opaque)
 {
     struct IscsiTask *iTask = opaque;
+    iTask->complete = 1;
     if (iTask->co) {
         qemu_coroutine_enter(iTask->co, NULL);
     }
@@ -171,7 +173,6 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
     struct IscsiTask *iTask = opaque;
     struct scsi_task *task = command_data;
 
-    iTask->complete = 1;
     iTask->status = status;
     iTask->do_retry = 0;
     iTask->task = task;

block/iscsi.c out: · line 217

Quoted 8 lines
block/iscsi.c +2 -0
@@ -209,6 +210,8 @@ out:
         iTask->bh = aio_bh_new(iTask->iscsilun->aio_context,
                                iscsi_co_generic_bh_cb, iTask);
         qemu_bh_schedule(iTask->bh);
+    } else {
+        iTask->complete = 1;
     }
 }
 

Applied, thanks. I'll leave the nfs patch to Kevin and/or Stefan.

Paolo

#2 lore raw
Quoted 34 lines · Paolo Bonzini

Il 10/06/2014 09:52, Peter Lieven ha scritto:

Quoted 33 lines

it might happen in the future that a function directly invokes its callback. In this case we end up in a segfault because the iTask is gone when the BH is scheduled.

---
 block/iscsi.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
block/iscsi.c +2 -0
index 019b324..4bf4238 100644
@@ -146,6 +146,7 @@ iscsi_schedule_bh(IscsiAIOCB *acb)
 static void iscsi_co_generic_bh_cb(void *opaque)
 {
     struct IscsiTask *iTask = opaque;
+    iTask->complete = 1;
     qemu_bh_delete(iTask->bh);
     qemu_coroutine_enter(iTask->co, NULL);
 }
@@ -153,6 +154,7 @@ static void iscsi_co_generic_bh_cb(void *opaque)
 static void iscsi_retry_timer_expired(void *opaque)
 {
     struct IscsiTask *iTask = opaque;
+    iTask->complete = 1;
     if (iTask->co) {
         qemu_coroutine_enter(iTask->co, NULL);
     }
@@ -171,7 +173,6 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
     struct IscsiTask *iTask = opaque;
     struct scsi_task *task = command_data;
 
Quoted 16 lines
Quoted 6 lines
block/iscsi.c +0 -1
-    iTask->complete = 1;
     iTask->status = status;
     iTask->do_retry = 0;
     iTask->task = task;

block/iscsi.c out: · line 217

Quoted 8 lines
block/iscsi.c +2 -0
@@ -209,6 +210,8 @@ out:
         iTask->bh = aio_bh_new(iTask->iscsilun->aio_context,
                                iscsi_co_generic_bh_cb, iTask);
         qemu_bh_schedule(iTask->bh);
+    } else {
+        iTask->complete = 1;
     }
 }
 

Applied, thanks. I'll leave the nfs patch to Kevin and/or Stefan.

Thank you,

Stefan/Kevin I messed up the commit message. Can you please fix when picking up:

---8<---

it will happen in the future that a function directly invokes its callback. In this case we end up in a segfault because the NFSRPC is gone when we the BH is scheduled.

--->8---

Thanks,
Peter