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 - 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
149 /* Message Item Types */
153 /* Filled in by userspace */
154 _KDBUS_ITEM_USER_BASE = 1,
155 KDBUS_ITEM_PAYLOAD_VEC = 1, /* .data_vec, reference to memory area */
156 KDBUS_ITEM_PAYLOAD_OFF, /* .data_vec, reference to memory area */
157 KDBUS_ITEM_PAYLOAD_MEMFD, /* file descriptor of a special data file */
158 KDBUS_ITEM_FDS, /* .data_fds of file descriptors */
159 KDBUS_ITEM_BLOOM, /* for broadcasts, carries bloom filter blob in .data */
160 KDBUS_ITEM_DST_NAME, /* destination's well-known name, in .str */
161 KDBUS_ITEM_PRIORITY, /* queue priority for message */
163 /* Filled in by kernelspace */
164 _KDBUS_ITEM_ATTACH_BASE = 0x400,
165 KDBUS_ITEM_NAMES = 0x400,/* NUL separated string list with well-known names of source */
166 KDBUS_ITEM_STARTER_NAME, /* Only used in HELLO for starter connection */
167 KDBUS_ITEM_TIMESTAMP, /* .timestamp */
169 /* when appended to a message, the following items refer to the sender */
170 KDBUS_ITEM_CREDS, /* .creds */
171 KDBUS_ITEM_PID_COMM, /* optional, in .str */
172 KDBUS_ITEM_TID_COMM, /* optional, in .str */
173 KDBUS_ITEM_EXE, /* optional, in .str */
174 KDBUS_ITEM_CMDLINE, /* optional, in .str (a chain of NUL str) */
175 KDBUS_ITEM_CGROUP, /* optional, in .str */
176 KDBUS_ITEM_CAPS, /* caps data blob, in .data */
177 KDBUS_ITEM_SECLABEL, /* NUL terminated string, in .str */
178 KDBUS_ITEM_AUDIT, /* .audit */
180 /* Special messages from kernel, consisting of one and only one of these data blocks */
181 _KDBUS_ITEM_KERNEL_BASE = 0x800,
182 KDBUS_ITEM_NAME_ADD = 0x800,/* .name_change */
183 KDBUS_ITEM_NAME_REMOVE, /* .name_change */
184 KDBUS_ITEM_NAME_CHANGE, /* .name_change */
185 KDBUS_ITEM_ID_ADD, /* .id_change */
186 KDBUS_ITEM_ID_REMOVE, /* .id_change */
187 KDBUS_ITEM_REPLY_TIMEOUT, /* empty, but .reply_cookie in .kdbus_msg is filled in */
188 KDBUS_ITEM_REPLY_DEAD, /* dito */
192 * struct kdbus_item - chain of data blocks
193 * @size : overall data record size
194 * @type: kdbus_item type of data
209 struct kdbus_vec vec;
211 /* process credentials and properties*/
212 struct kdbus_creds creds;
213 struct kdbus_audit audit;
214 struct kdbus_timestamp timestamp;
216 /* specific fields */
217 struct kdbus_memfd memfd;
219 struct kdbus_notify_name_change name_change;
220 struct kdbus_notify_id_change id_change;
225 KDBUS_MSG_FLAGS_EXPECT_REPLY = 1 << 0,
226 KDBUS_MSG_FLAGS_NO_AUTO_START = 1 << 1,
230 KDBUS_PAYLOAD_KERNEL,
231 KDBUS_PAYLOAD_DBUS1 = 0x4442757356657231ULL, /* 'DBusVer1' */
232 KDBUS_PAYLOAD_GVARIANT = 0x4756617269616e74ULL, /* 'GVariant' */
236 * struct kdbus_msg - the representation of a kdbus message
237 * @size: Total size of the message
238 * @flags: Message flags (KDBUS_MSG_FLAGS_*)
239 * @dst_id: 64-bit ID of the destination connection
240 * @src_id: 64-bit ID of the source connection
241 * @payload_type: Payload type (KDBUS_PAYLOAD_*)
242 * @cookie: Userspace-supplied cookie
243 * @cookie_reply: For kernel-generated messages, this is the cookie
244 * the message is a reply to
245 * @timeout_ns: For non-kernel-generated messages, this denotes the
246 * message timeout in nanoseconds
247 * @items: A list of kdbus_items containing the message payload
260 struct kdbus_item items[0];
270 _KDBUS_POLICY_ACCESS_NULL,
271 KDBUS_POLICY_ACCESS_USER,
272 KDBUS_POLICY_ACCESS_GROUP,
273 KDBUS_POLICY_ACCESS_WORLD,
277 KDBUS_POLICY_RECV = 1 << 2,
278 KDBUS_POLICY_SEND = 1 << 1,
279 KDBUS_POLICY_OWN = 1 << 0,
283 * struct kdbus_policy_access - policy access item
284 * @type: One of KDBUS_POLICY_ACCESS_* types
285 * @bits: Access to grant. One of KDBUS_POLICY_*
286 * @id: For KDBUS_POLICY_ACCESS_USER, the uid
287 * For KDBUS_POLICY_ACCESS_GROUP, the gid
289 struct kdbus_policy_access {
290 __u64 type; /* USER, GROUP, WORLD */
291 __u64 bits; /* RECV, SEND, OWN */
292 __u64 id; /* uid, gid, 0 */
296 * struct kdbus_policy - a policy to upload
297 * @size: The total size of the structure
298 * @type: KDBUS_POLICY_NAME or KDBUS_POLICY_ACCESS
299 * @name: The well-known name to grant access to,
300 * if @type is KDBUS_POLICY_NAME
301 * @access: The policy access details,
302 * if @type is KDBUS_POLICY_ACCESS
304 struct kdbus_policy {
308 struct kdbus_policy_access access;
313 * struct kdbus_cmd_policy - a series of policies to upload
314 * @size: The total size of the structure
315 * @policies: The policies to upload
317 * A KDBUS_POLICY_NAME must always preceed a KDBUS_POLICY_ACCESS entry.
318 * A new KDBUS_POLICY_NAME can be added after KDBUS_POLICY_ACCESS for
319 * chaining multiple policies together.
321 struct kdbus_cmd_policy {
323 struct kdbus_policy policies[0];
326 /* Flags for struct kdbus_cmd_hello */
328 KDBUS_HELLO_STARTER = 1 << 0,
329 KDBUS_HELLO_ACCEPT_FD = 1 << 1,
332 /* Flags for message attachments */
334 KDBUS_ATTACH_TIMESTAMP = 1 << 0,
335 KDBUS_ATTACH_CREDS = 1 << 1,
336 KDBUS_ATTACH_NAMES = 1 << 2,
337 KDBUS_ATTACH_COMM = 1 << 3,
338 KDBUS_ATTACH_EXE = 1 << 4,
339 KDBUS_ATTACH_CMDLINE = 1 << 5,
340 KDBUS_ATTACH_CGROUP = 1 << 6,
341 KDBUS_ATTACH_CAPS = 1 << 7,
342 KDBUS_ATTACH_SECLABEL = 1 << 8,
343 KDBUS_ATTACH_AUDIT = 1 << 9,
347 * struct kdbus_cmd_hello - struct to say hello to kdbus
348 * @size: The total size of the structure
349 * @conn_flags: Connection flags (KDBUS_HELLO_*). The kernel will
350 * return its capabilities in that field.
351 * @attach_flags: Mask of metdata to attach to each message sent
353 * @bus_flags: The flags field copied verbatim from the original
354 * KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
355 * to do negotiation of features of the payload that is
356 * transferred (kernel → userspace)
357 * @id: The id of this connection (kernel → userspace)
358 * @bloom_size: The bloom filter size chosen by the owner
359 * (kernel → userspace)
360 * @pool_size: Maximum size of the pool buffer (kernel → userspace)
361 * @id128: Unique 128-bit ID of the bus (kernel → userspace)
362 * @items; A list of items
364 * This struct is used with the KDBUS_CMD_HELLO ioctl. See the ioctl
365 * documentation for more information.
367 struct kdbus_cmd_hello {
370 /* userspace → kernel, kernel → userspace */
374 /* kernel → userspace */
381 struct kdbus_item items[0];
384 /* Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE */
386 KDBUS_MAKE_ACCESS_GROUP = 1 << 0,
387 KDBUS_MAKE_ACCESS_WORLD = 1 << 1,
388 KDBUS_MAKE_POLICY_OPEN = 1 << 2,
391 /* Items to append to KDBUS_CMD_{BUS,EP,NS}_MAKE */
395 KDBUS_MAKE_CRED,/* allow translator services which connect
396 * to the bus on behalf of somebody else,
397 * allow specifying the credentials of the
398 * client to connect on behalf on. Needs
403 * struct kdbus_cmd_bus_make - struct to make a bus
404 * @size: The total size of the struct
407 * @bloom_filter: Size of the bloom filter for this bus
408 * @items: Items describing details such as the name of the bus
410 * This structure is used with the KDBUS_CMD_BUS_MAKE ioctl. Refer to the
411 * documentation for more information.
413 struct kdbus_cmd_bus_make {
418 struct kdbus_item items[0];
422 * struct kdbus_cmd_ep_make - struct to make an endpoint
423 * @size: The total size of the struct
424 * @flags: Unused for now
425 * @items: Items describing details such as the
426 * name of the endpoint
428 * This structure is used with the KDBUS_CMD_EP_MAKE ioctl. Refer to the
429 * documentation for more information.
431 struct kdbus_cmd_ep_make {
434 struct kdbus_item items[0];
438 * struct kdbus_cmd_ns_make - struct to make a namespace
439 * @size: The total size of the struct
440 * @flags: Unused for now
441 * @items: Items describing details such as the
442 * name of the namespace
444 * This structure is used with the KDBUS_CMD_NS_MAKE ioctl. Refer to the
445 * documentation for more information.
447 struct kdbus_cmd_ns_make {
450 struct kdbus_item items[0];
454 /* userspace → kernel */
455 KDBUS_NAME_REPLACE_EXISTING = 1 << 0,
456 KDBUS_NAME_QUEUE = 1 << 1,
457 KDBUS_NAME_ALLOW_REPLACEMENT = 1 << 2,
459 /* kernel → userspace */
460 KDBUS_NAME_IN_QUEUE = 1 << 16,
464 * struct kdbus_cmd_name - struct to describe a well-known name
465 * @size: The total size of the struct
466 * @flags: Flags for a name entry (KDBUS_NAME_*)
467 * @id: Priviledged users may use this field to (de)register
468 * names on behalf of other peers.
469 * @conn_flags: The flags of the owning connection (KDBUS_HELLO_*)
470 * @name: The well-known name
472 * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
473 * Refer to the documentation for more information.
475 struct kdbus_cmd_name {
484 KDBUS_NAME_LIST_UNIQUE = 1 << 0,
485 KDBUS_NAME_LIST_NAMES = 1 << 1,
486 KDBUS_NAME_LIST_STARTERS = 1 << 2,
487 KDBUS_NAME_LIST_QUEUED = 1 << 3,
491 * struct kdbus_cmd_name_list - request a list of name entries
492 * @flags: Flags for the query (KDBUS_NAME_LIST_*)
493 * @offset: The returned offset in the caller's pool buffer.
494 * The user must use KDBUS_CMD_FREE to free the
497 * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
499 struct kdbus_cmd_name_list {
505 * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
506 * @size: The total size of the structure
507 * @names: A list of names
509 * Note that the user is responsible for freeing the allocated memory with
510 * the KDBUS_CMD_FREE ioctl.
512 struct kdbus_name_list {
514 struct kdbus_cmd_name names[0];
518 * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
519 * @size: The total size of the struct
520 * @flags: KDBUS_ATTACH_* flags
521 * @id: The 64-bit ID of the connection. If set to zero, passing
522 * @name is required. kdbus will look up the name to determine
523 * the ID in this case.
524 * @offset: Returned offset in the caller's pool buffer where the
525 * kdbus_name_info struct result is stored. The user must
526 * use KDBUS_CMD_FREE to free the allocated memory.
527 * @name: The optional well-known name to look up. Only needed in
530 * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
531 * tell the user the offset in the connection pool buffer at which to find the
532 * result in a struct kdbus_conn_info.
534 struct kdbus_cmd_conn_info {
543 * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
544 * @size: The total size of the struct
545 * @id: The connection's 64-bit ID
546 * @flags: The connection's flags
547 * @items: A list of struct kdbus_item
549 * Note that the user is responsible for freeing the allocated memory with
550 * the KDBUS_CMD_FREE ioctl.
552 struct kdbus_conn_info {
556 struct kdbus_item items[0];
561 KDBUS_MATCH_BLOOM, /* Matches a mask blob against KDBUS_MSG_BLOOM */
562 KDBUS_MATCH_SRC_NAME, /* Matches a name string against KDBUS_MSG_SRC_NAMES */
563 KDBUS_MATCH_NAME_ADD, /* Matches a name string against KDBUS_MSG_NAME_ADD */
564 KDBUS_MATCH_NAME_REMOVE, /* Matches a name string against KDBUS_MSG_NAME_REMOVE */
565 KDBUS_MATCH_NAME_CHANGE, /* Matches a name string against KDBUS_MSG_NAME_CHANGE */
566 KDBUS_MATCH_ID_ADD, /* Matches an ID against KDBUS_MSG_ID_ADD */
567 KDBUS_MATCH_ID_REMOVE, /* Matches an ID against KDBUS_MSG_ID_REMOVE */
571 * struct kdbus_cmd_match - struct to add or remove matches
572 * @size: The total size of the struct
573 * @id: Priviledged users may (de)register matches on behalf
575 * In other cases, set to 0.
576 * @cookie: Userspace supplied cookie. When removing, the cookie is
577 * suffices as information
578 * @src_id: The source ID to match against. Use KDBUS_MATCH_SRC_ID_ANY or
579 * any other value for a unique match.
580 * @items: A list of items for additional information
582 * This structure is used with the KDBUS_CMD_ADD_MATCH and
583 * KDBUS_CMD_REMOVE_MATCH ioctl. Refer to the documentation for more
586 struct kdbus_cmd_match {
591 struct kdbus_item items[0];
595 KDBUS_MONITOR_ENABLE = 1 << 0,
599 * struct kdbus_cmd_monitor - struct to enable or disable eavesdropping
600 * @id: Priviledged users may enable or disable the monitor feature
601 * on behalf of other peers
602 * @flags: Use KDBUS_MONITOR_ENABLE to enable eavesdropping
604 * This structure is used with the KDBUS_CMD_MONITOR ioctl.
605 * Refer to the documentation for more information.
607 struct kdbus_cmd_monitor {
613 /* kdbus control node commands: require unset state */
614 KDBUS_CMD_BUS_MAKE = _IOW(KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_bus_make),
615 KDBUS_CMD_NS_MAKE = _IOR(KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_ns_make),
617 /* kdbus ep node commands: require unset state */
618 KDBUS_CMD_EP_MAKE = _IOW(KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_ep_make),
619 KDBUS_CMD_HELLO = _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_hello),
621 /* kdbus ep node commands: require connected state */
622 KDBUS_CMD_MSG_SEND = _IOW(KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
623 KDBUS_CMD_MSG_RECV = _IOR(KDBUS_IOC_MAGIC, 0x41, __u64 *),
624 KDBUS_CMD_FREE = _IOW(KDBUS_IOC_MAGIC, 0x42, __u64 *),
626 KDBUS_CMD_NAME_ACQUIRE = _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
627 KDBUS_CMD_NAME_RELEASE = _IOW(KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
628 KDBUS_CMD_NAME_LIST = _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_name_list),
630 KDBUS_CMD_CONN_INFO = _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_conn_info),
632 KDBUS_CMD_MATCH_ADD = _IOW(KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_match),
633 KDBUS_CMD_MATCH_REMOVE = _IOW(KDBUS_IOC_MAGIC, 0x71, struct kdbus_cmd_match),
634 KDBUS_CMD_MONITOR = _IOW(KDBUS_IOC_MAGIC, 0x72, struct kdbus_cmd_monitor),
636 /* kdbus ep node commands: require ep owner state */
637 KDBUS_CMD_EP_POLICY_SET = _IOW(KDBUS_IOC_MAGIC, 0x80, struct kdbus_cmd_policy),
639 /* kdbus memfd commands: */
640 KDBUS_CMD_MEMFD_NEW = _IOR(KDBUS_IOC_MAGIC, 0x90, int *),
641 KDBUS_CMD_MEMFD_SIZE_GET = _IOR(KDBUS_IOC_MAGIC, 0x91, __u64 *),
642 KDBUS_CMD_MEMFD_SIZE_SET = _IOW(KDBUS_IOC_MAGIC, 0x92, __u64 *),
643 KDBUS_CMD_MEMFD_SEAL_GET = _IOR(KDBUS_IOC_MAGIC, 0x93, int *),
644 KDBUS_CMD_MEMFD_SEAL_SET = _IO(KDBUS_IOC_MAGIC, 0x94),