*d = (struct kdbus_item *) ((uint8_t*) *d + (*d)->size);
}
-static void append_payload_memfd(struct kdbus_item **d, int memfd, size_t sz) {
+static void append_payload_memfd(struct kdbus_item **d, int memfd, size_t start, size_t sz) {
assert(d);
assert(memfd >= 0);
assert(sz > 0);
(*d)->size = offsetof(struct kdbus_item, memfd) + sizeof(struct kdbus_memfd);
(*d)->type = KDBUS_ITEM_PAYLOAD_MEMFD;
(*d)->memfd.fd = memfd;
+ (*d)->memfd.start = start;
(*d)->memfd.size = sz;
*d = (struct kdbus_item *) ((uint8_t*) *d + (*d)->size);
sz = offsetof(struct kdbus_msg, items);
- assert_cc(ALIGN8(offsetof(struct kdbus_item, vec) + sizeof(struct kdbus_vec)) ==
- ALIGN8(offsetof(struct kdbus_item, memfd) + sizeof(struct kdbus_memfd)));
-
/* Add in fixed header, fields header and payload */
- sz += (1 + m->n_body_parts) *
- ALIGN8(offsetof(struct kdbus_item, vec) + sizeof(struct kdbus_vec));
+ sz += (1 + m->n_body_parts) * ALIGN8(offsetof(struct kdbus_item, vec) +
+ MAX(sizeof(struct kdbus_vec),
+ sizeof(struct kdbus_memfd)));
/* Add space for bloom filter */
sz += ALIGN8(offsetof(struct kdbus_item, bloom_filter) +
/* Try to send a memfd, if the part is
* sealed and this is not a broadcast. Since we can only */
- append_payload_memfd(&d, part->memfd, part->size);
+ append_payload_memfd(&d, part->memfd, part->memfd_offset, part->size);
continue;
}
}
part->memfd = d->memfd.fd;
+ part->memfd_offset = d->memfd.start;
part->size = d->memfd.size;
part->sealed = true;
psz = PAGE_ALIGN(sz > 0 ? sz : 1);
if (part->mapped <= 0)
- n = mmap(NULL, psz, PROT_READ|PROT_WRITE, MAP_SHARED, part->memfd, 0);
+ n = mmap(NULL, psz, PROT_READ|PROT_WRITE, MAP_SHARED, part->memfd, part->memfd_offset);
else
n = mremap(part->data, part->mapped, psz, MREMAP_MAYMOVE);
return -ENOMEM;
part->memfd = copy_fd;
+ part->memfd_offset = 0;
part->sealed = true;
part->size = size;
copy_fd = -1;
return -ENOMEM;
part->memfd = copy_fd;
+ part->memfd_offset = 0;
part->sealed = true;
part->size = size;
copy_fd = -1;
psz = PAGE_ALIGN(part->size);
if (part->memfd >= 0)
- p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE, part->memfd, 0);
+ p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE, part->memfd, part->memfd_offset);
else if (part->is_zero)
p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
else
size_t size;
size_t mapped;
size_t allocated;
+ size_t memfd_offset;
int memfd;
bool free_this:1;
bool munmap_this:1;
/**
* struct kdbus_memfd - a kdbus memfd
- * @size: The memfd's size
+ * @start: The offset into the memfd where the segment starts
+ * @size: The size of the memfd segment
* @fd: The file descriptor number
* @__pad: Padding to ensure proper alignment and size
*
* KDBUS_ITEM_PAYLOAD_MEMFD
*/
struct kdbus_memfd {
+ __u64 start;
__u64 size;
int fd;
__u32 __pad;
* a service
* @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor
* bus traffic
+ * @KDBUS_HELLO_UNPRIVILEGED: Don't treat this connection as privileged once
+ * the bus connection was established.
*/
enum kdbus_hello_flags {
KDBUS_HELLO_ACCEPT_FD = 1ULL << 0,
KDBUS_HELLO_ACTIVATOR = 1ULL << 1,
KDBUS_HELLO_POLICY_HOLDER = 1ULL << 2,
KDBUS_HELLO_MONITOR = 1ULL << 3,
+ KDBUS_HELLO_UNPRIVILEGED = 1ULL << 4,
};
/**