socket: don't restore ucred from kernel messages

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>
Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>

(cherry picked from commit 70948c510699aa8a2d28fc1669ad25dd81a6b102)
Signed-off-by: Ahmed Elaidy <elaidya225@gmail.com>
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
This commit is contained in:
Andrei Vagin 2026-07-08 22:29:57 +03:00 committed by Alexander Mikhalitsyn
parent 1b3a0c8048
commit d77eb99d2a

View file

@ -160,7 +160,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);
} else {
@ -389,7 +391,7 @@ static int send_one_pkt(int fd, struct sk_packet *pkt)
* boundaries messages should be saved.
*/
if (entry->ucred) {
if (entry->ucred && entry->ucred->pid) {
struct ucred *ucred;
struct cmsghdr *ch;