kdbus_kvec_set(&kvec[cnt++], kdbus_meta_payload_ptr(pay), KDBUS_ALIGN8(pay_size));
size = KDBUS_ALIGN8(size) + pay_size;
}
- cnt += kdbus_meta_emit_kvecs(&kvec[cnt], bus->meta_items, attach_flags & KDBUS_ATTACH_MASK_PROC_DST_AGNOSTIC, &size);
+ cnt += kdbus_meta_emit(kdbus_wrap_kvec(&kvec[cnt]), bus->meta_items, attach_flags & KDBUS_ATTACH_MASK_PROC_DST_AGNOSTIC, &size, 0);
header.info.size = size;
size = KDBUS_ALIGN8(size);
size = KDBUS_ALIGN8(size) + pay_size;
}
- cnt += kdbus_meta_emit_kvecs(&kvec[cnt], meta_items, attach_flags & (KDBUS_ATTACH_MASK_PROC_DST_AGNOSTIC|KDBUS_ATTACH_CONN_DESCRIPTION), &size);
+ cnt += kdbus_meta_emit(kdbus_wrap_kvec(&kvec[cnt]), meta_items, attach_flags & (KDBUS_ATTACH_MASK_PROC_DST_AGNOSTIC|KDBUS_ATTACH_CONN_DESCRIPTION), &size, 0);
kdbus_assert(cnt <= sizeof(kvec)/sizeof(kvec[0]));
info.size = size;
size = KDBUS_ALIGN8(size);
var(dst_id, msg->dst_id);
struct kdbus_item *item, *negotiation = NULL;
var(staging, (struct kdbus_staging_user *__restrict__)((uintptr_t)msg - offsetof(struct kdbus_staging_user, msg)));
- struct iovec *parts = kdbus_parts_of_staging_user(staging);
+ struct kvec *parts = kdbus_parts_of_staging_user(staging);
var(scratch, (struct kdbus_msg_parse_scratch *__restrict__)((uintptr_t)staging + scratch_offset));
ulong items_size;
ulong bloom_filter_off, iov_1_len, iov_2_off = 0, active_iov_len = offsetof(typeof(*msg), items);
/* real offset is patched later on if not NUL padding */
if ((ptr = (void __user *)KDBUS_PTR(item->vec.address))) {
- struct iovec *vec;
+ struct kvec *vec;
if (unlikely(!access_ok(VERIFY_READ, ptr, size)))
return -EFAULT;
vec = &parts[n_parts++];
u64 msg_size;
struct kdbus_item *item;
struct kdbus_pool_slice *slice;
- struct iovec *parts;
+ struct kvec *parts;
struct kdbus_staging_user *__restrict__ staging = *pstaging;
- ulong size, n_fds, cnt = 0;
+ ulong size, n_fds, cnt = 0, size_before_payload = 0;
int ret;
ulong attach = kdbus_meta_msg_mask(src, dst) & (
src->have_meta_fake
BUILD_BUG_ON(sizeof(msg_size) != sizeof(staging->msg->size));
size = staging->emit_size;
- parts[0].iov_base = (void __user *)&msg_size;
- parts[1].iov_base = (void __user *)((uintptr_t)staging->msg + sizeof(msg_size));
+ parts[0].iov_base = &msg_size;
+ parts[1].iov_base = (void *)((uintptr_t)staging->msg + sizeof(msg_size));
parts[1].iov_len = staging->iov_1_len;
- parts[2].iov_base = (void __user *)((uintptr_t)staging + staging->iov_2_off);
+ parts[2].iov_base = (void *)((uintptr_t)staging + staging->iov_2_off);
parts[2].iov_len = staging->iov_2_len;
if (attach & KDBUS_ATTACH_TIMESTAMP) { /* timestamp stored after msg proper */
cnt = 3;
/* metadata items */
- cnt += kdbus_meta_emit_stack_iovec(&staging->meta, dst, &parts[cnt], &meta_stack, attach, &size);
- cnt += kdbus_meta_emit_iovecs(&parts[cnt], kdbus_meta_payload_ptr(kdbus_meta_payload_of_staging_user(staging)), attach & (KDBUS_ATTACH_MASK_PROC_DST_AGNOSTIC|KDBUS_ATTACH_AUXGROUPS|KDBUS_ATTACH_NAMES), &size, staging->total_meta_name_size);
+ cnt += kdbus_meta_emit_stack_kvec(&staging->meta, dst, &parts[cnt], &meta_stack, attach, &size);
+ cnt += kdbus_meta_emit(kdbus_wrap_kvec(&parts[cnt]), kdbus_meta_payload_ptr(kdbus_meta_payload_of_staging_user(staging)), attach & (KDBUS_ATTACH_MASK_PROC_DST_AGNOSTIC|KDBUS_ATTACH_AUXGROUPS|KDBUS_ATTACH_NAMES), &size, staging->total_meta_name_size);
if (attach & KDBUS_ATTACH_CONN_DESCRIPTION && (item = src->description)) {
ulong item_size = item->size;
parts[cnt].iov_base = item;
kdbus_assert(kdbus_pool_slice_size(slice) == size);
- ret = kdbus_pool_slice_copy_iovec(&dst->pool, slice, parts,
- staging->n_parts, size);
- if (ret >= 0) /* all done, return slice to caller */
+ {
+ ulong count_parts;
+ for (count_parts = 0; count_parts < N_RESERVED_STAGING_USER_PARTS_BEFORE_PAYLOAD; count_parts++)
+ size_before_payload += parts[count_parts].iov_len;
+ }
+
+ ret = kdbus_pool_slice_copy_kvec(&dst->pool, slice, 0, parts,
+ N_RESERVED_STAGING_USER_PARTS_BEFORE_PAYLOAD, size_before_payload);
+ if (ret < 0)
+ goto error_copy;
+
+ {
+ ulong count_parts;
+ for (count_parts = N_RESERVED_STAGING_USER_PARTS_BEFORE_PAYLOAD; count_parts < staging->n_parts; count_parts++) {
+ if (parts[count_parts].iov_base != zeros)
+ ret = kdbus_pool_slice_copy_iovec(&dst->pool, slice, size_before_payload, (struct iovec *)&parts[count_parts],
+ 1, parts[count_parts].iov_len);
+ else
+ ret = kdbus_pool_slice_copy_kvec(&dst->pool, slice, size_before_payload, &parts[count_parts],
+ 1, parts[count_parts].iov_len);
+ if (ret < 0)
+ goto error_copy;
+ size_before_payload += parts[count_parts].iov_len;
+ }
goto exit;
+ }
+error_copy:
kdbus_pool_slice_release(&dst->pool, slice);
error_quota:
kdbus_conn_quota_dec(dst, src->user, size, n_fds);
{
struct kdbus_pool_slice *slice = NULL;
ulong size = KDBUS_ALIGN8(staging->msg->size);
- struct iovec iov;
+ struct kvec iov;
int ret;
iov.iov_base = staging->msg;
kdbus_assert(kdbus_pool_slice_size(slice) == size);
- if (0 <= (ret = kdbus_pool_slice_copy_iovec(&dst->pool, slice, &iov, 1, size))) /* all done, return slice to caller */
+ if (0 <= (ret = kdbus_pool_slice_copy_kvec(&dst->pool, slice, 0, &iov, 1, size))) /* all done, return slice to caller */
goto exit;
kdbus_pool_slice_release(&dst->pool, slice);
struct kdbus_msg msg[0];
};
-/* timestamp item is stored directly after message proper, iovecs directly after timestamp */
+/* timestamp item is stored directly after message proper, kvecs directly after timestamp */
static inline wur struct kdbus_item *kdbus_timestamp_of_staging_user(struct kdbus_staging_user *staging) {
return (struct kdbus_item *)(KDBUS_ALIGN8((uintptr_t)staging->msg + (ulong)staging->msg->size));
}
-static inline wur struct iovec *kdbus_parts_of_staging_user(struct kdbus_staging_user *staging) {
- return (struct iovec *)((uintptr_t)kdbus_timestamp_of_staging_user(staging) + KDBUS_ITEM_SIZE(sizeof(struct kdbus_timestamp)));
+static inline wur struct kvec *kdbus_parts_of_staging_user(struct kdbus_staging_user *staging) {
+ return (struct kvec *)((uintptr_t)kdbus_timestamp_of_staging_user(staging) + KDBUS_ITEM_SIZE(sizeof(struct kdbus_timestamp)));
}
static inline wur struct kdbus_meta_payload *kdbus_meta_payload_of_staging_user(struct kdbus_staging_user *staging) {
ulong item_size;
if (owner->flags & KDBUS_NAME_IN_QUEUE)
continue;
+
len = strlen(name = owner->name->name);
item_size = KDBUS_ITEM_HEADER_SIZE + sizeof(struct kdbus_name) + len+1;
if (unlikely((missing_space += KDBUS_ALIGN8(item_size)) > 0)) {
return total_size;
}
-ulong _kdbus_meta_emit_(struct k_or_io_vec vec, struct kdbus_item *__restrict__ meta_item, ulong what, ulong *__restrict__ size, ulong total_meta_name_size)
+ulong kdbus_meta_emit(struct k_or_io_vec vec, struct kdbus_item *__restrict__ meta_item, ulong what, ulong *__restrict__ size, ulong total_meta_name_size)
{
ulong cnt = 0;
struct kdbus_item *__restrict__ item = NULL;
wur int kdbus_meta_proc_collect(struct kdbus_meta_payload *__restrict__ *__restrict__ pptr, ulong what);
wur int kdbus_meta_fake_collect(struct kdbus_meta_payload *__restrict__ *__restrict__ pptr, const char *__restrict__ seclabel);
-wur ulong _kdbus_meta_emit_(struct k_or_io_vec vec, struct kdbus_item *meta_item, ulong what, ulong *size, ulong total_meta_name_size);
-
-static inline wur ulong kdbus_meta_emit_kvecs(struct kvec *vec, struct kdbus_item *meta_item, ulong what, ulong *size) {
- return _kdbus_meta_emit_(kdbus_wrap_kvec(vec), meta_item, what, size, 0);
-}
-static inline wur ulong kdbus_meta_emit_iovecs(struct iovec *vec, struct kdbus_item *meta_item, ulong what, ulong *size, ulong total_meta_name_size) {
- return _kdbus_meta_emit_(kdbus_wrap_iovec(vec), meta_item, what, size, total_meta_name_size);
-}
+wur ulong kdbus_meta_emit(struct k_or_io_vec vec, struct kdbus_item *meta_item, ulong what, ulong *size, ulong total_meta_name_size);
wur int kdbus_meta_payload_collect_names(struct kdbus_meta_payload *__restrict__ *__restrict__ pptr, struct kdbus_conn const *__restrict__ owner_conn);
static ulong kdbus_strnhash(const char *str, ulong len)
{
- ulong hash = init_name_hash(str);
+ ulong hash = init_name_hash(0);
while (len--)
hash = partial_name_hash(*str++, hash);
*/
int
kdbus_pool_slice_copy_iovec(struct kdbus_pool *pool, const struct kdbus_pool_slice *slice,
- struct iovec *iov, ulong iov_len, ulong total_len)
+ ulong off, struct iovec *iov, ulong iov_len, ulong total_len)
{
struct iov_iter iter;
int len;
kdbus_assert(total_len <= slice->size);
iov_iter_init(&iter, WRITE, iov, iov_len, total_len);
+
+ off += slice->off;
{
- loff_t off_ = slice->off;
+ loff_t off_ = off;
len = vfs_iter_write(pool->f, &iter, &off_, 0);
}
}
kaddr = (char __force __user *)kmap(page) + page_off;
- n_read = __vfs_read(f_src, kaddr, copy_len, &off_src);
+ n_read = kernel_read(f_src, kaddr, copy_len, &off_src);
kunmap(page);
mark_page_accessed(page);
flush_dcache_page(page);
ulong off, struct kvec *kvec,
ulong kvec_count, ulong total_len);
wur int kdbus_pool_slice_copy_iovec(struct kdbus_pool *pool, const struct kdbus_pool_slice *slice,
- struct iovec *iov, ulong iov_count, ulong total_len);
+ ulong off, struct iovec *iov, ulong iov_count, ulong total_len);
#endif
*/
static inline wur ulong kdbus_strhash(const char *str)
{
- ulong hash = init_name_hash(str);
+ ulong hash = init_name_hash(0);
while (*str)
hash = partial_name_hash(*str++, hash);
Summary: Kdbus tests
License: Apache-2.0
Group: Base/IPC
-Version: 0.0.1
+Version: 4.14.99
Release: 0
Source: %{name}-%{version}.tar.gz
-Source1001: packaging/%{name}.manifest
-BuildRequires: libcap-devel
+Source1001: %{name}.manifest
+BuildRequires: libcap-devel rsync
%define _test_runner_dir /usr/lib/dbus-tests/runner
%prep
%setup -q
+cp %{SOURCE1001} .
%build
make -C tools/testing/selftests/kdbus
%files
%defattr(-,root,root)
%{_test_runner_dir}/kdbus-test
-%manifest packaging/%{name}.manifest
+%manifest %{name}.manifest
-CFLAGS += -I../../../../usr/include/
CFLAGS += -I../../../../samples/kdbus/
-CFLAGS += -I../../../../include/uapi/
+#CFLAGS += -I../../../../include/uapi/
+CFLAGS += -I../../../../usr/include/
CFLAGS += -std=c11 -Wall -Wextra -Wno-maybe-uninitialized -Wno-missing-field-initializers
CFLAGS += -DKBUILD_MODNAME=\"kdbus\" -D_GNU_SOURCE
LDLIBS = -pthread -lcap -lm
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
-#include <stddef.h>
#include <unistd.h>
#include <stdint.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <linux/unistd.h>
-#include <linux/memfd.h>
#ifndef __NR_memfd_create
#ifdef __x86_64__
{
int ret, fd;
- fd = syscall(__NR_memfd_create, name, MFD_ALLOW_SEALING);
+ fd = syscall(__NR_memfd_create, name, 2/*MFD_ALLOW_SEALING*/);
if (fd < 0)
return fd;