[CRIU] [PATCH] files: check fd flags after restore
Stanislav Kinsburskiy
skinsbursky at virtuozzo.com
Mon Dec 14 07:19:57 PST 2015
System call sys_fcntl() in _some_ kernels can silently drop some flags during
set and return success code.
This patch adds double check, that all the fd flags were really set.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
files.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/files.c b/files.c
index a27667d..751a9a9 100644
--- a/files.c
+++ b/files.c
@@ -741,6 +741,17 @@ int set_fd_flags(int fd, int flags)
ret = fcntl(fd, F_SETFL, flags);
if (ret < 0)
goto err;
+
+ /* Let's check, that now actual flags contains those we need */
+ ret = fcntl(fd, F_GETFL, 0);
+ if (ret < 0)
+ goto err;
+
+ if (ret != flags) {
+ pr_err("fcntl call on fd %d (flags %#o) succeeded, "
+ "but some flags were dropped: %#o\n", fd, flags, ret);
+ return -1;
+ }
return 0;
err:
More information about the CRIU
mailing list