protocol-native: check msg fds against available fds

Check that the number of fds for the message does not exceed the number
of received fds with SCM_RIGHTS.

The check was simply doing an array bounds check. This could still lead
to out-of-sync fds or usage of uninitialized/invalid fds when the
message header claims more fds than there were passed with SCM_RIGHTS.

Found by Claude Code.
This commit is contained in:
Wim Taymans 2026-04-07 18:20:26 +02:00
parent 247918339e
commit c9ecbf9fab

View file

@ -536,7 +536,7 @@ static int prepare_packet(struct pw_protocol_native_connection *conn, struct buf
size -= impl->hdr_size; size -= impl->hdr_size;
buf->msg.fds = &buf->fds[buf->fds_offset]; buf->msg.fds = &buf->fds[buf->fds_offset];
if (buf->msg.n_fds + buf->fds_offset > MAX_FDS) if (buf->msg.n_fds + buf->fds_offset > buf->n_fds)
return -EPROTO; return -EPROTO;
if (size < len) if (size < len)