sk-queue: Don't fail if we're dumping dead process queued creds

The queue may have a dead process' data in such case we rather
should ignore the packet.

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

(cherry picked from commit f854da2284c2c0163055322804aa616b17a34c28)
Signed-off-by: Ahmed Elaidy <elaidya225@gmail.com>
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
This commit is contained in:
Cyrill Gorcunov 2017-04-10 14:53:59 +03:00 committed by Alexander Mikhalitsyn
parent 5641ea6d10
commit c01b6c85ff

View file

@ -265,7 +265,7 @@ static int dump_sk_creds(struct ucred *ucred, SkPacketEntry *pe, int flags)
} else {
int pidns = root_ns_mask & CLONE_NEWPID;
char path[64];
int ret;
int ret, _errno;
/* Does a process exist? */
if (ucred->pid == 0) {
@ -273,21 +273,22 @@ static int dump_sk_creds(struct ucred *ucred, SkPacketEntry *pe, int flags)
} else if (pidns) {
snprintf(path, sizeof(path), "%d", ucred->pid);
ret = faccessat(get_service_fd(CR_PROC_FD_OFF), path, R_OK, 0);
_errno = errno;
} else {
snprintf(path, sizeof(path), "/proc/%d", ucred->pid);
ret = access(path, R_OK);
_errno = errno;
}
if (ret) {
pr_err("Unable to dump ucred for a dead process %d\n", ucred->pid);
goto out;
pr_warn("ucred: Unable to dump ucred for a dead process %d, ignoring packet: %s\n",
ucred->pid, strerror(_errno));
pe->ucred = NULL;
xfree(ent);
return 2;
}
}
return 0;
out:
pe->ucred = NULL;
xfree(ent);
return -1;
}
static int dump_packet_cmsg(struct msghdr *mh, SkPacketEntry *pe, int flags)
@ -455,9 +456,11 @@ int dump_sk_queue(int sock_fd, int sock_id, int flags)
goto err_set_sock;
if (ret > 0) {
ret = -1;
if (queue_packet_entry(&pe, data, pe.length))
goto err_set_sock;
if (ret == 1) {
ret = -1;
if (queue_packet_entry(&pe, data, pe.length))
goto err_set_sock;
}
continue;
}