[CRIU] [PATCH] zdtm: fix a race in socket_udp and socket_udplite

Andrei Vagin avagin at openvz.org
Thu Jan 19 17:56:00 PST 2017


From: Andrei Vagin <avagin at virtuozzo.com>

If we have two sockets and send an upd message from one to another,
we can't be sure that it will be delivered immediately,
there is a change to get from recv(..., MSG_DONTWAIT) EGAIN.

This message is handled asynchronously in a kernel space, so
there may be a small timeout before we get it from another socket.

Reported-by: Mr Travis
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 test/zdtm/static/socket_udp.c     | 4 ++--
 test/zdtm/static/socket_udplite.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/test/zdtm/static/socket_udp.c b/test/zdtm/static/socket_udp.c
index e84e8bf..5e24a8b 100644
--- a/test/zdtm/static/socket_udp.c
+++ b/test/zdtm/static/socket_udp.c
@@ -90,7 +90,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ret = recvfrom(sk1, buf, sizeof(buf), MSG_DONTWAIT,
+	ret = recvfrom(sk1, buf, sizeof(buf), 0,
 			(struct sockaddr *)&addr, &len);
 	if (ret <= 0) {
 		fail("Can't recv C");
@@ -107,7 +107,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ret = recvfrom(sk2, buf, sizeof(buf), MSG_DONTWAIT,
+	ret = recvfrom(sk2, buf, sizeof(buf), 0,
 			(struct sockaddr *)&addr, &len);
 	if (ret <= 0) {
 		fail("Can't recv");
diff --git a/test/zdtm/static/socket_udplite.c b/test/zdtm/static/socket_udplite.c
index aaa40e1..8218ff5 100644
--- a/test/zdtm/static/socket_udplite.c
+++ b/test/zdtm/static/socket_udplite.c
@@ -90,7 +90,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ret = recvfrom(sk1, buf, sizeof(buf), MSG_DONTWAIT,
+	ret = recvfrom(sk1, buf, sizeof(buf), 0,
 			(struct sockaddr *)&addr, &len);
 	if (ret <= 0) {
 		fail("Can't recv C");
@@ -107,7 +107,7 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	ret = recvfrom(sk2, buf, sizeof(buf), MSG_DONTWAIT,
+	ret = recvfrom(sk2, buf, sizeof(buf), 0,
 			(struct sockaddr *)&addr, &len);
 	if (ret <= 0) {
 		fail("Can't recv");
-- 
2.7.4



More information about the CRIU mailing list