Skip to content

Commit 66fed30

Browse files
stefano-garzarellaXanClic
authored andcommitted
block/mirror: fix NULL pointer dereference in mirror_wait_on_conflicts()
In mirror_iteration() we call mirror_wait_on_conflicts() with `self` parameter set to NULL. Starting from commit d44dae1 we dereference `self` pointer in mirror_wait_on_conflicts() without checks if it is not NULL. Backtrace: Program terminated with signal SIGSEGV, Segmentation fault. #0 mirror_wait_on_conflicts (self=0x0, s=<optimized out>, offset=<optimized out>, bytes=<optimized out>) at ../block/mirror.c:172 172 self->waiting_for_op = op; [Current thread is 1 (Thread 0x7f0908931ec0 (LWP 380249))] (gdb) bt #0 mirror_wait_on_conflicts (self=0x0, s=<optimized out>, offset=<optimized out>, bytes=<optimized out>) at ../block/mirror.c:172 #1 0x00005610c5d9d631 in mirror_run (job=0x5610c76a2c00, errp=<optimized out>) at ../block/mirror.c:491 #2 0x00005610c5d58726 in job_co_entry (opaque=0x5610c76a2c00) at ../job.c:917 #3 0x00005610c5f046c6 in coroutine_trampoline (i0=<optimized out>, i1=<optimized out>) at ../util/coroutine-ucontext.c:173 #4 0x00007f0909975820 in ?? () at ../sysdeps/unix/sysv/linux/x86_64/__start_context.S:91 from /usr/lib64/libc.so.6 Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2001404 Fixes: d44dae1 ("block/mirror: fix active mirror dead-lock in mirror_wait_on_conflicts") Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Message-Id: <20210910124533.288318-1-sgarzare@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
1 parent 098d983 commit 66fed30

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

block/mirror.c

+16-9
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,25 @@ static void coroutine_fn mirror_wait_on_conflicts(MirrorOp *self,
160160
if (ranges_overlap(self_start_chunk, self_nb_chunks,
161161
op_start_chunk, op_nb_chunks))
162162
{
163-
/*
164-
* If the operation is already (indirectly) waiting for us, or
165-
* will wait for us as soon as it wakes up, then just go on
166-
* (instead of producing a deadlock in the former case).
167-
*/
168-
if (op->waiting_for_op) {
169-
continue;
163+
if (self) {
164+
/*
165+
* If the operation is already (indirectly) waiting for us,
166+
* or will wait for us as soon as it wakes up, then just go
167+
* on (instead of producing a deadlock in the former case).
168+
*/
169+
if (op->waiting_for_op) {
170+
continue;
171+
}
172+
173+
self->waiting_for_op = op;
170174
}
171175

172-
self->waiting_for_op = op;
173176
qemu_co_queue_wait(&op->waiting_requests, NULL);
174-
self->waiting_for_op = NULL;
177+
178+
if (self) {
179+
self->waiting_for_op = NULL;
180+
}
181+
175182
break;
176183
}
177184
}

0 commit comments

Comments
 (0)