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_AUXGROUPS: Auxiliary process groups
227 * @KDBUS_ITEM_PID_COMM: Process ID "comm" identifier
228 * @KDBUS_ITEM_TID_COMM: Thread ID "comm" identifier
229 * @KDBUS_ITEM_EXE: The path of the executable
230 * @KDBUS_ITEM_CMDLINE: The process command line
231 * @KDBUS_ITEM_CGROUP: The croup membership
232 * @KDBUS_ITEM_CAPS: The process capabilities
233 * @KDBUS_ITEM_SECLABEL: The security label
234 * @KDBUS_ITEM_AUDIT: The audit IDs
235 * @KDBUS_ITEM_CONN_NAME: The connection's human-readable name (debugging)
236 * @_KDBUS_ITEM_POLICY_BASE: Start of policy items
237 * @KDBUS_ITEM_POLICY_ACCESS: Policy access block
238 * @_KDBUS_ITEM_KERNEL_BASE: Start of kernel-generated message items
239 * @KDBUS_ITEM_NAME_ADD: Notify in struct kdbus_notify_name_change
240 * @KDBUS_ITEM_NAME_REMOVE: Notify in struct kdbus_notify_name_change
241 * @KDBUS_ITEM_NAME_CHANGE: Notify in struct kdbus_notify_name_change
242 * @KDBUS_ITEM_ID_ADD: Notify in struct kdbus_notify_id_change
243 * @KDBUS_ITEM_ID_REMOVE: Notify in struct kdbus_notify_id_change
244 * @KDBUS_ITEM_REPLY_TIMEOUT: Timeout has been reached
245 * @KDBUS_ITEM_REPLY_DEAD: Destination died
247 enum kdbus_item_type {
249 _KDBUS_ITEM_USER_BASE,
250 KDBUS_ITEM_PAYLOAD_VEC = _KDBUS_ITEM_USER_BASE,
251 KDBUS_ITEM_PAYLOAD_OFF,
252 KDBUS_ITEM_PAYLOAD_MEMFD,
254 KDBUS_ITEM_BLOOM_PARAMETER,
255 KDBUS_ITEM_BLOOM_FILTER,
256 KDBUS_ITEM_BLOOM_MASK,
258 KDBUS_ITEM_MAKE_NAME,
259 KDBUS_ITEM_MEMFD_NAME,
260 KDBUS_ITEM_ATTACH_FLAGS,
262 _KDBUS_ITEM_ATTACH_BASE = 0x1000,
263 KDBUS_ITEM_NAME = _KDBUS_ITEM_ATTACH_BASE,
265 KDBUS_ITEM_TIMESTAMP,
267 KDBUS_ITEM_AUXGROUPS,
276 KDBUS_ITEM_CONN_NAME,
278 _KDBUS_ITEM_POLICY_BASE = 0x2000,
279 KDBUS_ITEM_POLICY_ACCESS = _KDBUS_ITEM_POLICY_BASE,
281 _KDBUS_ITEM_KERNEL_BASE = 0x8000,
282 KDBUS_ITEM_NAME_ADD = _KDBUS_ITEM_KERNEL_BASE,
283 KDBUS_ITEM_NAME_REMOVE,
284 KDBUS_ITEM_NAME_CHANGE,
286 KDBUS_ITEM_ID_REMOVE,
287 KDBUS_ITEM_REPLY_TIMEOUT,
288 KDBUS_ITEM_REPLY_DEAD,
292 * struct kdbus_item - chain of data blocks
293 * @size: Overall data record size
294 * @type: Kdbus_item type of data
295 * @data: Generic bytes
296 * @data32: Generic 32 bit array
297 * @data64: Generic 64 bit array
298 * @str: Generic string
300 * @vec: KDBUS_ITEM_PAYLOAD_VEC
301 * @creds: KDBUS_ITEM_CREDS
302 * @audit: KDBUS_ITEM_AUDIT
303 * @timestamp: KDBUS_ITEM_TIMESTAMP
304 * @name: KDBUS_ITEM_NAME
305 * @bloom_parameter: KDBUS_ITEM_BLOOM_PARAMETER
306 * @bloom_filter: KDBUS_ITEM_BLOOM_FILTER
307 * @memfd: KDBUS_ITEM_PAYLOAD_MEMFD
308 * @name_change: KDBUS_ITEM_NAME_ADD
309 * KDBUS_ITEM_NAME_REMOVE
310 * KDBUS_ITEM_NAME_CHANGE
311 * @id_change: KDBUS_ITEM_ID_ADD
312 * KDBUS_ITEM_ID_REMOVE
313 * @policy: KDBUS_ITEM_POLICY_ACCESS
325 struct kdbus_vec vec;
326 struct kdbus_creds creds;
327 struct kdbus_audit audit;
328 struct kdbus_timestamp timestamp;
329 struct kdbus_name name;
330 struct kdbus_bloom_parameter bloom_parameter;
331 struct kdbus_bloom_filter bloom_filter;
332 struct kdbus_memfd memfd;
334 struct kdbus_notify_name_change name_change;
335 struct kdbus_notify_id_change id_change;
336 struct kdbus_policy_access policy_access;
341 * enum kdbus_msg_flags - type of message
342 * @KDBUS_MSG_FLAGS_EXPECT_REPLY: Expect a reply message, used for
343 * method calls. The userspace-supplied
344 * cookie identifies the message and the
345 * respective reply carries the cookie
347 * @KDBUS_MSG_FLAGS_SYNC_REPLY: Wait for destination connection to
348 * reply to this message. The
349 * KDBUS_CMD_MSG_SEND ioctl() will block
350 * until the reply is received, and
351 * offset_reply in struct kdbus_msg will
352 * yield the offset in the sender's pool
353 * where the reply can be found.
354 * This flag is only valid if
355 * @KDBUS_MSG_FLAGS_EXPECT_REPLY is set as
357 * @KDBUS_MSG_FLAGS_NO_AUTO_START: Do not start a service, if the addressed
358 * name is not currently active
360 enum kdbus_msg_flags {
361 KDBUS_MSG_FLAGS_EXPECT_REPLY = 1 << 0,
362 KDBUS_MSG_FLAGS_SYNC_REPLY = 1 << 1,
363 KDBUS_MSG_FLAGS_NO_AUTO_START = 1 << 2,
367 * enum kdbus_payload_type - type of payload carried by message
368 * @KDBUS_PAYLOAD_KERNEL: Kernel-generated simple message
369 * @KDBUS_PAYLOAD_DBUS: D-Bus marshalling "DBusDBus"
371 enum kdbus_payload_type {
372 KDBUS_PAYLOAD_KERNEL,
373 KDBUS_PAYLOAD_DBUS = 0x4442757344427573ULL,
377 * struct kdbus_msg - the representation of a kdbus message
378 * @size: Total size of the message
379 * @flags: Message flags (KDBUS_MSG_FLAGS_*)
380 * @priority: Message queue priority value
381 * @dst_id: 64-bit ID of the destination connection
382 * @src_id: 64-bit ID of the source connection
383 * @payload_type: Payload type (KDBUS_PAYLOAD_*)
384 * @cookie: Userspace-supplied cookie, for the connection
385 * to identify its messages
386 * @timeout_ns: The time to wait for a message reply from the peer.
387 * If there is no reply, a kernel-generated message
388 * with an attached KDBUS_ITEM_REPLY_TIMEOUT item
389 * is sent to @src_id.
390 * @cookie_reply: A reply to the requesting message with the same
391 * cookie. The requesting connection can match its
392 * request and the reply with this value
393 * @offset_reply: If KDBUS_MSG_FLAGS_EXPECT_REPLY, this field will
394 * contain the offset in the sender's pool where the
396 * @items: A list of kdbus_items containing the message payload
411 struct kdbus_item items[0];
412 } __attribute__((aligned(8)));
415 * enum kdbus_recv_flags - flags for de-queuing messages
416 * @KDBUS_RECV_PEEK: Return the next queued message without
417 * actually de-queuing it, and without installing
418 * any file descriptors or other resources. It is
419 * usually used to determine the activating
420 * connection of a bus name.
421 * @KDBUS_RECV_DROP: Drop and free the next queued message and all
422 * its resources without actually receiving it.
423 * @KDBUS_RECV_USE_PRIORITY: Only de-queue messages with the specified or
424 * higher priority (lowest values); if not set,
425 * the priority value is ignored.
427 enum kdbus_recv_flags {
428 KDBUS_RECV_PEEK = 1 << 0,
429 KDBUS_RECV_DROP = 1 << 1,
430 KDBUS_RECV_USE_PRIORITY = 1 << 2,
434 * struct kdbus_cmd_recv - struct to de-queue a buffered message
435 * @flags: KDBUS_RECV_* flags
436 * @priority: Minimum priority of the messages to de-queue. Lowest
437 * values have the highest priority.
438 * @offset: Returned offset in the pool where the message is
439 * stored. The user must use KDBUS_CMD_FREE to free
440 * the allocated memory.
442 * This struct is used with the KDBUS_CMD_MSG_RECV ioctl.
444 struct kdbus_cmd_recv {
448 } __attribute__((aligned(8)));
451 * enum kdbus_policy_access_type - permissions of a policy record
452 * @_KDBUS_POLICY_ACCESS_NULL: Uninitialized/invalid
453 * @KDBUS_POLICY_ACCESS_USER: Grant access to a uid
454 * @KDBUS_POLICY_ACCESS_GROUP: Grant access to gid
455 * @KDBUS_POLICY_ACCESS_WORLD: World-accessible
457 enum kdbus_policy_access_type {
458 _KDBUS_POLICY_ACCESS_NULL,
459 KDBUS_POLICY_ACCESS_USER,
460 KDBUS_POLICY_ACCESS_GROUP,
461 KDBUS_POLICY_ACCESS_WORLD,
465 * enum kdbus_policy_access_flags - mode flags
466 * @KDBUS_POLICY_OWN: Allow to own a well-known name
467 * Implies KDBUS_POLICY_TALK and KDBUS_POLICY_SEE
468 * @KDBUS_POLICY_TALK: Allow communication to a well-known name
469 * Implies KDBUS_POLICY_SEE
470 * @KDBUS_POLICY_SEE: Allow to see a well-known name
472 enum kdbus_policy_type {
473 KDBUS_POLICY_SEE = 0,
479 * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
480 * @KDBUS_HELLO_ACCEPT_FD: The connection allows the receiving of
481 * any passed file descriptors
482 * @KDBUS_HELLO_ACTIVATOR: Special-purpose connection which registers
483 * a well-know name for a process to be started
484 * when traffic arrives
485 * @KDBUS_HELLO_POLICY_HOLDER: Special-purpose connection which registers
486 * policy entries for a name. The provided name
487 * is not activated and not registered with the
488 * name database, it only allows unprivileged
489 * connections to aquire a name, talk or discover
491 * @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor
494 enum kdbus_hello_flags {
495 KDBUS_HELLO_ACCEPT_FD = 1 << 0,
496 KDBUS_HELLO_ACTIVATOR = 1 << 1,
497 KDBUS_HELLO_POLICY_HOLDER = 1 << 2,
498 KDBUS_HELLO_MONITOR = 1 << 3,
502 * enum kdbus_attach_flags - flags for metadata attachments
503 * @KDBUS_ATTACH_TIMESTAMP: Timestamp
504 * @KDBUS_ATTACH_CREDS: Credentials
505 * @KDBUS_ATTACH_AUXGROUPS: Auxiliary groups
506 * @KDBUS_ATTACH_NAMES: Well-known names
507 * @KDBUS_ATTACH_COMM: The "comm" process identifier
508 * @KDBUS_ATTACH_EXE: The path of the executable
509 * @KDBUS_ATTACH_CMDLINE: The process command line
510 * @KDBUS_ATTACH_CGROUP: The croup membership
511 * @KDBUS_ATTACH_CAPS: The process capabilities
512 * @KDBUS_ATTACH_SECLABEL: The security label
513 * @KDBUS_ATTACH_AUDIT: The audit IDs
514 * @KDBUS_ATTACH_CONN_NAME: The human-readable connection name
515 * @_KDBUS_ATTACH_ALL: All of the above
517 enum kdbus_attach_flags {
518 KDBUS_ATTACH_TIMESTAMP = 1 << 0,
519 KDBUS_ATTACH_CREDS = 1 << 1,
520 KDBUS_ATTACH_AUXGROUPS = 1 << 2,
521 KDBUS_ATTACH_NAMES = 1 << 3,
522 KDBUS_ATTACH_COMM = 1 << 4,
523 KDBUS_ATTACH_EXE = 1 << 5,
524 KDBUS_ATTACH_CMDLINE = 1 << 6,
525 KDBUS_ATTACH_CGROUP = 1 << 7,
526 KDBUS_ATTACH_CAPS = 1 << 8,
527 KDBUS_ATTACH_SECLABEL = 1 << 9,
528 KDBUS_ATTACH_AUDIT = 1 << 10,
529 KDBUS_ATTACH_CONN_NAME = 1 << 11,
530 _KDBUS_ATTACH_ALL = (1 << 12) - 1,
534 * struct kdbus_cmd_hello - struct to say hello to kdbus
535 * @size: The total size of the structure
536 * @conn_flags: Connection flags (KDBUS_HELLO_*). The kernel will
537 * return its capabilities in that field.
538 * @attach_flags: Mask of metadata to attach to each message sent
540 * @bus_flags: The flags field copied verbatim from the original
541 * KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
542 * to do negotiation of features of the payload that is
543 * transferred (kernel → userspace)
544 * @id: The ID of this connection (kernel → userspace)
545 * @pool_size: Size of the connection's buffer where the received
546 * messages are placed
547 * @bloom: The bloom properties of the bus, specified
548 * by the bus creator (kernel → userspace)
549 * @id128: Unique 128-bit ID of the bus (kernel → userspace)
550 * @items: A list of items
552 * This struct is used with the KDBUS_CMD_HELLO ioctl.
554 struct kdbus_cmd_hello {
561 struct kdbus_bloom_parameter bloom;
563 struct kdbus_item items[0];
564 } __attribute__((aligned(8)));
567 * enum kdbus_make_flags - Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE
568 * @KDBUS_MAKE_ACCESS_GROUP: Make the device node group-accessible
569 * @KDBUS_MAKE_ACCESS_WORLD: Make the device node world-accessible
571 enum kdbus_make_flags {
572 KDBUS_MAKE_ACCESS_GROUP = 1 << 0,
573 KDBUS_MAKE_ACCESS_WORLD = 1 << 1,
577 * struct kdbus_cmd_make - struct to make a bus, an endpoint or a domain
578 * @size: The total size of the struct
579 * @flags: Properties for the bus/ep/domain to create
580 * @items: Items describing details
582 * This structure is used with the KDBUS_CMD_BUS_MAKE, KDBUS_CMD_EP_MAKE and
583 * KDBUS_CMD_DOMAIN_MAKE ioctls.
585 struct kdbus_cmd_make {
588 struct kdbus_item items[0];
589 } __attribute__((aligned(8)));
592 * enum kdbus_name_flags - properties of a well-known name
593 * @KDBUS_NAME_REPLACE_EXISTING: Try to replace name of other connections
594 * @KDBUS_NAME_ALLOW_REPLACEMENT: Allow the replacement of the name
595 * @KDBUS_NAME_QUEUE: Name should be queued if busy
596 * @KDBUS_NAME_IN_QUEUE: Name is queued
597 * @KDBUS_NAME_ACTIVATOR: Name is owned by a activator connection
599 enum kdbus_name_flags {
600 KDBUS_NAME_REPLACE_EXISTING = 1 << 0,
601 KDBUS_NAME_ALLOW_REPLACEMENT = 1 << 1,
602 KDBUS_NAME_QUEUE = 1 << 2,
603 KDBUS_NAME_IN_QUEUE = 1 << 3,
604 KDBUS_NAME_ACTIVATOR = 1 << 4,
608 * struct kdbus_cmd_name - struct to describe a well-known name
609 * @size: The total size of the struct
610 * @flags: Flags for a name entry (KDBUS_NAME_*)
611 * @owner_id: The current owner of the name.
612 * @conn_flags: The flags of the owning connection (KDBUS_HELLO_*)
613 * @name: The well-known name
615 * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
617 struct kdbus_cmd_name {
623 } __attribute__((aligned(8)));
626 * enum kdbus_name_list_flags - what to include into the returned list
627 * @KDBUS_NAME_LIST_UNIQUE: All active connections
628 * @KDBUS_NAME_LIST_NAMES: All known well-known names
629 * @KDBUS_NAME_LIST_ACTIVATORS: All activator connections
630 * @KDBUS_NAME_LIST_QUEUED: All queued-up names
632 enum kdbus_name_list_flags {
633 KDBUS_NAME_LIST_UNIQUE = 1 << 0,
634 KDBUS_NAME_LIST_NAMES = 1 << 1,
635 KDBUS_NAME_LIST_ACTIVATORS = 1 << 2,
636 KDBUS_NAME_LIST_QUEUED = 1 << 3,
640 * struct kdbus_cmd_name_list - request a list of name entries
641 * @flags: Flags for the query (KDBUS_NAME_LIST_*)
642 * @offset: The returned offset in the caller's pool buffer.
643 * The user must use KDBUS_CMD_FREE to free the
646 * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
648 struct kdbus_cmd_name_list {
651 } __attribute__((aligned(8)));
654 * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
655 * @size: The total size of the structure
656 * @names: A list of names
658 * Note that the user is responsible for freeing the allocated memory with
659 * the KDBUS_CMD_FREE ioctl.
661 struct kdbus_name_list {
663 struct kdbus_cmd_name names[0];
667 * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
668 * @size: The total size of the struct
669 * @flags: KDBUS_ATTACH_* flags
670 * @id: The 64-bit ID of the connection. If set to zero, passing
671 * @name is required. kdbus will look up the name to
672 * determine the ID in this case.
673 * @offset: Returned offset in the caller's pool buffer where the
674 * kdbus_conn_info struct result is stored. The user must
675 * use KDBUS_CMD_FREE to free the allocated memory.
676 * @name: The optional well-known name to look up. Only needed in
679 * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
680 * tell the user the offset in the connection pool buffer at which to find the
681 * result in a struct kdbus_conn_info.
683 struct kdbus_cmd_conn_info {
689 } __attribute__((aligned(8)));
692 * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
693 * @size: The total size of the struct
694 * @id: The connection's 64-bit ID
695 * @flags: The connection's flags
696 * @items: A list of struct kdbus_item
698 * Note that the user is responsible for freeing the allocated memory with
699 * the KDBUS_CMD_FREE ioctl.
701 struct kdbus_conn_info {
705 struct kdbus_item items[0];
709 * struct kdbus_cmd_update - update flags of a connection
710 * @size: The total size of the struct
711 * @items: A list of struct kdbus_item
713 * This struct is used with the KDBUS_CMD_CONN_UPDATE ioctl.
715 struct kdbus_cmd_update {
717 struct kdbus_item items[0];
718 } __attribute__((aligned(8)));
721 * struct kdbus_cmd_match - struct to add or remove matches
722 * @size: The total size of the struct
723 * @cookie: Userspace supplied cookie. When removing, the cookie
724 * identifies the match to remove
725 * @items: A list of items for additional information
727 * This structure is used with the KDBUS_CMD_ADD_MATCH and
728 * KDBUS_CMD_REMOVE_MATCH ioctl.
730 struct kdbus_cmd_match {
733 struct kdbus_item items[0];
734 } __attribute__((aligned(8)));
737 * struct kdbus_cmd_memfd_make - create a kdbus memfd
738 * @size: The total size of the struct
739 * @file_size: The initial file size
740 * @fd: The returned file descriptor number
741 * @__pad: Padding to ensure proper alignement
742 * @items: A list of items for additional information
744 * This structure is used with the KDBUS_CMD_MEMFD_NEW ioctl.
746 struct kdbus_cmd_memfd_make {
751 struct kdbus_item items[0];
752 } __attribute__((aligned(8)));
755 * enum kdbus_ioctl_type - Ioctl API
756 * @KDBUS_CMD_BUS_MAKE: After opening the "control" device node, this
757 * command creates a new bus with the specified
758 * name. The bus is immediately shut down and
759 * cleaned up when the opened "control" device node
761 * @KDBUS_CMD_DOMAIN_MAKE: Similar to KDBUS_CMD_BUS_MAKE, but it creates a
763 * @KDBUS_CMD_EP_MAKE: Creates a new named special endpoint to talk to
764 * the bus. Such endpoints usually carry a more
765 * restrictive policy and grant restricted access
766 * to specific applications.
767 * @KDBUS_CMD_HELLO: By opening the bus device node a connection is
768 * created. After a HELLO the opened connection
769 * becomes an active peer on the bus.
770 * @KDBUS_CMD_BYEBYE: Disconnect a connection. If the connection's
771 * message list is empty, the calls succeeds, and
772 * the handle is rendered unusable. Otherwise,
773 * -EAGAIN is returned without any further side-
775 * @KDBUS_CMD_MSG_SEND: Send a message and pass data from userspace to
777 * @KDBUS_CMD_MSG_RECV: Receive a message from the kernel which is
778 * placed in the receiver's pool.
779 * @KDBUS_CMD_MSG_CANCEL: Cancel a pending request of a message that
780 * blocks while waiting for a reply. The parameter
781 * denotes the cookie of the message in flight.
782 * @KDBUS_CMD_FREE: Release the allocated memory in the receiver's
784 * @KDBUS_CMD_NAME_ACQUIRE: Request a well-known bus name to associate with
785 * the connection. Well-known names are used to
786 * address a peer on the bus.
787 * @KDBUS_CMD_NAME_RELEASE: Release a well-known name the connection
789 * @KDBUS_CMD_NAME_LIST: Retrieve the list of all currently registered
790 * well-known and unique names.
791 * @KDBUS_CMD_CONN_INFO: Retrieve credentials and properties of the
792 * initial creator of the connection. The data was
793 * stored at registration time and does not
794 * necessarily represent the connected process or
795 * the actual state of the process.
796 * @KDBUS_CMD_CONN_UPDATE: Update the properties of a connection. Used to
797 * update the metadata subscription mask and
799 * @KDBUS_CMD_EP_UPDATE: Update the properties of a custom enpoint. Used
800 * to update the policy.
801 * @KDBUS_CMD_MATCH_ADD: Install a match which broadcast messages should
802 * be delivered to the connection.
803 * @KDBUS_CMD_MATCH_REMOVE: Remove a current match for broadcast messages.
804 * @KDBUS_CMD_MEMFD_NEW: Return a new file descriptor which provides an
805 * anonymous shared memory file and which can be
806 * used to pass around larger chunks of data.
807 * Kdbus memfd files can be sealed, which allows
808 * the receiver to trust the data it has received.
809 * Kdbus memfd files expose only very limited
810 * operations, they can be mmap()ed, seek()ed,
811 * (p)read(v)() and (p)write(v)(); most other
812 * common file operations are not implemented.
813 * Special caution needs to be taken with
814 * read(v)()/write(v)() on a shared file; the
815 * underlying file position is always shared
816 * between all users of the file and race against
817 * each other, pread(v)()/pwrite(v)() avoid these
819 * @KDBUS_CMD_MEMFD_SIZE_GET: Return the size of the underlying file, which
820 * changes with write().
821 * @KDBUS_CMD_MEMFD_SIZE_SET: Truncate the underlying file to the specified
823 * @KDBUS_CMD_MEMFD_SEAL_GET: Return the state of the file sealing.
824 * @KDBUS_CMD_MEMFD_SEAL_SET: Seal or break a seal of the file. Only files
825 * which are not shared with other processes and
826 * which are currently not mapped can be sealed.
827 * The current process needs to be the one and
828 * single owner of the file, the sealing cannot
829 * be changed as long as the file is shared.
831 enum kdbus_ioctl_type {
832 KDBUS_CMD_BUS_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x00,
833 struct kdbus_cmd_make),
834 KDBUS_CMD_DOMAIN_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x10,
835 struct kdbus_cmd_make),
836 KDBUS_CMD_EP_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x20,
837 struct kdbus_cmd_make),
839 KDBUS_CMD_HELLO = _IOWR(KDBUS_IOCTL_MAGIC, 0x30,
840 struct kdbus_cmd_hello),
841 KDBUS_CMD_BYEBYE = _IO(KDBUS_IOCTL_MAGIC, 0x31),
843 KDBUS_CMD_MSG_SEND = _IOWR(KDBUS_IOCTL_MAGIC, 0x40,
845 KDBUS_CMD_MSG_RECV = _IOWR(KDBUS_IOCTL_MAGIC, 0x41,
846 struct kdbus_cmd_recv),
847 KDBUS_CMD_MSG_CANCEL = _IOW(KDBUS_IOCTL_MAGIC, 0x42, __u64 *),
848 KDBUS_CMD_FREE = _IOW(KDBUS_IOCTL_MAGIC, 0x43, __u64 *),
850 KDBUS_CMD_NAME_ACQUIRE = _IOWR(KDBUS_IOCTL_MAGIC, 0x50,
851 struct kdbus_cmd_name),
852 KDBUS_CMD_NAME_RELEASE = _IOW(KDBUS_IOCTL_MAGIC, 0x51,
853 struct kdbus_cmd_name),
854 KDBUS_CMD_NAME_LIST = _IOWR(KDBUS_IOCTL_MAGIC, 0x52,
855 struct kdbus_cmd_name_list),
857 KDBUS_CMD_CONN_INFO = _IOWR(KDBUS_IOCTL_MAGIC, 0x60,
858 struct kdbus_cmd_conn_info),
859 KDBUS_CMD_CONN_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x61,
860 struct kdbus_cmd_update),
862 KDBUS_CMD_EP_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x71,
863 struct kdbus_cmd_update),
865 KDBUS_CMD_MATCH_ADD = _IOW(KDBUS_IOCTL_MAGIC, 0x80,
866 struct kdbus_cmd_match),
867 KDBUS_CMD_MATCH_REMOVE = _IOW(KDBUS_IOCTL_MAGIC, 0x81,
868 struct kdbus_cmd_match),
870 KDBUS_CMD_MEMFD_NEW = _IOWR(KDBUS_IOCTL_MAGIC, 0xc0,
871 struct kdbus_cmd_memfd_make),
872 KDBUS_CMD_MEMFD_SIZE_GET = _IOR(KDBUS_IOCTL_MAGIC, 0xc1, __u64 *),
873 KDBUS_CMD_MEMFD_SIZE_SET = _IOW(KDBUS_IOCTL_MAGIC, 0xc2, __u64 *),
874 KDBUS_CMD_MEMFD_SEAL_GET = _IOR(KDBUS_IOCTL_MAGIC, 0xc3, int *),
875 KDBUS_CMD_MEMFD_SEAL_SET = _IO(KDBUS_IOCTL_MAGIC, 0xc4),
879 * errno - api error codes
880 * @E2BIG: A message contains too many records or items.
881 * @EADDRINUSE: A well-known bus name is already taken by another
883 * @EADDRNOTAVAIL: A message flagged not to activate a service, addressed
884 * a service which is not currently running.
885 * @EAGAIN: No messages are queued at the moment.
886 * @EALREADY: A requested name is already owned by the connection,
887 * a connection is already disconnected, memfd is already
888 * sealed or has the requested size.
889 * @EBADF: File descriptors passed with the message are not valid.
890 * @EBADFD: A bus connection is in a corrupted state.
891 * @EBADMSG: Passed data contains a combination of conflicting or
892 * inconsistent types.
893 * @EBUSY: The user tried to say BYEBYE to a connection, but the
894 * connection had a non-empty message list.
895 * @ECANCELED: A synchronous message sending was cancelled.
896 * @ECONNRESET: A connection is shut down, no further operations are
898 * @ECOMM: A peer does not accept the file descriptors addressed
900 * @EDESTADDRREQ: The well-known bus name is required but missing.
901 * @EDOM: The size of data does not match the expectations. Used
902 * for bloom bit field sizes.
903 * @EEXIST: A requested domain, bus or endpoint with the same
904 * name already exists. A specific data type, which is
905 * only expected once, is provided multiple times.
906 * @EFAULT: The supplied memory could not be accessed, the data
907 * is not properly aligned, or the current task's memory
909 * @EINVAL: The provided data does not match its type or other
910 * expectations, like a string which is not NUL terminated,
911 * or a string length that points behind the first
912 * \0-byte in the string.
913 * @EMEDIUMTYPE: A file descriptor which is not a kdbus memfd was
914 * refused to send as KDBUS_MSG_PAYLOAD_MEMFD.
915 * @EMFILE: Too many file descriptors have been supplied with a
917 * Too many connections or buses are created for a given
919 * @EMLINK: Too many requests from this connection to other peers
920 * are queued and waiting for a reply
921 * @EMSGSIZE: The supplied data is larger than the allowed maximum
923 * @ENAMETOOLONG: The requested name is larger than the allowed maximum
925 * @ENOBUFS: There is no space left for the submitted data to fit
926 * into the receiver's pool.
927 * @ENOENT: The to be cancelled message was not found.
928 * @ENOMEM: Out of memory.
929 * @ENOMSG: The queue is not empty, but no message with a matching
930 * priority is currently queued.
931 * @ENOSYS: The requested functionality is not available.
932 * @ENOTTY: An unknown ioctl command was received.
933 * @ENOTUNIQ: A specific data type was addressed to a broadcast
934 * address, but only direct addresses support this kind of
936 * @ENXIO: A unique address does not exist, or an offset in the
937 * receiver's pool does not represent a queued message.
938 * @EOPNOTSUPP: The feature negotiation failed, a not supported feature
939 * was requested, or an unknown item type was received.
940 * @EPERM: The policy prevented an operation. The requested
941 * resource is owned by another entity.
942 * @EPIPE: When sending a message, a synchronous reply from the
943 * receiving connection was expected but the connection
944 * died before answering.
945 * @ESHUTDOWN: A domain, bus or endpoint is currently shutting down;
946 * no further operations will be possible.
947 * @ESRCH: A requested well-known bus name is not found.
948 * @ETIMEDOUT: A synchronous wait for a message reply did not arrive
949 * within the specified time frame.
950 * @ETXTBSY: A kdbus memfd file cannot be sealed or the seal removed,
951 * because it is shared with other processes or still
953 * @EXFULL: The size limits in the pool are reached, no data of
954 * the size tried to submit can be queued.