From ed24d8bc75cfcec12f3e3c39075ec3aa0b715cb4 Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Mon, 30 Dec 2013 09:17:01 -0500 Subject: [PATCH] qubes-restore: fix race condition in allocating VM IDs --- dispvm/qubes-restore.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dispvm/qubes-restore.c b/dispvm/qubes-restore.c index 3129d896..038e6f14 100644 --- a/dispvm/qubes-restore.c +++ b/dispvm/qubes-restore.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -415,6 +416,10 @@ int get_next_disposable_id() perror("open dispVM.seq"); exit(1); } + if (flock(fd, LOCK_EX) < 0) { + perror("lock dispVM.seq"); + exit(1); + } if (read(fd, &seq, sizeof(seq)) != sizeof(seq)) { perror("read dispVM.seq"); exit(1); @@ -428,6 +433,7 @@ int get_next_disposable_id() perror("write dispVM.seq"); exit(1); } + flock(fd, LOCK_UN); close(fd); return seq; }