[CRIU] [PATCH 3/5] netlink: prevent dumping of sockets if they are not collected

Andrey Vagin avagin at openvz.org
Wed Mar 27 09:23:15 EDT 2013


If netlink sockets are not collected and a dumped task has a netlink
socket, crtools should return an errror instead of dumping it as a
"clear" socket.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/sockets.h | 2 ++
 sk-netlink.c      | 7 +++++++
 sockets.c         | 3 ++-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/sockets.h b/include/sockets.h
index a596fa8..66726c9 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -26,6 +26,8 @@ struct socket_desc {
 	int			already_dumped;
 };
 
+extern bool netlink_collected;
+
 extern int dump_socket(struct fd_parms *p, int lfd, const int fdinfo);
 extern int dump_socket_opts(int sk, SkOptsEntry *soe);
 extern int restore_socket_opts(int sk, SkOptsEntry *soe);
diff --git a/sk-netlink.c b/sk-netlink.c
index 48194dd..e7f0b0a 100644
--- a/sk-netlink.c
+++ b/sk-netlink.c
@@ -13,6 +13,8 @@
 #include "netlink_diag.h"
 #include "libnetlink.h"
 
+bool netlink_collected;
+
 struct netlink_sk_desc {
 	struct socket_desc	sd;
 	u32                     portid;
@@ -90,6 +92,11 @@ static int dump_one_netlink_fd(int lfd, u32 id, const struct fd_parms *p)
 	NetlinkSkEntry ne = NETLINK_SK_ENTRY__INIT;
 	SkOptsEntry skopts = SK_OPTS_ENTRY__INIT;
 
+	if (!netlink_collected) {
+		pr_err("Netlink sockets are not collected\n");
+		return -1;
+	}
+
 	sk = (struct netlink_sk_desc *)lookup_socket(p->stat.st_ino, PF_NETLINK);
 
 	ne.id = id;
diff --git a/sockets.c b/sockets.c
index 83bc7f3..0b992f5 100644
--- a/sockets.c
+++ b/sockets.c
@@ -531,7 +531,8 @@ int collect_sockets(int pid)
 			pr_warn("The currect kernel doesn't support netlink_diag\n");
 		else
 			err = tmp;
-	}
+	} else
+		netlink_collected = true;
 
 	close(nl);
 out:
-- 
1.7.11.7



More information about the CRIU mailing list