[Devel,3/5] socket: don't restore ucred from kernel messages

Submitted by Andrei Vagin on Feb. 19, 2017, 6:58 a.m.

Details

Message ID 1487487496-12063-4-git-send-email-avagin@openvz.org
State New
Series "A few fixes for netlink sockets"
Headers show

Commit Message

Andrei Vagin Feb. 19, 2017, 6:58 a.m.
From: Andrei Vagin <avagin@virtuozzo.com>

ucred.pid is zero for kernel messages and in this case it is
impossible to restore it.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/sk-queue.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/sk-queue.c b/criu/sk-queue.c
index e72ca45..88e47b8 100644
--- a/criu/sk-queue.c
+++ b/criu/sk-queue.c
@@ -92,7 +92,9 @@  static int dump_sk_creds(struct ucred *ucred, SkPacketEntry *pe, int flags)
 		int ret;
 
 		/* Does a process exist? */
-		if (pidns) {
+		if (ucred->pid == 0) {
+			ret = 0;
+		} else if (pidns) {
 			snprintf(path, sizeof(path), "%d", ucred->pid);
 			ret = faccessat(get_service_fd(CR_PROC_FD_OFF),
 							path, R_OK, 0);
@@ -322,7 +324,7 @@  int restore_sk_queue(int fd, unsigned int peer_id)
 			goto err;
 		}
 
-		if (entry->ucred) {
+		if (entry->ucred && entry->ucred->pid) {
 			struct ucred *ucred;
 			struct cmsghdr *ch;