[pve-devel] [RFC/PATCH v2 qemu 2/3] PVE-Backup: ensure jobs in di_list are referenced
Fabian Ebner
f.ebner at proxmox.com
Wed May 25 13:59:38 CEST 2022
Ensures that qmp_backup_cancel doesn't pick a job that's already been
freed. With unlucky timings it seems possible that:
1. job_exit -> job_completed -> job_finalize_single starts
2. pvebackup_co_complete_stream gets spawned in completion callback
3. job finalize_single finishes -> job's refcount hits zero -> job is
freed
4. qmp_backup_cancel comes in and locks backup_state.backup_mutex
before pvebackup_co_complete_stream can remove the job from the
di_list
5. qmp_backup_cancel will pick a job that's already been freed
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
New in v2.
pve-backup.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/pve-backup.c b/pve-backup.c
index dfaf4c93f8..3cede98b1d 100644
--- a/pve-backup.c
+++ b/pve-backup.c
@@ -314,6 +314,11 @@ static void coroutine_fn pvebackup_co_complete_stream(void *opaque)
}
}
+ if (di->job) {
+ job_unref(&di->job->job);
+ di->job = NULL;
+ }
+
// remove self from job list
backup_state.di_list = g_list_remove(backup_state.di_list, di);
@@ -497,6 +502,9 @@ static void create_backup_jobs_bh(void *opaque) {
aio_context_release(aio_context);
di->job = job;
+ if (job) {
+ job_ref(&job->job);
+ }
if (!job || local_err) {
error_setg(errp, "backup_job_create failed: %s",
@@ -531,6 +539,11 @@ static void create_backup_jobs_bh(void *opaque) {
aio_context_release(ctx);
canceled = true;
}
+
+ if (di->job) {
+ job_unref(&di->job->job);
+ di->job = NULL;
+ }
}
}
--
2.30.2
More information about the pve-devel
mailing list