test: use kdbus_msg_dump() to check for message integrity

Make kdbus_msg_dump() return an error in case there's anything wrong
with the message. Return such errors from kdbus_msg_recv(). We currently
fail with notifications.

Signed-off-by: Daniel Mack <daniel@zonque.org>
Revert "notify: set item->size"

This reverts commit b62c3ed2b7bed76935a57a9a65e7bba63602b4c4.

m->msg.items[0].size is already set from kdbus_kmsg_new(), so this
is unnecessary. Furthermode, we need to ALIGN8() the item size, which
kdbus_kmsg_new() also does for us already.
handle.c: fix and add kernel-doc

Signed-off-by: Daniel Mack <daniel@zonque.org>
Makefile: add 'doc' target

So easy the process of checking kernel-doc entries

Signed-off-by: Daniel Mack <daniel@zonque.org>
test-sync: do a second recv only when SA_RESTART was passed

The test was working for all cases, but fix it to only check for the
SA_RESTART case.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
test: make sure that creating endpoint with long names will fail

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
test: just define KDBUS_SYSNAME_MAX_LEN here in test-endpoint

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
connection: remove unused variable

That was introduced by a wrong conflict resolution.

Signed-off-by: Daniel Mack <daniel@zonque.org>
message: allow memfds for broadcast messages

As discussed on LPC.

Signed-off-by: Daniel Mack <daniel@zonque.org>
test-fd: add a bloom filter to broadcast message

Satisfy a kernel check so we can be sure we really bail out due
to the check we're actually enforcing.

Signed-off-by: Daniel Mack <daniel@zonque.org>
message: we want to allow O_PATHed file descriptors

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
message: switch to fget_raw() to allow passing O_PATH file descriptors

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
kdbus.h: add KDBUS_CMD_BUS_CREATOR_INFO

Add a call to return metadata on the task that created a bus, at the
moment it did so. The call behaves similar to KDBUS_CMD_CONN_INFO, and
shares the same dispatcher code in handle.c.

While at it, factor out bus-related test functions to their own file,
and also add some code test the new ioctl.

Signed-off-by: Daniel Mack <daniel@zonque.org>
kdbus.h: rename kdbus_{cmd,}_conn_info → kdbus_{cmd,}_info

As we now use kdbus_cmd_conn_info and kdbus_conn_info for bus creator
information as well, rename the structs to a more generic term.

Signed-off-by: Daniel Mack <daniel@zonque.org>
test-fd: make sure that passed fds do not also allow fd queueing

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
connection: simplify reply cleanups

There is no reason why we cannot destroy replies while holding a
connection lock. If the reply points to the connection whose lock we hold,
we also have another ref on that connection due to our context. If the
lock points to another connection, we can simply unref it at any time.

Note that we never cause disconnects on the connection. We only unref it!
The object destruction is a simple memory cleanup. Nothing fancy is done
there, and no inter-object refs can exist anymore (otherwise, it would not
get freed). Therefore, fix all our callers to free replies directly,
instead of releasing the locks first.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
connection: don't send DEAD-NOTIFICATIONS on sync SENDs

If we synchronously send messages, we never queue notifications on the
sender if a timeout or reset occurs. Fix the DEAD_DESTINATION handling to
not queue such messages either.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
connection: rename reply->conn to reply->reply_dst

reply->conn is pretty vague and I have a hard time remembering which side
of the communication it points to. Rename it to "reply_dst" so it's clear
that it points to the destination of the reply (or: origin of the call).

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
connection: correctly filter messages on name takeover

If a name is taken over by an activator, we move messages that were
targetted at the this exact name over. However, we must make sure to leave
all other messages correctly queued on the source, so it can continue
using other names it might posess.

This fixes the filtering we apply on the messages itself, to no longer
leak them. Furthermore, it also applies proper filtering to the conn_reply
objects, so only matching objects are moved.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
connection: dont leak replies if message-queueing fails

Currently, we queue the conn_reply _before_ queueing the actual message.
This might leak conn_reply objects if we cannot queue the message. Avoid
this by queuing the conn_reply object at the same time we queue the
message.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>