sk-queue: Add missing MSG_CTRUNC check in dump_sk_queue

After recvmsg() with MSG_PEEK, dump_sk_queue() checks for MSG_TRUNC
(data truncation) but not MSG_CTRUNC (control data truncation). When
the control message buffer is too small, the kernel sets MSG_CTRUNC
and silently discards the overflowing ancillary data. For SCM_RIGHTS,
this means passed file descriptors are lost without any error.

Add a MSG_CTRUNC check right after the existing MSG_TRUNC check so
that dump fails explicitly instead of silently producing an incomplete
image.

Signed-off-by: Ahmed Elaidy <elaidya225@gmail.com>
This commit is contained in:
Ahmed Elaidy 2026-02-25 21:09:00 +02:00 committed by Alexander Mikhalitsyn
parent d72f1586bc
commit 83fc5aca02
No known key found for this signature in database
GPG key ID: B1F47F5CB05B4FA3

View file

@ -244,6 +244,17 @@ int dump_sk_queue(int sock_fd, int sock_id)
ret = -E2BIG;
goto err_set_sock;
}
if (msg.msg_flags & MSG_CTRUNC) {
/*
* Control data truncated. This means the cmsg
* buffer was too small and SCM data (such as
* passed file descriptors) has been silently
* discarded by the kernel.
*/
pr_err("sys_recvmsg failed: control data truncated\n");
ret = -E2BIG;
goto err_set_sock;
}
if (dump_packet_cmsg(&msg, &pe))
goto err_set_sock;