1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
8 <title>kdbus.item</title>
9 <productname>kdbus item</productname>
13 <refentrytitle>kdbus.item</refentrytitle>
14 <manvolnum>7</manvolnum>
18 <refname>kdbus.item</refname>
19 <refpurpose>kdbus item structure, layout and usage</refpurpose>
23 <title>Description</title>
26 To flexibly augment transport structures, data blobs of type
27 <type>struct kdbus_item</type> can be attached to the structs passed
28 into the ioctls. Some ioctls make items of certain types mandatory,
29 others are optional. Items that are unsupported by ioctls they are
30 attached to will cause the ioctl to fail with <varname>errno</varname>
31 set to <constant>EINVAL</constant>.
32 Items are also used for information stored in a connection's
33 <emphasis>pool</emphasis>, such as received messages, name lists or
34 requested connection or bus owner information. Depending on the type of
35 an item, its total size is either fixed or variable.
39 <title>Chaining items</title>
41 Whenever items are used as part of the kdbus kernel API, they are
42 embedded in structs that are embedded inside structs that themselves
43 include a size field containing the overall size of the structure.
44 This allows multiple items to be chained up, and an item iterator
45 (see below) is capable of detecting the end of an item chain.
50 <title>Alignment</title>
52 The kernel expects all items to be aligned to 8-byte boundaries.
53 Unaligned items will cause the ioctl they are used with to fail
54 with <varname>errno</varname> set to <constant>EINVAL</constant>.
55 An item that has an unaligned size itself hence needs to be padded
56 if it is followed by another item.
61 <title>Iterating items</title>
63 A simple iterator would iterate over the items until the items have
64 reached the embedding structure's overall size. An example
65 implementation is shown below.
68 <programlisting><![CDATA[
69 #define KDBUS_ALIGN8(val) (((val) + 7) & ~7)
71 #define KDBUS_ITEM_NEXT(item) \
72 (typeof(item))(((uint8_t *)item) + KDBUS_ALIGN8((item)->size))
74 #define KDBUS_ITEM_FOREACH(item, head, first) \
75 for (item = (head)->first; \
76 ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) && \
77 ((uint8_t *)(item) >= (uint8_t *)(head)); \
78 item = KDBUS_ITEM_NEXT(item))
84 <title>Item layout</title>
86 A <type>struct kdbus_item</type> consists of a
87 <varname>size</varname> field, describing its overall size, and a
88 <varname>type</varname> field, both 64 bit wide. They are followed by
89 a union to store information that is specific to the item's type.
90 The struct layout is shown below.
97 /* item payload - see below */
105 struct kdbus_vec vec;
106 struct kdbus_creds creds;
107 struct kdbus_pids pids;
108 struct kdbus_audit audit;
109 struct kdbus_caps caps;
110 struct kdbus_timestamp timestamp;
111 struct kdbus_name name;
112 struct kdbus_bloom_parameter bloom_parameter;
113 struct kdbus_bloom_filter bloom_filter;
114 struct kdbus_memfd memfd;
116 struct kdbus_notify_name_change name_change;
117 struct kdbus_notify_id_change id_change;
118 struct kdbus_policy_access policy_access;
124 <type>struct kdbus_item</type> should never be used to allocate
125 an item instance, as its size may grow in future releases of the API.
126 Instead, it should be manually assembled by storing the
127 <varname>size</varname>, <varname>type</varname> and payload to a
133 <title>Item types</title>
136 <title>Negotiation item</title>
139 <term><constant>KDBUS_ITEM_NEGOTIATE</constant></term>
141 With this item is attached to any ioctl, programs can
142 <emphasis>probe</emphasis> the kernel for known item types.
143 The item carries an array of <type>uint64_t</type> values in
144 <varname>item.data64</varname>, each set to an item type to
145 probe. The kernel will reset each member of this array that is
146 not recognized as valid item type to <constant>0</constant>.
147 This way, users can negotiate kernel features at start-up to
148 keep newer userspace compatible with older kernels. This item
149 is never attached by the kernel in response to any command.
156 <title>Command specific items</title>
159 <term><constant>KDBUS_ITEM_PAYLOAD_VEC</constant></term>
160 <term><constant>KDBUS_ITEM_PAYLOAD_OFF</constant></term>
162 Messages are directly copied by the sending process into the
165 <refentrytitle>kdbus.pool</refentrytitle>
166 <manvolnum>7</manvolnum>
168 This way, two peers can exchange data by effectively doing a
169 single-copy from one process to another; the kernel will not buffer
170 the data anywhere else. <constant>KDBUS_ITEM_PAYLOAD_VEC</constant>
171 is used when <emphasis>sending</emphasis> message. The item
172 references a memory address when the payload data can be found.
173 <constant>KDBUS_ITEM_PAYLOAD_OFF</constant> is used when messages
174 are <emphasis>received</emphasis>, and the
175 <constant>offset</constant> value describes the offset inside the
176 receiving connection's
178 <refentrytitle>kdbus.pool</refentrytitle>
179 <manvolnum>7</manvolnum>
181 where the message payload can be found. See
183 <refentrytitle>kdbus.message</refentrytitle>
184 <manvolnum>7</manvolnum>
186 for more information on passing of payload data along with a
201 <term><constant>KDBUS_ITEM_PAYLOAD_MEMFD</constant></term>
203 Transports a file descriptor of a <emphasis>memfd</emphasis> in
204 <type>struct kdbus_memfd</type> in <varname>item.memfd</varname>.
205 The <varname>size</varname> field has to match the actual size of
206 the memfd that was specified when it was created. The
207 <varname>start</varname> parameter denotes the offset inside the
208 memfd at which the referenced payload starts. See
210 <refentrytitle>kdbus.message</refentrytitle>
211 <manvolnum>7</manvolnum>
213 for more information on passing of payload data along with a
227 <term><constant>KDBUS_ITEM_FDS</constant></term>
229 Contains an array of <emphasis>file descriptors</emphasis>.
230 When used with <constant>KDBUS_CMD_SEND</constant>, the values of
231 this array must be filled with valid file descriptor numbers.
232 When received as item attached to a message, the array will
233 contain the numbers of the installed file descriptors, or
234 <constant>-1</constant> in case an error occurred.
235 In either case, the number of entries in the array is derived from
236 the item's total size. See
238 <refentrytitle>kdbus.message</refentrytitle>
239 <manvolnum>7</manvolnum>
241 for more information.
248 <title>Items specific to some commands</title>
251 <term><constant>KDBUS_ITEM_CANCEL_FD</constant></term>
253 Transports a file descriptor that can be used to cancel a
254 synchronous <constant>KDBUS_CMD_SEND</constant> operation by
255 writing to it. The file descriptor is stored in
256 <varname>item.fd[0]</varname>. The item may only contain one
259 <refentrytitle>kdbus.message</refentrytitle>
260 <manvolnum>7</manvolnum>
262 for more information on this item and how to use it.
267 <term><constant>KDBUS_ITEM_BLOOM_PARAMETER</constant></term>
269 Contains a set of <emphasis>bloom parameters</emphasis> as
270 <type>struct kdbus_bloom_parameter</type> in
271 <varname>item.bloom_parameter</varname>.
272 The item is passed from userspace to kernel during the
273 <constant>KDBUS_CMD_BUS_MAKE</constant> ioctl, and returned
274 verbatim when <constant>KDBUS_CMD_HELLO</constant> is called.
275 The kernel does not use the bloom parameters, but they need to
276 be known by each connection on the bus in order to define the
277 bloom filter hash details. See
279 <refentrytitle>kdbus.match</refentrytitle>
280 <manvolnum>7</manvolnum>
282 for more information on matching and bloom filters.
284 struct kdbus_bloom_parameter {
293 <term><constant>KDBUS_ITEM_BLOOM_FILTER</constant></term>
295 Carries a <emphasis>bloom filter</emphasis> as
296 <type>struct kdbus_bloom_filter</type> in
297 <varname>item.bloom_filter</varname>. It is mandatory to send this
298 item attached to a <type>struct kdbus_msg</type>, in case the
299 message is a signal. This item is never transported from kernel to
302 <refentrytitle>kdbus.match</refentrytitle>
303 <manvolnum>7</manvolnum>
305 for more information on matching and bloom filters.
307 struct kdbus_bloom_filter {
316 <term><constant>KDBUS_ITEM_BLOOM_MASK</constant></term>
318 Transports a <emphasis>bloom mask</emphasis> as binary data blob
319 stored in <varname>item.data</varname>. This item is used to
320 describe a match into a connection's match database. See
322 <refentrytitle>kdbus.match</refentrytitle>
323 <manvolnum>7</manvolnum>
325 for more information on matching and bloom filters.
330 <term><constant>KDBUS_ITEM_DST_NAME</constant></term>
332 Contains a <emphasis>well-known name</emphasis> to send a
333 message to, as null-terminated string in
334 <varname>item.str</varname>. This item is used with
335 <constant>KDBUS_CMD_SEND</constant>. See
337 <refentrytitle>kdbus.message</refentrytitle>
338 <manvolnum>7</manvolnum>
340 for more information on how to send a message.
345 <term><constant>KDBUS_ITEM_MAKE_NAME</constant></term>
347 Contains a <emphasis>bus name</emphasis> or
348 <emphasis>endpoint name</emphasis>, stored as null-terminated
349 string in <varname>item.str</varname>. This item is sent from
350 userspace to kernel when buses or endpoints are created, and
351 returned back to userspace when the bus creator information is
354 <refentrytitle>kdbus.bus</refentrytitle>
355 <manvolnum>7</manvolnum>
359 <refentrytitle>kdbus.endpoint</refentrytitle>
360 <manvolnum>7</manvolnum>
366 <term><constant>KDBUS_ITEM_ATTACH_FLAGS_SEND</constant></term>
367 <term><constant>KDBUS_ITEM_ATTACH_FLAGS_RECV</constant></term>
369 Contains a set of <emphasis>attach flags</emphasis> at
370 <emphasis>send</emphasis> or <emphasis>receive</emphasis> time. See
372 <refentrytitle>kdbus</refentrytitle>
373 <manvolnum>7</manvolnum>
376 <refentrytitle>kdbus.bus</refentrytitle>
377 <manvolnum>7</manvolnum>
380 <refentrytitle>kdbus.connection</refentrytitle>
381 <manvolnum>7</manvolnum>
383 for more information on attach flags.
388 <term><constant>KDBUS_ITEM_ID</constant></term>
390 Transports a connection's <emphasis>numerical ID</emphasis> of
391 a connection as <type>uint64_t</type> value in
392 <varname>item.id</varname>.
397 <term><constant>KDBUS_ITEM_NAME</constant></term>
399 Transports a name associated with the
400 <emphasis>name registry</emphasis> as null-terminated string as
401 <type>struct kdbus_name</type> in
402 <varname>item.name</varname>. The <varname>flags</varname>
403 contains the flags of the name. See
405 <refentrytitle>kdbus.name</refentrytitle>
406 <manvolnum>7</manvolnum>
408 for more information on how to access the name registry of a bus.
421 <title>Items attached by the kernel as metadata</title>
425 <term><constant>KDBUS_ITEM_TIMESTAMP</constant></term>
427 Contains both the <emphasis>monotonic</emphasis> and the
428 <emphasis>realtime</emphasis> timestamp, taken when the message
429 was processed on the kernel side.
430 Stored as <type>struct kdbus_timestamp</type> in
431 <varname>item.timestamp</varname>.
433 struct kdbus_timestamp {
443 <term><constant>KDBUS_ITEM_CREDS</constant></term>
445 Contains a set of <emphasis>user</emphasis> and
446 <emphasis>group</emphasis> information as 32-bit values, in the
447 usual four flavors: real, effective, saved and filesystem related.
448 Stored as <type>struct kdbus_creds</type> in
449 <varname>item.creds</varname>.
466 <term><constant>KDBUS_ITEM_PIDS</constant></term>
468 Contains the <emphasis>PID</emphasis>, <emphasis>TID</emphasis>
469 and <emphasis>parent PID (PPID)</emphasis> of a remote peer.
470 Stored as <type>struct kdbus_pids</type> in
471 <varname>item.pids</varname>.
483 <term><constant>KDBUS_ITEM_AUXGROUPS</constant></term>
485 Contains the <emphasis>auxiliary (supplementary) groups</emphasis>
486 a remote peer is a member of, stored as array of
487 <type>uint32_t</type> values in <varname>item.data32</varname>.
488 The array length can be determined by looking at the item's total
489 size, subtracting the size of the header and dividing the
490 remainder by <constant>sizeof(uint32_t)</constant>.
495 <term><constant>KDBUS_ITEM_OWNED_NAME</constant></term>
497 Contains a <emphasis>well-known name</emphasis> currently owned
498 by a connection. The name is stored as null-terminated string in
499 <varname>item.str</varname>. Its length can also be derived from
500 the item's total size.
505 <term><constant>KDBUS_ITEM_TID_COMM</constant> [*]</term>
507 Contains the <emphasis>comm</emphasis> string of a task's
508 <emphasis>TID</emphasis> (thread ID), stored as null-terminated
509 string in <varname>item.str</varname>. Its length can also be
510 derived from the item's total size. Receivers of this item should
511 not use its contents for any kind of security measures. See below.
516 <term><constant>KDBUS_ITEM_PID_COMM</constant> [*]</term>
518 Contains the <emphasis>comm</emphasis> string of a task's
519 <emphasis>PID</emphasis> (process ID), stored as null-terminated
520 string in <varname>item.str</varname>. Its length can also be
521 derived from the item's total size. Receivers of this item should
522 not use its contents for any kind of security measures. See below.
527 <term><constant>KDBUS_ITEM_EXE</constant> [*]</term>
529 Contains the <emphasis>path to the executable</emphasis> of a task,
530 stored as null-terminated string in <varname>item.str</varname>. Its
531 length can also be derived from the item's total size. Receivers of
532 this item should not use its contents for any kind of security
538 <term><constant>KDBUS_ITEM_CMDLINE</constant> [*]</term>
540 Contains the <emphasis>command line arguments</emphasis> of a
541 task, stored as an <emphasis>array</emphasis> of null-terminated
542 strings in <varname>item.str</varname>. The total length of all
543 strings in the array can be derived from the item's total size.
544 Receivers of this item should not use its contents for any kind
545 of security measures. See below.
550 <term><constant>KDBUS_ITEM_CGROUP</constant></term>
552 Contains the <emphasis>cgroup path</emphasis> of a task, stored
553 as null-terminated string in <varname>item.str</varname>. Its
554 length can also be derived from the item's total size.
559 <term><constant>KDBUS_ITEM_CAPS</constant></term>
561 Contains sets of <emphasis>capabilities</emphasis>, stored as
562 <type>struct kdbus_caps</type> in <varname>item.caps</varname>.
563 As the item size may increase in the future, programs should be
564 written in a way that it takes
565 <varname>item.caps.last_cap</varname> into account, and derive
566 the number of sets and rows from the item size and the reported
567 number of valid capability bits.
578 <term><constant>KDBUS_ITEM_SECLABEL</constant></term>
580 Contains the <emphasis>LSM label</emphasis> of a task, stored as
581 null-terminated string in <varname>item.str</varname>. Its length
582 can also be derived from the item's total size.
587 <term><constant>KDBUS_ITEM_AUDIT</constant></term>
589 Contains the audit <emphasis>sessionid</emphasis> and
590 <emphasis>loginuid</emphasis> of a task, stored as
591 <type>struct kdbus_audit</type> in
592 <varname>item.audit</varname>.
603 <term><constant>KDBUS_ITEM_CONN_DESCRIPTION</constant></term>
605 Contains the <emphasis>connection description</emphasis>, as set
606 by <constant>KDBUS_CMD_HELLO</constant> or
607 <constant>KDBUS_CMD_CONN_UPDATE</constant>, stored as
608 null-terminated string in <varname>item.str</varname>. Its length
609 can also be derived from the item's total size.
615 All metadata is automatically translated into the
616 <emphasis>namespaces</emphasis> of the task that receives them. See
618 <refentrytitle>kdbus.message</refentrytitle>
619 <manvolnum>7</manvolnum>
621 for more information.
625 [*] Note that the content stored in metadata items of type
626 <constant>KDBUS_ITEM_TID_COMM</constant>,
627 <constant>KDBUS_ITEM_PID_COMM</constant>,
628 <constant>KDBUS_ITEM_EXE</constant> and
629 <constant>KDBUS_ITEM_CMDLINE</constant>
630 can easily be tampered by the sending tasks. Therefore, they should
631 <emphasis>not</emphasis> be used for any sort of security relevant
632 assumptions. The only reason they are transmitted is to let
633 receivers know about details that were set when metadata was
634 collected, even though the task they were collected from is not
635 active any longer when the items are received.
640 <title>Items used for policy entries, matches and notifications</title>
644 <term><constant>KDBUS_ITEM_POLICY_ACCESS</constant></term>
646 This item describes a <emphasis>policy access</emphasis> entry to
647 access the policy database of a
649 <refentrytitle>kdbus.bus</refentrytitle>
650 <manvolnum>7</manvolnum>
653 <refentrytitle>kdbus.endpoint</refentrytitle>
654 <manvolnum>7</manvolnum>
658 <refentrytitle>kdbus.policy</refentrytitle>
659 <manvolnum>7</manvolnum>
661 for more information on the policy database and how to access it.
663 struct kdbus_policy_access {
673 <term><constant>KDBUS_ITEM_ID_ADD</constant></term>
674 <term><constant>KDBUS_ITEM_ID_REMOVE</constant></term>
676 This item is sent as attachment to a
677 <emphasis>kernel notification</emphasis> and indicates that a
678 new connection was created on the bus, or that a connection was
679 disconnected, respectively. It stores a
680 <type>struct kdbus_notify_id_change</type> in
681 <varname>item.id_change</varname>.
682 The <varname>id</varname> field contains the numeric ID of the
683 connection that was added or removed, and <varname>flags</varname>
684 is set to the connection flags, as passed by
685 <constant>KDBUS_CMD_HELLO</constant>. See
687 <refentrytitle>kdbus.match</refentrytitle>
688 <manvolnum>7</manvolnum>
692 <refentrytitle>kdbus.message</refentrytitle>
693 <manvolnum>7</manvolnum>
695 for more information on matches and notification messages.
697 struct kdbus_notify_id_change {
706 <term><constant>KDBUS_ITEM_NAME_ADD</constant></term>
707 <term><constant>KDBUS_ITEM_NAME_REMOVE</constant></term>
708 <term><constant>KDBUS_ITEM_NAME_CHANGE</constant></term>
710 This item is sent as attachment to a
711 <emphasis>kernel notification</emphasis> and indicates that a
712 <emphasis>well-known name</emphasis> appeared, disappeared or
713 transferred to another owner on the bus. It stores a
714 <type>struct kdbus_notify_name_change</type> in
715 <varname>item.name_change</varname>.
716 <varname>old_id</varname> describes the former owner of the name
717 and is set to <constant>0</constant> values in case of
718 <constant>KDBUS_ITEM_NAME_ADD</constant>.
719 <varname>new_id</varname> describes the new owner of the name and
720 is set to <constant>0</constant> values in case of
721 <constant>KDBUS_ITEM_NAME_REMOVE</constant>.
722 The <varname>name</varname> field contains the well-known name the
723 notification is about, as null-terminated string. See
725 <refentrytitle>kdbus.match</refentrytitle>
726 <manvolnum>7</manvolnum>
730 <refentrytitle>kdbus.message</refentrytitle>
731 <manvolnum>7</manvolnum>
733 for more information on matches and notification messages.
735 struct kdbus_notify_name_change {
736 struct kdbus_notify_id_change old_id;
737 struct kdbus_notify_id_change new_id;
745 <term><constant>KDBUS_ITEM_REPLY_TIMEOUT</constant></term>
747 This item is sent as attachment to a
748 <emphasis>kernel notification</emphasis>. It informs the receiver
749 that an expected reply to a message was not received in time.
750 The remote peer ID and the message cookie are stored in the message
753 <refentrytitle>kdbus.message</refentrytitle>
754 <manvolnum>7</manvolnum>
756 for more information about messages, timeouts and notifications.
761 <term><constant>KDBUS_ITEM_REPLY_DEAD</constant></term>
763 This item is sent as attachment to a
764 <emphasis>kernel notification</emphasis>. It informs the receiver
765 that a remote connection a reply is expected from was disconnected
766 before that reply was sent. The remote peer ID and the message
767 cookie are stored in the message header. See
769 <refentrytitle>kdbus.message</refentrytitle>
770 <manvolnum>7</manvolnum>
772 for more information about messages, timeouts and notifications.
780 <title>See Also</title>
781 <simplelist type="inline">
784 <refentrytitle>kdbus</refentrytitle>
785 <manvolnum>7</manvolnum>
790 <refentrytitle>kdbus.bus</refentrytitle>
791 <manvolnum>7</manvolnum>
796 <refentrytitle>kdbus.connection</refentrytitle>
797 <manvolnum>7</manvolnum>
802 <refentrytitle>kdbus.endpoint</refentrytitle>
803 <manvolnum>7</manvolnum>
808 <refentrytitle>kdbus.fs</refentrytitle>
809 <manvolnum>7</manvolnum>
814 <refentrytitle>kdbus.message</refentrytitle>
815 <manvolnum>7</manvolnum>
820 <refentrytitle>kdbus.name</refentrytitle>
821 <manvolnum>7</manvolnum>
826 <refentrytitle>kdbus.pool</refentrytitle>
827 <manvolnum>7</manvolnum>
832 <refentrytitle>memfd_create</refentrytitle>
833 <manvolnum>2</manvolnum>