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.
18 #include <sys/ioctl.h>
19 #include <sys/types.h>
20 #include <linux/types.h>
23 #define KDBUS_IOC_MAGIC 0x95
24 #define KDBUS_SRC_ID_KERNEL (0)
25 #define KDBUS_DST_ID_NAME (0)
26 #define KDBUS_MATCH_SRC_ID_ANY (~0ULL)
27 #define KDBUS_DST_ID_BROADCAST (~0ULL)
30 * struct KDBUS_PART_HEADER - anonymous struct used as header
31 * @size: Size of element, excluding padding bytes
32 * @type Type of element
34 * Common first elements in a structure, used to specify the type
35 * and size of the data.
37 #define KDBUS_PART_HEADER \
44 * struct kdbus_notify_name_change - name registry change message
45 * @old_id Former owner of a name
46 * @new_id New owner of a name
47 * @flags flags from KDBUS_NAME_*
48 * @name Well-known name
52 * KDBUS_ITEM_NAME_REMOVE
53 * KDBUS_ITEM_NAME_CHANGE
55 * Sent from kernel to userspace when the owner or starter of
56 * a well-known name changes.
58 struct kdbus_notify_name_change {
66 * struct kdbus_notify_id_change - name registry change message
67 * @id New or former owner of the name
68 * @flags flags field from KDBUS_HELLO_*
72 * KDBUS_ITEM_ID_REMOVE
74 * Sent from kernel to userspace when the owner or starter of
75 * a well-known name changes.
77 struct kdbus_notify_id_change {
83 * struct kdbus_creds - process credentials
88 * @starttime Starttime of the process
90 * The starttime of the process PID. This is useful to detect PID overruns
91 * from the client side. i.e. if you use the PID to look something up in
92 * /proc/$PID/ you can afterwards check the starttime field of it, to ensure
93 * you didn't run into a PID overrun.
104 * struct kdbus_audit - audit information
105 * @sessionid The audit session ID
106 * @loginuid The audit login uid
114 * struct kdbus_timestamp
115 * @monotonic_ns: Monotonic timestamp, in nanoseconds
116 * @realtime_ns: Realtime timestamp, in nanoseconds
118 struct kdbus_timestamp {
124 * struct kdbus_vec - I/O vector for kdbus payload items
125 * @size: The size of the vector
126 * @address Memory address for memory addresses
127 * @offset Offset in the in-message payload memory
138 * struct kdbus_memfd - a kdbus memfd
139 * @size: The memfd's size
140 * @fd: The file descriptor number
141 * @__pad: Padding to make the struct aligned
150 * struct kdbus_name - a registered well-known name with its flags
151 * @flags flags from KDBUS_NAME_*
152 * @name well-known name
159 /* Message Item Types */
163 /* Filled in by userspace */
164 _KDBUS_ITEM_USER_BASE = 1,
165 KDBUS_ITEM_PAYLOAD_VEC = 1, /* .data_vec, reference to memory area */
166 KDBUS_ITEM_PAYLOAD_OFF, /* .data_vec, reference to memory area */
167 KDBUS_ITEM_PAYLOAD_MEMFD, /* file descriptor of a special data file */
168 KDBUS_ITEM_FDS, /* .data_fds of file descriptors */
169 KDBUS_ITEM_BLOOM, /* for broadcasts, carries bloom filter blob in .data */
170 KDBUS_ITEM_DST_NAME, /* destination's well-known name, in .str */
171 KDBUS_ITEM_PRIORITY, /* queue priority for message */
173 /* Filled in by kernelspace */
174 _KDBUS_ITEM_ATTACH_BASE = 0x400,
175 KDBUS_ITEM_NAME = 0x400,/* NUL separated string list with well-known names of source */
176 KDBUS_ITEM_STARTER_NAME, /* Only used in HELLO for starter connection */
177 KDBUS_ITEM_TIMESTAMP, /* .timestamp */
179 /* when appended to a message, the following items refer to the sender */
180 KDBUS_ITEM_CREDS, /* .creds */
181 KDBUS_ITEM_PID_COMM, /* optional, in .str */
182 KDBUS_ITEM_TID_COMM, /* optional, in .str */
183 KDBUS_ITEM_EXE, /* optional, in .str */
184 KDBUS_ITEM_CMDLINE, /* optional, in .str (a chain of NUL str) */
185 KDBUS_ITEM_CGROUP, /* optional, in .str */
186 KDBUS_ITEM_CAPS, /* caps data blob, in .data */
187 KDBUS_ITEM_SECLABEL, /* NUL terminated string, in .str */
188 KDBUS_ITEM_AUDIT, /* .audit */
190 /* Special messages from kernel, consisting of one and only one of these data blocks */
191 _KDBUS_ITEM_KERNEL_BASE = 0x800,
192 KDBUS_ITEM_NAME_ADD = 0x800,/* .name_change */
193 KDBUS_ITEM_NAME_REMOVE, /* .name_change */
194 KDBUS_ITEM_NAME_CHANGE, /* .name_change */
195 KDBUS_ITEM_ID_ADD, /* .id_change */
196 KDBUS_ITEM_ID_REMOVE, /* .id_change */
197 KDBUS_ITEM_REPLY_TIMEOUT, /* empty, but .reply_cookie in .kdbus_msg is filled in */
198 KDBUS_ITEM_REPLY_DEAD, /* dito */
202 * struct kdbus_item - chain of data blocks
203 * @size : overall data record size
204 * @type: kdbus_item type of data
219 struct kdbus_vec vec;
221 /* process credentials and properties*/
222 struct kdbus_creds creds;
223 struct kdbus_audit audit;
224 struct kdbus_timestamp timestamp;
225 struct kdbus_name name;
227 /* specific fields */
228 struct kdbus_memfd memfd;
230 struct kdbus_notify_name_change name_change;
231 struct kdbus_notify_id_change id_change;
236 KDBUS_MSG_FLAGS_EXPECT_REPLY = 1 << 0,
237 KDBUS_MSG_FLAGS_NO_AUTO_START = 1 << 1,
241 KDBUS_PAYLOAD_KERNEL,
242 KDBUS_PAYLOAD_DBUS1 = 0x4442757356657231ULL, /* 'DBusVer1' */
243 KDBUS_PAYLOAD_GVARIANT = 0x4756617269616e74ULL, /* 'GVariant' */
247 * struct kdbus_msg - the representation of a kdbus message
248 * @size: Total size of the message
249 * @flags: Message flags (KDBUS_MSG_FLAGS_*)
250 * @dst_id: 64-bit ID of the destination connection
251 * @src_id: 64-bit ID of the source connection
252 * @payload_type: Payload type (KDBUS_PAYLOAD_*)
253 * @cookie: Userspace-supplied cookie
254 * @cookie_reply: For kernel-generated messages, this is the cookie
255 * the message is a reply to
256 * @timeout_ns: For non-kernel-generated messages, this denotes the
257 * message timeout in nanoseconds
258 * @items: A list of kdbus_items containing the message payload
271 struct kdbus_item items[0];
281 _KDBUS_POLICY_ACCESS_NULL,
282 KDBUS_POLICY_ACCESS_USER,
283 KDBUS_POLICY_ACCESS_GROUP,
284 KDBUS_POLICY_ACCESS_WORLD,
288 KDBUS_POLICY_RECV = 1 << 2,
289 KDBUS_POLICY_SEND = 1 << 1,
290 KDBUS_POLICY_OWN = 1 << 0,
294 * struct kdbus_policy_access - policy access item
295 * @type: One of KDBUS_POLICY_ACCESS_* types
296 * @bits: Access to grant. One of KDBUS_POLICY_*
297 * @id: For KDBUS_POLICY_ACCESS_USER, the uid
298 * For KDBUS_POLICY_ACCESS_GROUP, the gid
300 struct kdbus_policy_access {
301 __u64 type; /* USER, GROUP, WORLD */
302 __u64 bits; /* RECV, SEND, OWN */
303 __u64 id; /* uid, gid, 0 */
307 * struct kdbus_policy - a policy to upload
308 * @size: The total size of the structure
309 * @type: KDBUS_POLICY_NAME or KDBUS_POLICY_ACCESS
310 * @name: The well-known name to grant access to,
311 * if @type is KDBUS_POLICY_NAME
312 * @access: The policy access details,
313 * if @type is KDBUS_POLICY_ACCESS
315 struct kdbus_policy {
319 struct kdbus_policy_access access;
324 * struct kdbus_cmd_policy - a series of policies to upload
325 * @size: The total size of the structure
326 * @policies: The policies to upload
328 * A KDBUS_POLICY_NAME must always preceed a KDBUS_POLICY_ACCESS entry.
329 * A new KDBUS_POLICY_NAME can be added after KDBUS_POLICY_ACCESS for
330 * chaining multiple policies together.
332 struct kdbus_cmd_policy {
334 struct kdbus_policy policies[0];
337 /* Flags for struct kdbus_cmd_hello */
339 KDBUS_HELLO_STARTER = 1 << 0,
340 KDBUS_HELLO_ACCEPT_FD = 1 << 1,
343 /* Flags for message attachments */
345 KDBUS_ATTACH_TIMESTAMP = 1 << 0,
346 KDBUS_ATTACH_CREDS = 1 << 1,
347 KDBUS_ATTACH_NAMES = 1 << 2,
348 KDBUS_ATTACH_COMM = 1 << 3,
349 KDBUS_ATTACH_EXE = 1 << 4,
350 KDBUS_ATTACH_CMDLINE = 1 << 5,
351 KDBUS_ATTACH_CGROUP = 1 << 6,
352 KDBUS_ATTACH_CAPS = 1 << 7,
353 KDBUS_ATTACH_SECLABEL = 1 << 8,
354 KDBUS_ATTACH_AUDIT = 1 << 9,
358 * struct kdbus_cmd_hello - struct to say hello to kdbus
359 * @size: The total size of the structure
360 * @conn_flags: Connection flags (KDBUS_HELLO_*). The kernel will
361 * return its capabilities in that field.
362 * @attach_flags: Mask of metdata to attach to each message sent
364 * @bus_flags: The flags field copied verbatim from the original
365 * KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
366 * to do negotiation of features of the payload that is
367 * transferred (kernel → userspace)
368 * @id: The ID of this connection (kernel → userspace)
369 * @bloom_size: The bloom filter size chosen by the owner
370 * (kernel → userspace)
371 * @pool_size: Maximum size of the pool buffer (kernel → userspace)
372 * @id128: Unique 128-bit ID of the bus (kernel → userspace)
373 * @items; A list of items
375 * This struct is used with the KDBUS_CMD_HELLO ioctl. See the ioctl
376 * documentation for more information.
378 struct kdbus_cmd_hello {
381 /* userspace → kernel, kernel → userspace */
385 /* kernel → userspace */
392 struct kdbus_item items[0];
395 /* Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE */
397 KDBUS_MAKE_ACCESS_GROUP = 1 << 0,
398 KDBUS_MAKE_ACCESS_WORLD = 1 << 1,
399 KDBUS_MAKE_POLICY_OPEN = 1 << 2,
402 /* Items to append to KDBUS_CMD_{BUS,EP,NS}_MAKE */
406 KDBUS_MAKE_CRED,/* allow translator services which connect
407 * to the bus on behalf of somebody else,
408 * allow specifying the credentials of the
409 * client to connect on behalf on. Needs
414 * struct kdbus_cmd_bus_make - struct to make a bus
415 * @size: The total size of the struct
418 * @bloom_filter: Size of the bloom filter for this bus
419 * @items: Items describing details such as the name of the bus
421 * This structure is used with the KDBUS_CMD_BUS_MAKE ioctl. Refer to the
422 * documentation for more information.
424 struct kdbus_cmd_bus_make {
429 struct kdbus_item items[0];
433 * struct kdbus_cmd_ep_make - struct to make an endpoint
434 * @size: The total size of the struct
435 * @flags: Unused for now
436 * @items: Items describing details such as the
437 * name of the endpoint
439 * This structure is used with the KDBUS_CMD_EP_MAKE ioctl. Refer to the
440 * documentation for more information.
442 struct kdbus_cmd_ep_make {
445 struct kdbus_item items[0];
449 * struct kdbus_cmd_ns_make - struct to make a namespace
450 * @size: The total size of the struct
451 * @flags: Unused for now
452 * @items: Items describing details such as the
453 * name of the namespace
455 * This structure is used with the KDBUS_CMD_NS_MAKE ioctl. Refer to the
456 * documentation for more information.
458 struct kdbus_cmd_ns_make {
461 struct kdbus_item items[0];
465 /* userspace → kernel */
466 KDBUS_NAME_REPLACE_EXISTING = 1 << 0,
467 KDBUS_NAME_QUEUE = 1 << 1,
468 KDBUS_NAME_ALLOW_REPLACEMENT = 1 << 2,
470 /* kernel → userspace */
471 KDBUS_NAME_IN_QUEUE = 1 << 16,
475 * struct kdbus_cmd_name - struct to describe a well-known name
476 * @size: The total size of the struct
477 * @flags: Flags for a name entry (KDBUS_NAME_*)
478 * @id: Priviledged users may use this field to (de)register
479 * names on behalf of other peers.
480 * @conn_flags: The flags of the owning connection (KDBUS_HELLO_*)
481 * @name: The well-known name
483 * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
484 * Refer to the documentation for more information.
486 struct kdbus_cmd_name {
495 KDBUS_NAME_LIST_UNIQUE = 1 << 0,
496 KDBUS_NAME_LIST_NAMES = 1 << 1,
497 KDBUS_NAME_LIST_STARTERS = 1 << 2,
498 KDBUS_NAME_LIST_QUEUED = 1 << 3,
502 * struct kdbus_cmd_name_list - request a list of name entries
503 * @flags: Flags for the query (KDBUS_NAME_LIST_*)
504 * @offset: The returned offset in the caller's pool buffer.
505 * The user must use KDBUS_CMD_FREE to free the
508 * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
510 struct kdbus_cmd_name_list {
516 * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
517 * @size: The total size of the structure
518 * @names: A list of names
520 * Note that the user is responsible for freeing the allocated memory with
521 * the KDBUS_CMD_FREE ioctl.
523 struct kdbus_name_list {
525 struct kdbus_cmd_name names[0];
529 * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
530 * @size: The total size of the struct
531 * @flags: KDBUS_ATTACH_* flags
532 * @id: The 64-bit ID of the connection. If set to zero, passing
533 * @name is required. kdbus will look up the name to determine
534 * the ID in this case.
535 * @offset: Returned offset in the caller's pool buffer where the
536 * kdbus_name_info struct result is stored. The user must
537 * use KDBUS_CMD_FREE to free the allocated memory.
538 * @name: The optional well-known name to look up. Only needed in
541 * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
542 * tell the user the offset in the connection pool buffer at which to find the
543 * result in a struct kdbus_conn_info.
545 struct kdbus_cmd_conn_info {
554 * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
555 * @size: The total size of the struct
556 * @id: The connection's 64-bit ID
557 * @flags: The connection's flags
558 * @items: A list of struct kdbus_item
560 * Note that the user is responsible for freeing the allocated memory with
561 * the KDBUS_CMD_FREE ioctl.
563 struct kdbus_conn_info {
567 struct kdbus_item items[0];
572 KDBUS_MATCH_BLOOM, /* Matches a mask blob against KDBUS_MSG_BLOOM */
573 KDBUS_MATCH_SRC_NAME, /* Matches a name string against KDBUS_ITEM_NAME */
574 KDBUS_MATCH_NAME_ADD, /* Matches a name string against KDBUS_ITEM_NAME_ADD */
575 KDBUS_MATCH_NAME_REMOVE, /* Matches a name string against KDBUS_ITEM_NAME_REMOVE */
576 KDBUS_MATCH_NAME_CHANGE, /* Matches a name string against KDBUS_ITEM_NAME_CHANGE */
577 KDBUS_MATCH_ID_ADD, /* Matches an ID against KDBUS_MSG_ID_ADD */
578 KDBUS_MATCH_ID_REMOVE, /* Matches an ID against KDBUS_MSG_ID_REMOVE */
582 * struct kdbus_cmd_match - struct to add or remove matches
583 * @size: The total size of the struct
584 * @id: Priviledged users may (de)register matches on behalf
586 * In other cases, set to 0.
587 * @cookie: Userspace supplied cookie. When removing, the cookie is
588 * suffices as information
589 * @src_id: The source ID to match against. Use KDBUS_MATCH_SRC_ID_ANY or
590 * any other value for a unique match.
591 * @items: A list of items for additional information
593 * This structure is used with the KDBUS_CMD_ADD_MATCH and
594 * KDBUS_CMD_REMOVE_MATCH ioctl. Refer to the documentation for more
597 struct kdbus_cmd_match {
602 struct kdbus_item items[0];
606 KDBUS_MONITOR_ENABLE = 1 << 0,
610 * struct kdbus_cmd_monitor - struct to enable or disable eavesdropping
611 * @id: Priviledged users may enable or disable the monitor feature
612 * on behalf of other peers
613 * @flags: Use KDBUS_MONITOR_ENABLE to enable eavesdropping
615 * This structure is used with the KDBUS_CMD_MONITOR ioctl.
616 * Refer to the documentation for more information.
618 struct kdbus_cmd_monitor {
624 /* kdbus control node commands: require unset state */
625 KDBUS_CMD_BUS_MAKE = _IOW(KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_bus_make),
626 KDBUS_CMD_NS_MAKE = _IOR(KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_ns_make),
628 /* kdbus ep node commands: require unset state */
629 KDBUS_CMD_EP_MAKE = _IOW(KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_ep_make),
630 KDBUS_CMD_HELLO = _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_hello),
632 /* kdbus ep node commands: require connected state */
633 KDBUS_CMD_MSG_SEND = _IOW(KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
634 KDBUS_CMD_MSG_RECV = _IOR(KDBUS_IOC_MAGIC, 0x41, __u64 *),
635 KDBUS_CMD_FREE = _IOW(KDBUS_IOC_MAGIC, 0x42, __u64 *),
637 KDBUS_CMD_NAME_ACQUIRE = _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
638 KDBUS_CMD_NAME_RELEASE = _IOW(KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
639 KDBUS_CMD_NAME_LIST = _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_name_list),
641 KDBUS_CMD_CONN_INFO = _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_conn_info),
643 KDBUS_CMD_MATCH_ADD = _IOW(KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_match),
644 KDBUS_CMD_MATCH_REMOVE = _IOW(KDBUS_IOC_MAGIC, 0x71, struct kdbus_cmd_match),
645 KDBUS_CMD_MONITOR = _IOW(KDBUS_IOC_MAGIC, 0x72, struct kdbus_cmd_monitor),
647 /* kdbus ep node commands: require ep owner state */
648 KDBUS_CMD_EP_POLICY_SET = _IOW(KDBUS_IOC_MAGIC, 0x80, struct kdbus_cmd_policy),
650 /* kdbus memfd commands: */
651 KDBUS_CMD_MEMFD_NEW = _IOR(KDBUS_IOC_MAGIC, 0x90, int *),
652 KDBUS_CMD_MEMFD_SIZE_GET = _IOR(KDBUS_IOC_MAGIC, 0x91, __u64 *),
653 KDBUS_CMD_MEMFD_SIZE_SET = _IOW(KDBUS_IOC_MAGIC, 0x92, __u64 *),
654 KDBUS_CMD_MEMFD_SEAL_GET = _IOR(KDBUS_IOC_MAGIC, 0x93, int *),
655 KDBUS_CMD_MEMFD_SEAL_SET = _IO(KDBUS_IOC_MAGIC, 0x94),