2 * Copyright (C) 2013 Kay Sievers
3 * Copyright (C) 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4 * Copyright (C) 2013 Linux Foundation
5 * Copyright (C) 2013 Lennart Poettering
6 * Copyright (C) 2013 Daniel Mack <daniel@zonque.org>
8 * kdbus is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Lesser General Public License as published by the
10 * Free Software Foundation; either version 2.1 of the License, or (at
11 * your option) any later version.
13 * "Everything should be made as simple as possible, but not simpler."
21 #include <sys/ioctl.h>
22 #include <sys/types.h>
23 #include <linux/types.h>
26 #define KDBUS_IOCTL_MAGIC 0x95
27 #define KDBUS_SRC_ID_KERNEL (0)
28 #define KDBUS_DST_ID_NAME (0)
29 #define KDBUS_MATCH_ID_ANY (~0ULL)
30 #define KDBUS_DST_ID_BROADCAST (~0ULL)
33 * struct kdbus_notify_id_change - name registry change message
34 * @id: New or former owner of the name
35 * @flags: flags field from KDBUS_HELLO_*
37 * Sent from kernel to userspace when the owner or activator of
38 * a well-known name changes.
42 * KDBUS_ITEM_ID_REMOVE
44 struct kdbus_notify_id_change {
50 * struct kdbus_notify_name_change - name registry change message
51 * @old: ID and flags of former owner of a name
52 * @new: ID and flags of new owner of a name
53 * @name: Well-known name
55 * Sent from kernel to userspace when the owner or activator of
56 * a well-known name changes.
60 * KDBUS_ITEM_NAME_REMOVE
61 * KDBUS_ITEM_NAME_CHANGE
63 struct kdbus_notify_name_change {
64 struct kdbus_notify_id_change old;
65 struct kdbus_notify_id_change new;
70 * struct kdbus_creds - process credentials
75 * @starttime: Starttime of the process
77 * The starttime of the process PID. This is useful to detect PID overruns
78 * from the client side. i.e. if you use the PID to look something up in
79 * /proc/$PID/ you can afterwards check the starttime field of it, to ensure
80 * you didn't run into a PID overrun.
94 * struct kdbus_audit - audit information
95 * @sessionid: The audit session ID
96 * @loginuid: The audit login uid
107 * struct kdbus_timestamp
108 * @seqnum: Global per-domain message sequence number
109 * @monotonic_ns: Monotonic timestamp, in nanoseconds
110 * @realtime_ns: Realtime timestamp, in nanoseconds
113 * KDBUS_ITEM_TIMESTAMP
115 struct kdbus_timestamp {
122 * struct kdbus_vec - I/O vector for kdbus payload items
123 * @size: The size of the vector
124 * @address: Memory address for memory addresses
125 * @offset: Offset in the in-message payload memory,
126 * relative to the message head
129 * KDBUS_ITEM_PAYLOAD_VEC
140 * struct kdbus_bloom_parameter - bus-wide bloom parameters
141 * @size: Size of the bit field in bytes (m / 8)
142 * @n_hash: Number of hash functions used (k)
144 struct kdbus_bloom_parameter {
150 * struct kdbus_bloom_filter - bloom filter containing n elements
151 * @generation: Generation of the element set in the filter
152 * @data: Bit field, multiple of 8 bytes
154 struct kdbus_bloom_filter {
160 * struct kdbus_memfd - a kdbus memfd
161 * @size: The memfd's size
162 * @fd: The file descriptor number
163 * @__pad: Padding to ensure proper alignement and size
166 * KDBUS_ITEM_PAYLOAD_MEMFD
175 * struct kdbus_name - a registered well-known name with its flags
176 * @flags: Flags from KDBUS_NAME_*
177 * @name: Well-known name
188 * struct kdbus_policy_access - policy access item
189 * @type: One of KDBUS_POLICY_ACCESS_* types
190 * @access: Access to grant
191 * @id: For KDBUS_POLICY_ACCESS_USER, the uid
192 * For KDBUS_POLICY_ACCESS_GROUP, the gid
194 struct kdbus_policy_access {
195 __u64 type; /* USER, GROUP, WORLD */
196 __u64 access; /* OWN, TALK, SEE */
197 __u64 id; /* uid, gid, 0 */
201 * enum kdbus_item_type - item types to chain data in a list
202 * @_KDBUS_ITEM_NULL: Uninitialized/invalid
203 * @_KDBUS_ITEM_USER_BASE: Start of user items
204 * @KDBUS_ITEM_PAYLOAD_VEC: Vector to data
205 * @KDBUS_ITEM_PAYLOAD_OFF: Data at returned offset to message head
206 * @KDBUS_ITEM_PAYLOAD_MEMFD: Data as sealed memfd
207 * @KDBUS_ITEM_FDS: Attached file descriptors
208 * @KDBUS_ITEM_BLOOM_PARAMETER: Bus-wide bloom parameters, used with
209 * KDBUS_CMD_BUS_MAKE, carries a
210 * struct kdbus_bloom_parameter
211 * @KDBUS_ITEM_BLOOM_FILTER: Bloom filter carried with a message, used to
212 * match against a bloom mask of a connection,
213 * carries a struct kdbus_bloom_filter
214 * @KDBUS_ITEM_BLOOM_MASK: Bloom mask used to match against a message's
216 * @KDBUS_ITEM_DST_NAME: Destination's well-known name
217 * @KDBUS_ITEM_MAKE_NAME: Name of domain, bus, endpoint
218 * @KDBUS_ITEM_MEMFD_NAME: The human readable name of a memfd (debugging)
219 * @KDBUS_ITEM_ATTACH_FLAGS: Attach-flags, used for updating which metadata
220 * a connection subscribes to
221 * @_KDBUS_ITEM_ATTACH_BASE: Start of metadata attach items
222 * @KDBUS_ITEM_NAME: Well-know name with flags
223 * @KDBUS_ITEM_ID: Connection ID
224 * @KDBUS_ITEM_TIMESTAMP: Timestamp
225 * @KDBUS_ITEM_CREDS: Process credential
226 * @KDBUS_ITEM_PID_COMM: Process ID "comm" identifier
227 * @KDBUS_ITEM_TID_COMM: Thread ID "comm" identifier
228 * @KDBUS_ITEM_EXE: The path of the executable
229 * @KDBUS_ITEM_CMDLINE: The process command line
230 * @KDBUS_ITEM_CGROUP: The croup membership
231 * @KDBUS_ITEM_CAPS: The process capabilities
232 * @KDBUS_ITEM_SECLABEL: The security label
233 * @KDBUS_ITEM_AUDIT: The audit IDs
234 * @KDBUS_ITEM_CONN_NAME: The connection's human-readable name (debugging)
235 * @_KDBUS_ITEM_POLICY_BASE: Start of policy items
236 * @KDBUS_ITEM_POLICY_ACCESS: Policy access block
237 * @_KDBUS_ITEM_KERNEL_BASE: Start of kernel-generated message items
238 * @KDBUS_ITEM_NAME_ADD: Notify in struct kdbus_notify_name_change
239 * @KDBUS_ITEM_NAME_REMOVE: Notify in struct kdbus_notify_name_change
240 * @KDBUS_ITEM_NAME_CHANGE: Notify in struct kdbus_notify_name_change
241 * @KDBUS_ITEM_ID_ADD: Notify in struct kdbus_notify_id_change
242 * @KDBUS_ITEM_ID_REMOVE: Notify in struct kdbus_notify_id_change
243 * @KDBUS_ITEM_REPLY_TIMEOUT: Timeout has been reached
244 * @KDBUS_ITEM_REPLY_DEAD: Destination died
246 enum kdbus_item_type {
248 _KDBUS_ITEM_USER_BASE,
249 KDBUS_ITEM_PAYLOAD_VEC = _KDBUS_ITEM_USER_BASE,
250 KDBUS_ITEM_PAYLOAD_OFF,
251 KDBUS_ITEM_PAYLOAD_MEMFD,
253 KDBUS_ITEM_BLOOM_PARAMETER,
254 KDBUS_ITEM_BLOOM_FILTER,
255 KDBUS_ITEM_BLOOM_MASK,
257 KDBUS_ITEM_MAKE_NAME,
258 KDBUS_ITEM_MEMFD_NAME,
259 KDBUS_ITEM_ATTACH_FLAGS,
261 _KDBUS_ITEM_ATTACH_BASE = 0x1000,
262 KDBUS_ITEM_NAME = _KDBUS_ITEM_ATTACH_BASE,
264 KDBUS_ITEM_TIMESTAMP,
274 KDBUS_ITEM_CONN_NAME,
276 _KDBUS_ITEM_POLICY_BASE = 0x2000,
277 KDBUS_ITEM_POLICY_ACCESS = _KDBUS_ITEM_POLICY_BASE,
279 _KDBUS_ITEM_KERNEL_BASE = 0x8000,
280 KDBUS_ITEM_NAME_ADD = _KDBUS_ITEM_KERNEL_BASE,
281 KDBUS_ITEM_NAME_REMOVE,
282 KDBUS_ITEM_NAME_CHANGE,
284 KDBUS_ITEM_ID_REMOVE,
285 KDBUS_ITEM_REPLY_TIMEOUT,
286 KDBUS_ITEM_REPLY_DEAD,
290 * struct kdbus_item - chain of data blocks
291 * @size: Overall data record size
292 * @type: Kdbus_item type of data
293 * @data: Generic bytes
294 * @data32: Generic 32 bit array
295 * @data64: Generic 64 bit array
296 * @str: Generic string
298 * @vec: KDBUS_ITEM_PAYLOAD_VEC
299 * @creds: KDBUS_ITEM_CREDS
300 * @audit: KDBUS_ITEM_AUDIT
301 * @timestamp: KDBUS_ITEM_TIMESTAMP
302 * @name: KDBUS_ITEM_NAME
303 * @bloom_parameter: KDBUS_ITEM_BLOOM_PARAMETER
304 * @bloom_filter: KDBUS_ITEM_BLOOM_FILTER
305 * @memfd: KDBUS_ITEM_PAYLOAD_MEMFD
306 * @name_change: KDBUS_ITEM_NAME_ADD
307 * KDBUS_ITEM_NAME_REMOVE
308 * KDBUS_ITEM_NAME_CHANGE
309 * @id_change: KDBUS_ITEM_ID_ADD
310 * KDBUS_ITEM_ID_REMOVE
311 * @policy: KDBUS_ITEM_POLICY_ACCESS
323 struct kdbus_vec vec;
324 struct kdbus_creds creds;
325 struct kdbus_audit audit;
326 struct kdbus_timestamp timestamp;
327 struct kdbus_name name;
328 struct kdbus_bloom_parameter bloom_parameter;
329 struct kdbus_bloom_filter bloom_filter;
330 struct kdbus_memfd memfd;
332 struct kdbus_notify_name_change name_change;
333 struct kdbus_notify_id_change id_change;
334 struct kdbus_policy_access policy_access;
339 * enum kdbus_msg_flags - type of message
340 * @KDBUS_MSG_FLAGS_EXPECT_REPLY: Expect a reply message, used for
341 * method calls. The userspace-supplied
342 * cookie identifies the message and the
343 * respective reply carries the cookie
345 * @KDBUS_MSG_FLAGS_SYNC_REPLY: Wait for destination connection to
346 * reply to this message. The
347 * KDBUS_CMD_MSG_SEND ioctl() will block
348 * until the reply is received, and
349 * offset_reply in struct kdbus_msg will
350 * yield the offset in the sender's pool
351 * where the reply can be found.
352 * This flag is only valid if
353 * @KDBUS_MSG_FLAGS_EXPECT_REPLY is set as
355 * @KDBUS_MSG_FLAGS_NO_AUTO_START: Do not start a service, if the addressed
356 * name is not currently active
358 enum kdbus_msg_flags {
359 KDBUS_MSG_FLAGS_EXPECT_REPLY = 1 << 0,
360 KDBUS_MSG_FLAGS_SYNC_REPLY = 1 << 1,
361 KDBUS_MSG_FLAGS_NO_AUTO_START = 1 << 2,
365 * enum kdbus_payload_type - type of payload carried by message
366 * @KDBUS_PAYLOAD_KERNEL: Kernel-generated simple message
367 * @KDBUS_PAYLOAD_DBUS: D-Bus marshalling "DBusDBus"
369 enum kdbus_payload_type {
370 KDBUS_PAYLOAD_KERNEL,
371 KDBUS_PAYLOAD_DBUS = 0x4442757344427573ULL,
375 * struct kdbus_msg - the representation of a kdbus message
376 * @size: Total size of the message
377 * @flags: Message flags (KDBUS_MSG_FLAGS_*)
378 * @priority: Message queue priority value
379 * @dst_id: 64-bit ID of the destination connection
380 * @src_id: 64-bit ID of the source connection
381 * @payload_type: Payload type (KDBUS_PAYLOAD_*)
382 * @cookie: Userspace-supplied cookie, for the connection
383 * to identify its messages
384 * @timeout_ns: The time to wait for a message reply from the peer.
385 * If there is no reply, a kernel-generated message
386 * with an attached KDBUS_ITEM_REPLY_TIMEOUT item
387 * is sent to @src_id.
388 * @cookie_reply: A reply to the requesting message with the same
389 * cookie. The requesting connection can match its
390 * request and the reply with this value
391 * @offset_reply: If KDBUS_MSG_FLAGS_EXPECT_REPLY, this field will
392 * contain the offset in the sender's pool where the
394 * @items: A list of kdbus_items containing the message payload
409 struct kdbus_item items[0];
410 } __attribute__((aligned(8)));
413 * enum kdbus_recv_flags - flags for de-queuing messages
414 * @KDBUS_RECV_PEEK: Return the next queued message without
415 * actually de-queuing it, and without installing
416 * any file descriptors or other resources. It is
417 * usually used to determine the activating
418 * connection of a bus name.
419 * @KDBUS_RECV_DROP: Drop and free the next queued message and all
420 * its resources without actually receiving it.
421 * @KDBUS_RECV_USE_PRIORITY: Only de-queue messages with the specified or
422 * higher priority (lowest values); if not set,
423 * the priority value is ignored.
425 enum kdbus_recv_flags {
426 KDBUS_RECV_PEEK = 1 << 0,
427 KDBUS_RECV_DROP = 1 << 1,
428 KDBUS_RECV_USE_PRIORITY = 1 << 2,
432 * struct kdbus_cmd_recv - struct to de-queue a buffered message
433 * @flags: KDBUS_RECV_* flags
434 * @priority: Minimum priority of the messages to de-queue. Lowest
435 * values have the highest priority.
436 * @offset: Returned offset in the pool where the message is
437 * stored. The user must use KDBUS_CMD_FREE to free
438 * the allocated memory.
440 * This struct is used with the KDBUS_CMD_MSG_RECV ioctl.
442 struct kdbus_cmd_recv {
446 } __attribute__((aligned(8)));
449 * enum kdbus_policy_access_type - permissions of a policy record
450 * @_KDBUS_POLICY_ACCESS_NULL: Uninitialized/invalid
451 * @KDBUS_POLICY_ACCESS_USER: Grant access to a uid
452 * @KDBUS_POLICY_ACCESS_GROUP: Grant access to gid
453 * @KDBUS_POLICY_ACCESS_WORLD: World-accessible
455 enum kdbus_policy_access_type {
456 _KDBUS_POLICY_ACCESS_NULL,
457 KDBUS_POLICY_ACCESS_USER,
458 KDBUS_POLICY_ACCESS_GROUP,
459 KDBUS_POLICY_ACCESS_WORLD,
463 * enum kdbus_policy_access_flags - mode flags
464 * @KDBUS_POLICY_OWN: Allow to own a well-known name
465 * Implies KDBUS_POLICY_TALK and KDBUS_POLICY_SEE
466 * @KDBUS_POLICY_TALK: Allow communication to a well-known name
467 * Implies KDBUS_POLICY_SEE
468 * @KDBUS_POLICY_SEE: Allow to see a well-known name
470 enum kdbus_policy_type {
471 KDBUS_POLICY_SEE = 0,
477 * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
478 * @KDBUS_HELLO_ACCEPT_FD: The connection allows the receiving of
479 * any passed file descriptors
480 * @KDBUS_HELLO_ACTIVATOR: Special-purpose connection which registers
481 * a well-know name for a process to be started
482 * when traffic arrives
483 * @KDBUS_HELLO_POLICY_HOLDER: Special-purpose connection which registers
484 * policy entries for a name. The provided name
485 * is not activated and not registered with the
486 * name database, it only allows unprivileged
487 * connections to aquire a name, talk or discover
489 * @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor
492 enum kdbus_hello_flags {
493 KDBUS_HELLO_ACCEPT_FD = 1 << 0,
494 KDBUS_HELLO_ACTIVATOR = 1 << 1,
495 KDBUS_HELLO_POLICY_HOLDER = 1 << 2,
496 KDBUS_HELLO_MONITOR = 1 << 3,
500 * enum kdbus_attach_flags - flags for metadata attachments
501 * @KDBUS_ATTACH_TIMESTAMP: Timestamp
502 * @KDBUS_ATTACH_CREDS: Credentials
503 * @KDBUS_ATTACH_NAMES: Well-known names
504 * @KDBUS_ATTACH_COMM: The "comm" process identifier
505 * @KDBUS_ATTACH_EXE: The path of the executable
506 * @KDBUS_ATTACH_CMDLINE: The process command line
507 * @KDBUS_ATTACH_CGROUP: The croup membership
508 * @KDBUS_ATTACH_CAPS: The process capabilities
509 * @KDBUS_ATTACH_SECLABEL: The security label
510 * @KDBUS_ATTACH_AUDIT: The audit IDs
511 * @KDBUS_ATTACH_CONN_NAME: The human-readable connection name
512 * @_KDBUS_ATTACH_ALL: All of the above
514 enum kdbus_attach_flags {
515 KDBUS_ATTACH_TIMESTAMP = 1 << 0,
516 KDBUS_ATTACH_CREDS = 1 << 1,
517 KDBUS_ATTACH_NAMES = 1 << 2,
518 KDBUS_ATTACH_COMM = 1 << 3,
519 KDBUS_ATTACH_EXE = 1 << 4,
520 KDBUS_ATTACH_CMDLINE = 1 << 5,
521 KDBUS_ATTACH_CGROUP = 1 << 6,
522 KDBUS_ATTACH_CAPS = 1 << 7,
523 KDBUS_ATTACH_SECLABEL = 1 << 8,
524 KDBUS_ATTACH_AUDIT = 1 << 9,
525 KDBUS_ATTACH_CONN_NAME = 1 << 10,
526 _KDBUS_ATTACH_ALL = (1 << 11) - 1,
530 * struct kdbus_cmd_hello - struct to say hello to kdbus
531 * @size: The total size of the structure
532 * @conn_flags: Connection flags (KDBUS_HELLO_*). The kernel will
533 * return its capabilities in that field.
534 * @attach_flags: Mask of metadata to attach to each message sent
536 * @bus_flags: The flags field copied verbatim from the original
537 * KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
538 * to do negotiation of features of the payload that is
539 * transferred (kernel → userspace)
540 * @id: The ID of this connection (kernel → userspace)
541 * @pool_size: Size of the connection's buffer where the received
542 * messages are placed
543 * @bloom: The bloom properties of the bus, specified
544 * by the bus creator (kernel → userspace)
545 * @id128: Unique 128-bit ID of the bus (kernel → userspace)
546 * @items: A list of items
548 * This struct is used with the KDBUS_CMD_HELLO ioctl.
550 struct kdbus_cmd_hello {
557 struct kdbus_bloom_parameter bloom;
559 struct kdbus_item items[0];
560 } __attribute__((aligned(8)));
563 * enum kdbus_make_flags - Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE
564 * @KDBUS_MAKE_ACCESS_GROUP: Make the device node group-accessible
565 * @KDBUS_MAKE_ACCESS_WORLD: Make the device node world-accessible
567 enum kdbus_make_flags {
568 KDBUS_MAKE_ACCESS_GROUP = 1 << 0,
569 KDBUS_MAKE_ACCESS_WORLD = 1 << 1,
573 * struct kdbus_cmd_make - struct to make a bus, an endpoint or a domain
574 * @size: The total size of the struct
575 * @flags: Properties for the bus/ep/domain to create
576 * @items: Items describing details
578 * This structure is used with the KDBUS_CMD_BUS_MAKE, KDBUS_CMD_EP_MAKE and
579 * KDBUS_CMD_DOMAIN_MAKE ioctls.
581 struct kdbus_cmd_make {
584 struct kdbus_item items[0];
585 } __attribute__((aligned(8)));
588 * enum kdbus_name_flags - properties of a well-known name
589 * @KDBUS_NAME_REPLACE_EXISTING: Try to replace name of other connections
590 * @KDBUS_NAME_ALLOW_REPLACEMENT: Allow the replacement of the name
591 * @KDBUS_NAME_QUEUE: Name should be queued if busy
592 * @KDBUS_NAME_IN_QUEUE: Name is queued
593 * @KDBUS_NAME_ACTIVATOR: Name is owned by a activator connection
595 enum kdbus_name_flags {
596 KDBUS_NAME_REPLACE_EXISTING = 1 << 0,
597 KDBUS_NAME_ALLOW_REPLACEMENT = 1 << 1,
598 KDBUS_NAME_QUEUE = 1 << 2,
599 KDBUS_NAME_IN_QUEUE = 1 << 3,
600 KDBUS_NAME_ACTIVATOR = 1 << 4,
604 * struct kdbus_cmd_name - struct to describe a well-known name
605 * @size: The total size of the struct
606 * @flags: Flags for a name entry (KDBUS_NAME_*)
607 * @owner_id: The current owner of the name.
608 * @conn_flags: The flags of the owning connection (KDBUS_HELLO_*)
609 * @name: The well-known name
611 * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
613 struct kdbus_cmd_name {
619 } __attribute__((aligned(8)));
622 * enum kdbus_name_list_flags - what to include into the returned list
623 * @KDBUS_NAME_LIST_UNIQUE: All active connections
624 * @KDBUS_NAME_LIST_NAMES: All known well-known names
625 * @KDBUS_NAME_LIST_ACTIVATORS: All activator connections
626 * @KDBUS_NAME_LIST_QUEUED: All queued-up names
628 enum kdbus_name_list_flags {
629 KDBUS_NAME_LIST_UNIQUE = 1 << 0,
630 KDBUS_NAME_LIST_NAMES = 1 << 1,
631 KDBUS_NAME_LIST_ACTIVATORS = 1 << 2,
632 KDBUS_NAME_LIST_QUEUED = 1 << 3,
636 * struct kdbus_cmd_name_list - request a list of name entries
637 * @flags: Flags for the query (KDBUS_NAME_LIST_*)
638 * @offset: The returned offset in the caller's pool buffer.
639 * The user must use KDBUS_CMD_FREE to free the
642 * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
644 struct kdbus_cmd_name_list {
647 } __attribute__((aligned(8)));
650 * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
651 * @size: The total size of the structure
652 * @names: A list of names
654 * Note that the user is responsible for freeing the allocated memory with
655 * the KDBUS_CMD_FREE ioctl.
657 struct kdbus_name_list {
659 struct kdbus_cmd_name names[0];
663 * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
664 * @size: The total size of the struct
665 * @flags: KDBUS_ATTACH_* flags
666 * @id: The 64-bit ID of the connection. If set to zero, passing
667 * @name is required. kdbus will look up the name to
668 * determine the ID in this case.
669 * @offset: Returned offset in the caller's pool buffer where the
670 * kdbus_conn_info struct result is stored. The user must
671 * use KDBUS_CMD_FREE to free the allocated memory.
672 * @name: The optional well-known name to look up. Only needed in
675 * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
676 * tell the user the offset in the connection pool buffer at which to find the
677 * result in a struct kdbus_conn_info.
679 struct kdbus_cmd_conn_info {
685 } __attribute__((aligned(8)));
688 * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
689 * @size: The total size of the struct
690 * @id: The connection's 64-bit ID
691 * @flags: The connection's flags
692 * @items: A list of struct kdbus_item
694 * Note that the user is responsible for freeing the allocated memory with
695 * the KDBUS_CMD_FREE ioctl.
697 struct kdbus_conn_info {
701 struct kdbus_item items[0];
705 * struct kdbus_cmd_update - update flags of a connection
706 * @size: The total size of the struct
707 * @items: A list of struct kdbus_item
709 * This struct is used with the KDBUS_CMD_CONN_UPDATE ioctl.
711 struct kdbus_cmd_update {
713 struct kdbus_item items[0];
714 } __attribute__((aligned(8)));
717 * struct kdbus_cmd_match - struct to add or remove matches
718 * @size: The total size of the struct
719 * @cookie: Userspace supplied cookie. When removing, the cookie
720 * identifies the match to remove
721 * @items: A list of items for additional information
723 * This structure is used with the KDBUS_CMD_ADD_MATCH and
724 * KDBUS_CMD_REMOVE_MATCH ioctl.
726 struct kdbus_cmd_match {
729 struct kdbus_item items[0];
730 } __attribute__((aligned(8)));
733 * struct kdbus_cmd_memfd_make - create a kdbus memfd
734 * @size: The total size of the struct
735 * @file_size: The initial file size
736 * @fd: The returned file descriptor number
737 * @__pad: Padding to ensure proper alignement
738 * @items: A list of items for additional information
740 * This structure is used with the KDBUS_CMD_MEMFD_NEW ioctl.
742 struct kdbus_cmd_memfd_make {
747 struct kdbus_item items[0];
748 } __attribute__((aligned(8)));
751 * enum kdbus_ioctl_type - Ioctl API
752 * @KDBUS_CMD_BUS_MAKE: After opening the "control" device node, this
753 * command creates a new bus with the specified
754 * name. The bus is immediately shut down and
755 * cleaned up when the opened "control" device node
757 * @KDBUS_CMD_DOMAIN_MAKE: Similar to KDBUS_CMD_BUS_MAKE, but it creates a
759 * @KDBUS_CMD_EP_MAKE: Creates a new named special endpoint to talk to
760 * the bus. Such endpoints usually carry a more
761 * restrictive policy and grant restricted access
762 * to specific applications.
763 * @KDBUS_CMD_HELLO: By opening the bus device node a connection is
764 * created. After a HELLO the opened connection
765 * becomes an active peer on the bus.
766 * @KDBUS_CMD_BYEBYE: Disconnect a connection. If the connection's
767 * message list is empty, the calls succeeds, and
768 * the handle is rendered unusable. Otherwise,
769 * -EAGAIN is returned without any further side-
771 * @KDBUS_CMD_MSG_SEND: Send a message and pass data from userspace to
773 * @KDBUS_CMD_MSG_RECV: Receive a message from the kernel which is
774 * placed in the receiver's pool.
775 * @KDBUS_CMD_MSG_CANCEL: Cancel a pending request of a message that
776 * blocks while waiting for a reply. The parameter
777 * denotes the cookie of the message in flight.
778 * @KDBUS_CMD_FREE: Release the allocated memory in the receiver's
780 * @KDBUS_CMD_NAME_ACQUIRE: Request a well-known bus name to associate with
781 * the connection. Well-known names are used to
782 * address a peer on the bus.
783 * @KDBUS_CMD_NAME_RELEASE: Release a well-known name the connection
785 * @KDBUS_CMD_NAME_LIST: Retrieve the list of all currently registered
786 * well-known and unique names.
787 * @KDBUS_CMD_CONN_INFO: Retrieve credentials and properties of the
788 * initial creator of the connection. The data was
789 * stored at registration time and does not
790 * necessarily represent the connected process or
791 * the actual state of the process.
792 * @KDBUS_CMD_CONN_UPDATE: Update the properties of a connection. Used to
793 * update the metadata subscription mask and
795 * @KDBUS_CMD_EP_UPDATE: Update the properties of a custom enpoint. Used
796 * to update the policy.
797 * @KDBUS_CMD_MATCH_ADD: Install a match which broadcast messages should
798 * be delivered to the connection.
799 * @KDBUS_CMD_MATCH_REMOVE: Remove a current match for broadcast messages.
800 * @KDBUS_CMD_MEMFD_NEW: Return a new file descriptor which provides an
801 * anonymous shared memory file and which can be
802 * used to pass around larger chunks of data.
803 * Kdbus memfd files can be sealed, which allows
804 * the receiver to trust the data it has received.
805 * Kdbus memfd files expose only very limited
806 * operations, they can be mmap()ed, seek()ed,
807 * (p)read(v)() and (p)write(v)(); most other
808 * common file operations are not implemented.
809 * Special caution needs to be taken with
810 * read(v)()/write(v)() on a shared file; the
811 * underlying file position is always shared
812 * between all users of the file and race against
813 * each other, pread(v)()/pwrite(v)() avoid these
815 * @KDBUS_CMD_MEMFD_SIZE_GET: Return the size of the underlying file, which
816 * changes with write().
817 * @KDBUS_CMD_MEMFD_SIZE_SET: Truncate the underlying file to the specified
819 * @KDBUS_CMD_MEMFD_SEAL_GET: Return the state of the file sealing.
820 * @KDBUS_CMD_MEMFD_SEAL_SET: Seal or break a seal of the file. Only files
821 * which are not shared with other processes and
822 * which are currently not mapped can be sealed.
823 * The current process needs to be the one and
824 * single owner of the file, the sealing cannot
825 * be changed as long as the file is shared.
827 enum kdbus_ioctl_type {
828 KDBUS_CMD_BUS_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x00,
829 struct kdbus_cmd_make),
830 KDBUS_CMD_DOMAIN_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x10,
831 struct kdbus_cmd_make),
832 KDBUS_CMD_EP_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x20,
833 struct kdbus_cmd_make),
835 KDBUS_CMD_HELLO = _IOWR(KDBUS_IOCTL_MAGIC, 0x30,
836 struct kdbus_cmd_hello),
837 KDBUS_CMD_BYEBYE = _IO(KDBUS_IOCTL_MAGIC, 0x31),
839 KDBUS_CMD_MSG_SEND = _IOWR(KDBUS_IOCTL_MAGIC, 0x40,
841 KDBUS_CMD_MSG_RECV = _IOWR(KDBUS_IOCTL_MAGIC, 0x41,
842 struct kdbus_cmd_recv),
843 KDBUS_CMD_MSG_CANCEL = _IOW(KDBUS_IOCTL_MAGIC, 0x42, __u64 *),
844 KDBUS_CMD_FREE = _IOW(KDBUS_IOCTL_MAGIC, 0x43, __u64 *),
846 KDBUS_CMD_NAME_ACQUIRE = _IOWR(KDBUS_IOCTL_MAGIC, 0x50,
847 struct kdbus_cmd_name),
848 KDBUS_CMD_NAME_RELEASE = _IOW(KDBUS_IOCTL_MAGIC, 0x51,
849 struct kdbus_cmd_name),
850 KDBUS_CMD_NAME_LIST = _IOWR(KDBUS_IOCTL_MAGIC, 0x52,
851 struct kdbus_cmd_name_list),
853 KDBUS_CMD_CONN_INFO = _IOWR(KDBUS_IOCTL_MAGIC, 0x60,
854 struct kdbus_cmd_conn_info),
855 KDBUS_CMD_CONN_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x61,
856 struct kdbus_cmd_update),
858 KDBUS_CMD_EP_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x71,
859 struct kdbus_cmd_update),
861 KDBUS_CMD_MATCH_ADD = _IOW(KDBUS_IOCTL_MAGIC, 0x80,
862 struct kdbus_cmd_match),
863 KDBUS_CMD_MATCH_REMOVE = _IOW(KDBUS_IOCTL_MAGIC, 0x81,
864 struct kdbus_cmd_match),
866 KDBUS_CMD_MEMFD_NEW = _IOWR(KDBUS_IOCTL_MAGIC, 0xc0,
867 struct kdbus_cmd_memfd_make),
868 KDBUS_CMD_MEMFD_SIZE_GET = _IOR(KDBUS_IOCTL_MAGIC, 0xc1, __u64 *),
869 KDBUS_CMD_MEMFD_SIZE_SET = _IOW(KDBUS_IOCTL_MAGIC, 0xc2, __u64 *),
870 KDBUS_CMD_MEMFD_SEAL_GET = _IOR(KDBUS_IOCTL_MAGIC, 0xc3, int *),
871 KDBUS_CMD_MEMFD_SEAL_SET = _IO(KDBUS_IOCTL_MAGIC, 0xc4),
875 * errno - api error codes
876 * @E2BIG: A message contains too many records or items.
877 * @EADDRINUSE: A well-known bus name is already taken by another
879 * @EADDRNOTAVAIL: A message flagged not to activate a service, addressed
880 * a service which is not currently running.
881 * @EAGAIN: No messages are queued at the moment.
882 * @EALREADY: A requested name is already owned by the connection,
883 * a connection is already disconnected, memfd is already
884 * sealed or has the requested size.
885 * @EBADF: File descriptors passed with the message are not valid.
886 * @EBADFD: A bus connection is in a corrupted state.
887 * @EBADMSG: Passed data contains a combination of conflicting or
888 * inconsistent types.
889 * @EBUSY: The user tried to say BYEBYE to a connection, but the
890 * connection had a non-empty message list.
891 * @ECANCELED: A synchronous message sending was cancelled.
892 * @ECONNRESET: A connection is shut down, no further operations are
894 * @ECOMM: A peer does not accept the file descriptors addressed
896 * @EDESTADDRREQ: The well-known bus name is required but missing.
897 * @EDOM: The size of data does not match the expectations. Used
898 * for bloom bit field sizes.
899 * @EEXIST: A requested domain, bus or endpoint with the same
900 * name already exists. A specific data type, which is
901 * only expected once, is provided multiple times.
902 * @EFAULT: The supplied memory could not be accessed, or the data
903 * is not properly aligned.
904 * @EINVAL: The provided data does not match its type or other
905 * expectations, like a string which is not NUL terminated,
906 * or a string length that points behind the first
907 * \0-byte in the string.
908 * @EMEDIUMTYPE: A file descriptor which is not a kdbus memfd was
909 * refused to send as KDBUS_MSG_PAYLOAD_MEMFD.
910 * @EMFILE: Too many file descriptors have been supplied with a
912 * Too many connections or buses are created for a given
914 * @EMLINK: Too many requests from this connection to other peers
915 * are queued and waiting for a reply
916 * @EMSGSIZE: The supplied data is larger than the allowed maximum
918 * @ENAMETOOLONG: The requested name is larger than the allowed maximum
920 * @ENOBUFS: There is no space left for the submitted data to fit
921 * into the receiver's pool.
922 * @ENOENT: The to be cancelled message was not found.
923 * @ENOMEM: Out of memory.
924 * @ENOMSG: The queue is not empty, but no message with a matching
925 * priority is currently queued.
926 * @ENOSYS: The requested functionality is not available.
927 * @ENOTTY: An unknown ioctl command was received.
928 * @ENOTUNIQ: A specific data type was addressed to a broadcast
929 * address, but only direct addresses support this kind of
931 * @ENXIO: A unique address does not exist, or an offset in the
932 * receiver's pool does not represent a queued message.
933 * @EOPNOTSUPP: The feature negotiation failed, a not supported feature
934 * was requested, or an unknown item type was received.
935 * @EPERM: The policy prevented an operation. The requested
936 * resource is owned by another entity.
937 * @EPIPE: When sending a message, a synchronous reply from the
938 * receiving connection was expected but the connection
939 * died before answering.
940 * @ESHUTDOWN: A domain, bus or endpoint is currently shutting down;
941 * no further operations will be possible.
942 * @ESRCH: A requested well-known bus name is not found.
943 * @ETIMEDOUT: A synchronous wait for a message reply did not arrive
944 * within the specified time frame.
945 * @ETXTBSY: A kdbus memfd file cannot be sealed or the seal removed,
946 * because it is shared with other processes or still
948 * @EXFULL: The size limits in the pool are reached, no data of
949 * the size tried to submit can be queued.