[CRIU] [PATCH] zdtm/maps007: fix a race condition

Andrey Vagin avagin at openvz.org
Tue Jan 20 07:58:02 PST 2015


If shm->delta = MAX_DELTA and we set shm->stop to 1, the child can exit
before the parent adds MAX_DELTA to shm->delta.

parent			child
shm->stop = 1
			if (shm->stop == 1 && shm->delta == MAX_DELTA)
				break
shm->delta += MAX_DELTA

Cc: Konstantin Neumoin <kneumoin at parallels.com>
Reported-by: Konstantin Neumoin <kneumoin at parallels.com>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/live/transition/maps007.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/test/zdtm/live/transition/maps007.c b/test/zdtm/live/transition/maps007.c
index 53b0b4c..d589b87 100644
--- a/test/zdtm/live/transition/maps007.c
+++ b/test/zdtm/live/transition/maps007.c
@@ -73,17 +73,20 @@ int main(int argc, char **argv)
 	if (child)
 		test_daemon();
 
-	while (test_go()) {
+	while (1) {
 		void *ret;
 		unsigned long size;
 		int prot = PROT_NONE;
 
 		if (child) {
+			if (!test_go())
+				break;
 			futex_wait_while_gt(&shm->delta, 2 * MAX_DELTA);
 			futex_inc_and_wake(&shm->delta);
 		} else {
 			if (!futex_get(&shm->stop))
-				futex_wait_while_lt(&shm->delta, MAX_DELTA);
+				/* shm->delta must be always bigger than MAX_DELTA */
+				futex_wait_while_lt(&shm->delta, MAX_DELTA + 2);
 
 			if (futex_get(&shm->stop) && atomic_get(&shm->delta.raw) == MAX_DELTA)
 				break;
@@ -123,6 +126,8 @@ int main(int argc, char **argv)
 	test_msg("count %d\n", count);
 
 	if (child == 0) {
+		if (!test_go())
+			err("unexpected state");
 		futex_set_and_wake(&shm->stop, 2);
 		test_waitsig();
 	} else {
-- 
1.9.3



More information about the CRIU mailing list