diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2015-06-24 15:29:53 +0200 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2015-07-06 18:14:37 +0200 |
commit | 149fd9e2deb3fc394cf37f6f848ccb1ea34358d2 (patch) | |
tree | 3dcc7c0b7e5c7a2c72b5f2c2f2766a041c366567 /ipc | |
parent | c7bd78731b3a709a6d7d83f4851e30dc1ebf5cca (diff) |
kdbus: drop unused metadata code
Now that we switched to the new kdbus_staging infrastructure, the old
RECV-time metadata helpers are no longer needed. Drop them.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/kdbus/metadata.c | 371 | ||||
-rw-r--r-- | ipc/kdbus/metadata.h | 11 |
2 files changed, 0 insertions, 382 deletions
diff --git a/ipc/kdbus/metadata.c b/ipc/kdbus/metadata.c index 70ce5d15fc98..43e5f4564925 100644 --- a/ipc/kdbus/metadata.c +++ b/ipc/kdbus/metadata.c @@ -714,138 +714,6 @@ exit_unlock: return ret; } -/* - * kdbus_meta_export_prepare() - Prepare metadata for export - * @mp: Process metadata, or NULL - * @mf: Fake metadata, or NULL - * @mc: Connection metadata, or NULL - * @mask: Pointer to mask of KDBUS_ATTACH_* flags to export - * @sz: Pointer to return the size needed by the metadata - * - * Does a conservative calculation of how much space metadata information - * will take up during export. It is 'conservative' because for string - * translations in namespaces, it will use the kernel namespaces, which is - * the longest possible version. - * - * The actual size consumed by kdbus_meta_export() may hence vary from the - * one reported here, but it is guaranteed never to be greater. - * - * Return: 0 on success, negative error number otherwise. - */ -int kdbus_meta_export_prepare(struct kdbus_meta_proc *mp, - struct kdbus_meta_fake *mf, - struct kdbus_meta_conn *mc, - u64 *mask, size_t *sz) -{ - char *exe_pathname = NULL; - void *exe_page = NULL; - size_t size = 0; - u64 valid = 0; - int ret = 0; - - if (WARN_ON(mf && mp)) - mp = NULL; - - if (mf) - valid |= mf->valid; - - if (mp) { - mutex_lock(&mp->lock); - valid |= mp->valid; - mutex_unlock(&mp->lock); - } - - if (mc) { - mutex_lock(&mc->lock); - valid |= mc->valid; - mutex_unlock(&mc->lock); - } - - *mask &= valid; - - if (!*mask) - goto exit; - - /* process metadata */ - - if ((mp || mf) && (*mask & KDBUS_ATTACH_CREDS)) - size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_creds)); - - if ((mp || mf) && (*mask & KDBUS_ATTACH_PIDS)) - size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_pids)); - - if (mp && (*mask & KDBUS_ATTACH_AUXGROUPS)) - size += KDBUS_ITEM_SIZE(mp->cred->group_info->ngroups * - sizeof(u64)); - - if (mp && (*mask & KDBUS_ATTACH_TID_COMM)) - size += KDBUS_ITEM_SIZE(strlen(mp->tid_comm) + 1); - - if (mp && (*mask & KDBUS_ATTACH_PID_COMM)) - size += KDBUS_ITEM_SIZE(strlen(mp->pid_comm) + 1); - - if (mp && (*mask & KDBUS_ATTACH_EXE)) { - exe_page = (void *)__get_free_page(GFP_TEMPORARY); - if (!exe_page) { - ret = -ENOMEM; - goto exit; - } - - exe_pathname = d_path(&mp->exe_path, exe_page, PAGE_SIZE); - if (IS_ERR(exe_pathname)) { - ret = PTR_ERR(exe_pathname); - goto exit; - } - - size += KDBUS_ITEM_SIZE(strlen(exe_pathname) + 1); - free_page((unsigned long)exe_page); - } - - if (mp && (*mask & KDBUS_ATTACH_CMDLINE)) - size += KDBUS_ITEM_SIZE(strlen(mp->cmdline) + 1); - - if (mp && (*mask & KDBUS_ATTACH_CGROUP)) - size += KDBUS_ITEM_SIZE(strlen(mp->cgroup) + 1); - - if (mp && (*mask & KDBUS_ATTACH_CAPS)) - size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_meta_caps)); - - if ((mp || mf) && (*mask & KDBUS_ATTACH_SECLABEL)) - size += KDBUS_ITEM_SIZE(strlen(mp ? mp->seclabel - : mf->seclabel) + 1); - - if (mp && (*mask & KDBUS_ATTACH_AUDIT)) - size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_audit)); - - /* connection metadata */ - - if (mc && (*mask & KDBUS_ATTACH_NAMES)) - size += KDBUS_ALIGN8(mc->owned_names_size); - - if (mc && (*mask & KDBUS_ATTACH_CONN_DESCRIPTION)) - size += KDBUS_ITEM_SIZE(strlen(mc->conn_description) + 1); - - if (mc && (*mask & KDBUS_ATTACH_TIMESTAMP)) - size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_timestamp)); - -exit: - *sz = size; - - return ret; -} - -static int kdbus_meta_push_kvec(struct kvec *kvec, - struct kdbus_item_header *hdr, - u64 type, void *payload, - size_t payload_size, u64 *size) -{ - hdr->type = type; - hdr->size = KDBUS_ITEM_HEADER_SIZE + payload_size; - kdbus_kvec_set(kvec++, hdr, sizeof(*hdr), size); - kdbus_kvec_set(kvec++, payload, payload_size, size); - return 2 + !!kdbus_kvec_pad(kvec++, size); -} - static void kdbus_meta_export_caps(struct kdbus_meta_caps *out, const struct kdbus_meta_proc *mp, struct user_namespace *user_ns) @@ -922,245 +790,6 @@ static gid_t kdbus_from_kgid_keep(struct user_namespace *ns, kgid_t gid) return gid_valid(gid) ? from_kgid_munged(ns, gid) : ((gid_t)-1); } -/** - * kdbus_meta_export() - export information from metadata into a slice - * @mp: Process metadata, or NULL - * @mf: Fake metadata, or NULL - * @mc: Connection metadata, or NULL - * @conn: Target connection to translate metadata into - * @mask: Mask of KDBUS_ATTACH_* flags to export - * @slice: The slice to export to - * @offset: The offset inside @slice to write to - * @real_size: The real size the metadata consumed - * - * This function exports information from metadata into @slice at offset - * @offset inside that slice. Only information that is requested in @mask - * and that has been collected before is exported. - * - * In order to make sure not to write out of bounds, @mask must be the same - * value that was previously returned from kdbus_meta_export_prepare(). The - * function will, however, not necessarily write as many bytes as returned by - * kdbus_meta_export_prepare(); depending on the namespaces in question, it - * might use up less than that. - * - * All information will be translated using the namespaces of @conn. - * - * Return: 0 on success, negative error number otherwise. - */ -int kdbus_meta_export(struct kdbus_meta_proc *mp, - struct kdbus_meta_fake *mf, - struct kdbus_meta_conn *mc, - struct kdbus_conn *conn, - u64 mask, - struct kdbus_pool_slice *slice, - off_t offset, - size_t *real_size) -{ - struct user_namespace *user_ns = conn->user_ns; - struct kdbus_item_header item_hdr[13], *hdr; - char *exe_pathname = NULL; - struct kdbus_creds creds; - struct kdbus_pids pids; - void *exe_page = NULL; - struct kvec kvec[40]; - u64 *auxgrps = NULL; - size_t cnt = 0; - u64 size = 0; - int ret = 0; - - if (WARN_ON(mf && mp)) - mp = NULL; - - hdr = &item_hdr[0]; - - if (mask == 0) { - *real_size = 0; - return 0; - } - - /* process metadata */ - - if (mf && (mask & KDBUS_ATTACH_CREDS)) { - creds.uid = kdbus_from_kuid_keep(user_ns, mf->uid); - creds.euid = kdbus_from_kuid_keep(user_ns, mf->euid); - creds.suid = kdbus_from_kuid_keep(user_ns, mf->suid); - creds.fsuid = kdbus_from_kuid_keep(user_ns, mf->fsuid); - creds.gid = kdbus_from_kgid_keep(user_ns, mf->gid); - creds.egid = kdbus_from_kgid_keep(user_ns, mf->egid); - creds.sgid = kdbus_from_kgid_keep(user_ns, mf->sgid); - creds.fsgid = kdbus_from_kgid_keep(user_ns, mf->fsgid); - - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, KDBUS_ITEM_CREDS, - &creds, sizeof(creds), &size); - } else if (mp && (mask & KDBUS_ATTACH_CREDS)) { - const struct cred *c = mp->cred; - - creds.uid = kdbus_from_kuid_keep(user_ns, c->uid); - creds.euid = kdbus_from_kuid_keep(user_ns, c->euid); - creds.suid = kdbus_from_kuid_keep(user_ns, c->suid); - creds.fsuid = kdbus_from_kuid_keep(user_ns, c->fsuid); - creds.gid = kdbus_from_kgid_keep(user_ns, c->gid); - creds.egid = kdbus_from_kgid_keep(user_ns, c->egid); - creds.sgid = kdbus_from_kgid_keep(user_ns, c->sgid); - creds.fsgid = kdbus_from_kgid_keep(user_ns, c->fsgid); - - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, KDBUS_ITEM_CREDS, - &creds, sizeof(creds), &size); - } - - if (mf && (mask & KDBUS_ATTACH_PIDS)) { - pids.pid = pid_nr_ns(mf->tgid, conn->pid_ns); - pids.tid = pid_nr_ns(mf->pid, conn->pid_ns); - pids.ppid = pid_nr_ns(mf->ppid, conn->pid_ns); - - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, KDBUS_ITEM_PIDS, - &pids, sizeof(pids), &size); - } else if (mp && (mask & KDBUS_ATTACH_PIDS)) { - pids.pid = pid_nr_ns(mp->tgid, conn->pid_ns); - pids.tid = pid_nr_ns(mp->pid, conn->pid_ns); - pids.ppid = pid_nr_ns(mp->ppid, conn->pid_ns); - - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, KDBUS_ITEM_PIDS, - &pids, sizeof(pids), &size); - } - - if (mp && (mask & KDBUS_ATTACH_AUXGROUPS)) { - const struct group_info *info = mp->cred->group_info; - size_t i, n, payload_size; - - n = info->ngroups; - payload_size = n * sizeof(u64); - auxgrps = kmalloc(payload_size, GFP_KERNEL); - if (!auxgrps) { - ret = -ENOMEM; - goto exit; - } - - for (i = 0; i < n; ++i) - auxgrps[i] = from_kgid_munged(user_ns, - GROUP_AT(info, i)); - - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_AUXGROUPS, - auxgrps, payload_size, &size); - } - - if (mp && (mask & KDBUS_ATTACH_TID_COMM)) - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_TID_COMM, mp->tid_comm, - strlen(mp->tid_comm) + 1, &size); - - if (mp && (mask & KDBUS_ATTACH_PID_COMM)) - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_PID_COMM, mp->pid_comm, - strlen(mp->pid_comm) + 1, &size); - - if (mp && (mask & KDBUS_ATTACH_EXE)) { - struct path p; - - /* - * TODO: We need access to __d_path() so we can write the path - * relative to conn->root_path. Once upstream, we need - * EXPORT_SYMBOL(__d_path) or an equivalent of d_path() that - * takes the root path directly. Until then, we drop this item - * if the root-paths differ. - */ - - get_fs_root(current->fs, &p); - if (path_equal(&p, &mp->root_path) && - path_equal(&p, &conn->root_path)) { - exe_page = (void *)__get_free_page(GFP_TEMPORARY); - if (!exe_page) { - path_put(&p); - ret = -ENOMEM; - goto exit; - } - - exe_pathname = d_path(&mp->exe_path, exe_page, - PAGE_SIZE); - if (IS_ERR(exe_pathname)) { - path_put(&p); - ret = PTR_ERR(exe_pathname); - goto exit; - } - - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_EXE, - exe_pathname, - strlen(exe_pathname) + 1, - &size); - } - path_put(&p); - } - - if (mp && (mask & KDBUS_ATTACH_CMDLINE)) - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_CMDLINE, mp->cmdline, - strlen(mp->cmdline) + 1, &size); - - if (mp && (mask & KDBUS_ATTACH_CGROUP)) - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_CGROUP, mp->cgroup, - strlen(mp->cgroup) + 1, &size); - - if (mp && (mask & KDBUS_ATTACH_CAPS)) { - struct kdbus_meta_caps caps = {}; - - kdbus_meta_export_caps(&caps, mp, user_ns); - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_CAPS, &caps, - sizeof(caps), &size); - } - - if (mf && (mask & KDBUS_ATTACH_SECLABEL)) - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_SECLABEL, mf->seclabel, - strlen(mf->seclabel) + 1, &size); - else if (mp && (mask & KDBUS_ATTACH_SECLABEL)) - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_SECLABEL, mp->seclabel, - strlen(mp->seclabel) + 1, &size); - - if (mp && (mask & KDBUS_ATTACH_AUDIT)) { - struct kdbus_audit a = { - .loginuid = from_kuid(user_ns, mp->audit_loginuid), - .sessionid = mp->audit_sessionid, - }; - - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, KDBUS_ITEM_AUDIT, - &a, sizeof(a), &size); - } - - /* connection metadata */ - - if (mc && (mask & KDBUS_ATTACH_NAMES)) - kdbus_kvec_set(&kvec[cnt++], mc->owned_names_items, - KDBUS_ALIGN8(mc->owned_names_size), &size); - - if (mc && (mask & KDBUS_ATTACH_CONN_DESCRIPTION)) - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_CONN_DESCRIPTION, - mc->conn_description, - strlen(mc->conn_description) + 1, - &size); - - if (mc && (mask & KDBUS_ATTACH_TIMESTAMP)) - cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, - KDBUS_ITEM_TIMESTAMP, &mc->ts, - sizeof(mc->ts), &size); - - ret = kdbus_pool_slice_copy_kvec(slice, offset, kvec, cnt, size); - *real_size = size; - -exit: - kfree(auxgrps); - - if (exe_page) - free_page((unsigned long)exe_page); - - return ret; -} - struct kdbus_meta_staging { const struct kdbus_meta_proc *mp; const struct kdbus_meta_fake *mf; diff --git a/ipc/kdbus/metadata.h b/ipc/kdbus/metadata.h index a30b0ad26af2..8fb2a9f7f82e 100644 --- a/ipc/kdbus/metadata.h +++ b/ipc/kdbus/metadata.h @@ -72,17 +72,6 @@ int kdbus_meta_conn_collect(struct kdbus_meta_conn *mc, struct kdbus_conn *conn, u64 msg_seqnum, u64 what); -int kdbus_meta_export_prepare(struct kdbus_meta_proc *mp, - struct kdbus_meta_fake *mf, - struct kdbus_meta_conn *mc, - u64 *mask, size_t *sz); -int kdbus_meta_export(struct kdbus_meta_proc *mp, - struct kdbus_meta_fake *mf, - struct kdbus_meta_conn *mc, - struct kdbus_conn *conn, - u64 mask, - struct kdbus_pool_slice *slice, - off_t offset, size_t *real_size); int kdbus_meta_emit(struct kdbus_meta_proc *mp, struct kdbus_meta_fake *mf, struct kdbus_meta_conn *mc, |