Release 4.7 ipc/util.c
/*
* linux/ipc/util.c
* Copyright (C) 1992 Krishna Balasubramanian
*
* Sep 1997 - Call suser() last after "normal" permission checks so we
* get BSD style process accounting right.
* Occurs in several places in the IPC code.
* Chris Evans, <chris@ferret.lmh.ox.ac.uk>
* Nov 1999 - ipc helper functions, unified SMP locking
* Manfred Spraul <manfred@colorfullife.com>
* Oct 2002 - One lock per IPC id. RCU ipc_free for lock-free grow_ary().
* Mingming Cao <cmm@us.ibm.com>
* Mar 2006 - support for audit of ipc object properties
* Dustin Kirkland <dustin.kirkland@us.ibm.com>
* Jun 2006 - namespaces ssupport
* OpenVZ, SWsoft Inc.
* Pavel Emelianov <xemul@openvz.org>
*
* General sysv ipc locking scheme:
* rcu_read_lock()
* obtain the ipc object (kern_ipc_perm) by looking up the id in an idr
* tree.
* - perform initial checks (capabilities, auditing and permission,
* etc).
* - perform read-only operations, such as STAT, INFO commands.
* acquire the ipc lock (kern_ipc_perm.lock) through
* ipc_lock_object()
* - perform data updates, such as SET, RMID commands and
* mechanism-specific operations (semop/semtimedop,
* msgsnd/msgrcv, shmat/shmdt).
* drop the ipc lock, through ipc_unlock_object().
* rcu_read_unlock()
*
* The ids->rwsem must be taken when:
* - creating, removing and iterating the existing entries in ipc
* identifier sets.
* - iterating through files under /proc/sysvipc/
*
* Note that sems have a special fast path that avoids kern_ipc_perm.lock -
* see sem_lock().
*/
#include <linux/mm.h>
#include <linux/shm.h>
#include <linux/init.h>
#include <linux/msg.h>
#include <linux/vmalloc.h>
#include <linux/slab.h>
#include <linux/notifier.h>
#include <linux/capability.h>
#include <linux/highuid.h>
#include <linux/security.h>
#include <linux/rcupdate.h>
#include <linux/workqueue.h>
#include <linux/seq_file.h>
#include <linux/proc_fs.h>
#include <linux/audit.h>
#include <linux/nsproxy.h>
#include <linux/rwsem.h>
#include <linux/memory.h>
#include <linux/ipc_namespace.h>
#include <asm/unistd.h>
#include "util.h"
struct ipc_proc_iface {
const char *path;
const char *header;
int ids;
int (*show)(struct seq_file *, void *);
};
/**
* ipc_init - initialise ipc subsystem
*
* The various sysv ipc resources (semaphores, messages and shared
* memory) are initialised.
*
* A callback routine is registered into the memory hotplug notifier
* chain: since msgmni scales to lowmem this callback routine will be
* called upon successful memory add / remove to recompute msmgni.
*/
static int __init ipc_init(void)
{
sem_init();
msg_init();
shm_init();
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 16 | 76.19% | 2 | 66.67% |
andrew morton | andrew morton | 5 | 23.81% | 1 | 33.33% |
| Total | 21 | 100.00% | 3 | 100.00% |
device_initcall(ipc_init);
/**
* ipc_init_ids - initialise ipc identifiers
* @ids: ipc identifier set
*
* Set up the sequence range to use for the ipc identifier range (limited
* below IPCMNI) then initialise the ids idr.
*/
void ipc_init_ids(struct ipc_ids *ids)
{
ids->in_use = 0;
ids->seq = 0;
ids->next_id = -1;
init_rwsem(&ids->rwsem);
idr_init(&ids->ipcs_idr);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 27 | 60.00% | 2 | 33.33% |
stanislav kinsbursky | stanislav kinsbursky | 7 | 15.56% | 1 | 16.67% |
davidlohr bueso | davidlohr bueso | 5 | 11.11% | 1 | 16.67% |
nadia derbey | nadia derbey | 3 | 6.67% | 1 | 16.67% |
paul e. mckenney | paul e. mckenney | 3 | 6.67% | 1 | 16.67% |
| Total | 45 | 100.00% | 6 | 100.00% |
#ifdef CONFIG_PROC_FS
static const struct file_operations sysvipc_proc_fops;
/**
* ipc_init_proc_interface - create a proc interface for sysipc types using a seq_file interface.
* @path: Path in procfs
* @header: Banner to be printed at the beginning of the file.
* @ids: ipc id table to iterate.
* @show: show routine.
*/
void __init ipc_init_proc_interface(const char *path, const char *header,
int ids, int (*show)(struct seq_file *, void *))
{
struct proc_dir_entry *pde;
struct ipc_proc_iface *iface;
iface = kmalloc(sizeof(*iface), GFP_KERNEL);
if (!iface)
return;
iface->path = path;
iface->header = header;
iface->ids = ids;
iface->show = show;
pde = proc_create_data(path,
S_IRUGO, /* world readable */
NULL, /* parent dir */
&sysvipc_proc_fops,
iface);
if (!pde)
kfree(iface);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
mike waychison | mike waychison | 106 | 92.98% | 1 | 33.33% |
denis v. lunev | denis v. lunev | 7 | 6.14% | 1 | 33.33% |
kirill korotaev | kirill korotaev | 1 | 0.88% | 1 | 33.33% |
| Total | 114 | 100.00% | 3 | 100.00% |
#endif
/**
* ipc_findkey - find a key in an ipc identifier set
* @ids: ipc identifier set
* @key: key to find
*
* Returns the locked pointer to the ipc structure if found or NULL
* otherwise. If key is found ipc points to the owning ipc structure
*
* Called with ipc_ids.rwsem held.
*/
static struct kern_ipc_perm *ipc_findkey(struct ipc_ids *ids, key_t key)
{
struct kern_ipc_perm *ipc;
int next_id;
int total;
for (total = 0, next_id = 0; total < ids->in_use; next_id++) {
ipc = idr_find(&ids->ipcs_idr, next_id);
if (ipc == NULL)
continue;
if (ipc->key != key) {
total++;
continue;
}
rcu_read_lock();
ipc_lock_object(ipc);
return ipc;
}
return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 45 | 47.37% | 2 | 33.33% |
nadia derbey | nadia derbey | 44 | 46.32% | 2 | 33.33% |
davidlohr bueso | davidlohr bueso | 4 | 4.21% | 1 | 16.67% |
andrew morton | andrew morton | 2 | 2.11% | 1 | 16.67% |
| Total | 95 | 100.00% | 6 | 100.00% |
/**
* ipc_get_maxid - get the last assigned id
* @ids: ipc identifier set
*
* Called with ipc_ids.rwsem held.
*/
int ipc_get_maxid(struct ipc_ids *ids)
{
struct kern_ipc_perm *ipc;
int max_id = -1;
int total, id;
if (ids->in_use == 0)
return -1;
if (ids->in_use == IPCMNI)
return IPCMNI - 1;
/* Look for the last assigned id */
total = 0;
for (id = 0; id < IPCMNI && total < ids->in_use; id++) {
ipc = idr_find(&ids->ipcs_idr, id);
if (ipc != NULL) {
max_id = id;
total++;
}
}
return max_id;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nadia derbey | nadia derbey | 59 | 55.14% | 1 | 25.00% |
pre-git | pre-git | 41 | 38.32% | 1 | 25.00% |
paul e. mckenney | paul e. mckenney | 6 | 5.61% | 1 | 25.00% |
andrew morton | andrew morton | 1 | 0.93% | 1 | 25.00% |
| Total | 107 | 100.00% | 4 | 100.00% |
/**
* ipc_addid - add an ipc identifier
* @ids: ipc identifier set
* @new: new ipc permission set
* @size: limit for the number of used ids
*
* Add an entry 'new' to the ipc ids idr. The permissions object is
* initialised and the first free entry is set up and the id assigned
* is returned. The 'new' entry is returned in a locked state on success.
* On failure the entry is not locked and a negative err-code is returned.
*
* Called with writer ipc_ids.rwsem held.
*/
int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int size)
{
kuid_t euid;
kgid_t egid;
int id;
int next_id = ids->next_id;
if (size > IPCMNI)
size = IPCMNI;
if (ids->in_use >= size)
return -ENOSPC;
idr_preload(GFP_KERNEL);
spin_lock_init(&new->lock);
new->deleted = false;
rcu_read_lock();
spin_lock(&new->lock);
current_euid_egid(&euid, &egid);
new->cuid = new->uid = euid;
new->gid = new->cgid = egid;
id = idr_alloc(&ids->ipcs_idr, new,
(next_id < 0) ? 0 : ipcid_to_idx(next_id), 0,
GFP_NOWAIT);
idr_preload_end();
if (id < 0) {
spin_unlock(&new->lock);
rcu_read_unlock();
return id;
}
ids->in_use++;
if (next_id < 0) {
new->seq = ids->seq++;
if (ids->seq > IPCID_SEQ_MAX)
ids->seq = 0;
} else {
new->seq = ipcid_to_seqx(next_id);
ids->next_id = -1;
}
new->id = ipc_buildid(id, new->seq);
return id;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 66 | 27.50% | 3 | 21.43% |
nadia derbey | nadia derbey | 59 | 24.58% | 2 | 14.29% |
stanislav kinsbursky | stanislav kinsbursky | 47 | 19.58% | 1 | 7.14% |
linus torvalds | linus torvalds | 29 | 12.08% | 1 | 7.14% |
tejun heo | tejun heo | 17 | 7.08% | 1 | 7.14% |
pierre peiffer | pierre peiffer | 14 | 5.83% | 2 | 14.29% |
david howells | david howells | 4 | 1.67% | 1 | 7.14% |
eric w. biederman | eric w. biederman | 2 | 0.83% | 1 | 7.14% |
rafael aquini | rafael aquini | 1 | 0.42% | 1 | 7.14% |
davidlohr bueso | davidlohr bueso | 1 | 0.42% | 1 | 7.14% |
| Total | 240 | 100.00% | 14 | 100.00% |
/**
* ipcget_new - create a new ipc object
* @ns: ipc namespace
* @ids: ipc identifier set
* @ops: the actual creation routine to call
* @params: its parameters
*
* This routine is called by sys_msgget, sys_semget() and sys_shmget()
* when the key is IPC_PRIVATE.
*/
static int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids,
const struct ipc_ops *ops, struct ipc_params *params)
{
int err;
down_write(&ids->rwsem);
err = ops->getnew(ns, params);
up_write(&ids->rwsem);
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nadia derbey | nadia derbey | 56 | 93.33% | 2 | 40.00% |
davidlohr bueso | davidlohr bueso | 2 | 3.33% | 1 | 20.00% |
mathias krause | mathias krause | 1 | 1.67% | 1 | 20.00% |
pavel emelianov | pavel emelianov | 1 | 1.67% | 1 | 20.00% |
| Total | 60 | 100.00% | 5 | 100.00% |
/**
* ipc_check_perms - check security and permissions for an ipc object
* @ns: ipc namespace
* @ipcp: ipc permission set
* @ops: the actual security routine to call
* @params: its parameters
*
* This routine is called by sys_msgget(), sys_semget() and sys_shmget()
* when the key is not IPC_PRIVATE and that key already exists in the
* ds IDR.
*
* On success, the ipc id is returned.
*
* It is called with ipc_ids.rwsem and ipcp->lock held.
*/
static int ipc_check_perms(struct ipc_namespace *ns,
struct kern_ipc_perm *ipcp,
const struct ipc_ops *ops,
struct ipc_params *params)
{
int err;
if (ipcperms(ns, ipcp, params->flg))
err = -EACCES;
else {
err = ops->associate(ipcp, params->flg);
if (!err)
err = ipcp->id;
}
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nadia derbey | nadia derbey | 70 | 89.74% | 1 | 33.33% |
serge hallyn | serge hallyn | 7 | 8.97% | 1 | 33.33% |
mathias krause | mathias krause | 1 | 1.28% | 1 | 33.33% |
| Total | 78 | 100.00% | 3 | 100.00% |
/**
* ipcget_public - get an ipc object or create a new one
* @ns: ipc namespace
* @ids: ipc identifier set
* @ops: the actual creation routine to call
* @params: its parameters
*
* This routine is called by sys_msgget, sys_semget() and sys_shmget()
* when the key is not IPC_PRIVATE.
* It adds a new entry if the key is not found and does some permission
* / security checkings if the key is found.
*
* On success, the ipc id is returned.
*/
static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
const struct ipc_ops *ops, struct ipc_params *params)
{
struct kern_ipc_perm *ipcp;
int flg = params->flg;
int err;
/*
* Take the lock as a writer since we are potentially going to add
* a new entry + read locks are not "upgradable"
*/
down_write(&ids->rwsem);
ipcp = ipc_findkey(ids, params->key);
if (ipcp == NULL) {
/* key not used */
if (!(flg & IPC_CREAT))
err = -ENOENT;
else
err = ops->getnew(ns, params);
} else {
/* ipc object has been locked by ipc_findkey() */
if (flg & IPC_CREAT && flg & IPC_EXCL)
err = -EEXIST;
else {
err = 0;
if (ops->more_checks)
err = ops->more_checks(ipcp, params);
if (!err)
/*
* ipc_check_perms returns the IPC id on
* success
*/
err = ipc_check_perms(ns, ipcp, ops, params);
}
ipc_unlock(ipcp);
}
up_write(&ids->rwsem);
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nadia derbey | nadia derbey | 169 | 96.57% | 3 | 42.86% |
davidlohr bueso | davidlohr bueso | 2 | 1.14% | 1 | 14.29% |
serge hallyn | serge hallyn | 2 | 1.14% | 1 | 14.29% |
pavel emelianov | pavel emelianov | 1 | 0.57% | 1 | 14.29% |
mathias krause | mathias krause | 1 | 0.57% | 1 | 14.29% |
| Total | 175 | 100.00% | 7 | 100.00% |
/**
* ipc_rmid - remove an ipc identifier
* @ids: ipc identifier set
* @ipcp: ipc perm structure containing the identifier to remove
*
* ipc_ids.rwsem (as a writer) and the spinlock for this ID are held
* before this function is called, and remain locked on the exit.
*/
void ipc_rmid(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
{
int lid = ipcid_to_idx(ipcp->id);
idr_remove(&ids->ipcs_idr, lid);
ids->in_use--;
ipcp->deleted = true;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 25 | 54.35% | 2 | 28.57% |
nadia derbey | nadia derbey | 14 | 30.43% | 2 | 28.57% |
andrew morton | andrew morton | 4 | 8.70% | 1 | 14.29% |
eric sesterhenn | eric sesterhenn | 2 | 4.35% | 1 | 14.29% |
rafael aquini | rafael aquini | 1 | 2.17% | 1 | 14.29% |
| Total | 46 | 100.00% | 7 | 100.00% |
/**
* ipc_alloc - allocate ipc space
* @size: size desired
*
* Allocate memory from the appropriate pools and return a pointer to it.
* NULL is returned if the allocation fails
*/
void *ipc_alloc(int size)
{
void *out;
if (size > PAGE_SIZE)
out = vmalloc(size);
else
out = kmalloc(size, GFP_KERNEL);
return out;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 39 | 100.00% | 3 | 100.00% |
| Total | 39 | 100.00% | 3 | 100.00% |
/**
* ipc_free - free ipc space
* @ptr: pointer returned by ipc_alloc
*
* Free a block created with ipc_alloc().
*/
void ipc_free(void *ptr)
{
kvfree(ptr);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 13 | 92.86% | 1 | 50.00% |
tetsuo handa | tetsuo handa | 1 | 7.14% | 1 | 50.00% |
| Total | 14 | 100.00% | 2 | 100.00% |
/**
* ipc_rcu_alloc - allocate ipc and rcu space
* @size: size desired
*
* Allocate memory for the rcu header structure + the object.
* Returns the pointer to the object or NULL upon failure.
*/
void *ipc_rcu_alloc(int size)
{
/*
* We prepend the allocation with the rcu struct
*/
struct ipc_rcu *out = ipc_alloc(sizeof(struct ipc_rcu) + size);
if (unlikely(!out))
return NULL;
atomic_set(&out->refcount, 1);
return out + 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew morton | andrew morton | 21 | 40.38% | 1 | 20.00% |
al viro | al viro | 14 | 26.92% | 1 | 20.00% |
manfred spraul | manfred spraul | 12 | 23.08% | 2 | 40.00% |
rik van riel | rik van riel | 5 | 9.62% | 1 | 20.00% |
| Total | 52 | 100.00% | 5 | 100.00% |
int ipc_rcu_getref(void *ptr)
{
struct ipc_rcu *p = ((struct ipc_rcu *)ptr) - 1;
return atomic_inc_not_zero(&p->refcount);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
manfred spraul | manfred spraul | 27 | 79.41% | 2 | 66.67% |
rik van riel | rik van riel | 7 | 20.59% | 1 | 33.33% |
| Total | 34 | 100.00% | 3 | 100.00% |
void ipc_rcu_putref(void *ptr, void (*func)(struct rcu_head *head))
{
struct ipc_rcu *p = ((struct ipc_rcu *)ptr) - 1;
if (!atomic_dec_and_test(&p->refcount))
return;
call_rcu(&p->rcu, func);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew morton | andrew morton | 17 | 28.81% | 1 | 16.67% |
al viro | al viro | 15 | 25.42% | 1 | 16.67% |
davidlohr bueso | davidlohr bueso | 13 | 22.03% | 1 | 16.67% |
manfred spraul | manfred spraul | 13 | 22.03% | 2 | 33.33% |
rik van riel | rik van riel | 1 | 1.69% | 1 | 16.67% |
| Total | 59 | 100.00% | 6 | 100.00% |
void ipc_rcu_free(struct rcu_head *head)
{
struct ipc_rcu *p = container_of(head, struct ipc_rcu, rcu);
kvfree(p);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
davidlohr bueso | davidlohr bueso | 22 | 73.33% | 1 | 20.00% |
andrew morton | andrew morton | 5 | 16.67% | 1 | 20.00% |
pekka j enberg | pekka j enberg | 1 | 3.33% | 1 | 20.00% |
lai jiangshan | lai jiangshan | 1 | 3.33% | 1 | 20.00% |
al viro | al viro | 1 | 3.33% | 1 | 20.00% |
| Total | 30 | 100.00% | 5 | 100.00% |
/**
* ipcperms - check ipc permissions
* @ns: ipc namespace
* @ipcp: ipc permission set
* @flag: desired permission set
*
* Check user, group, other permissions for access
* to ipc resources. return 0 if allowed
*
* @flag will most probably be 0 or S_...UGO from <linux/stat.h>
*/
int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
{
kuid_t euid = current_euid();
int requested_mode, granted_mode;
audit_ipc_obj(ipcp);
requested_mode = (flag >> 6) | (flag >> 3) | flag;
granted_mode = ipcp->mode;
if (uid_eq(euid, ipcp->cuid) ||
uid_eq(euid, ipcp->uid))
granted_mode >>= 6;
else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
granted_mode >>= 3;
/* is there some bit set in requested_mode but not in granted_mode? */
if ((requested_mode & ~granted_mode & 0007) &&
!ns_capable(ns->user_ns, CAP_IPC_OWNER))
return -1;
return security_ipc_permission(ipcp, flag);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 100 | 74.07% | 6 | 46.15% |
serge hallyn | serge hallyn | 10 | 7.41% | 1 | 7.69% |
eric w. biederman | eric w. biederman | 9 | 6.67% | 1 | 7.69% |
david howells | david howells | 5 | 3.70% | 1 | 7.69% |
stephen d. smalley | stephen d. smalley | 5 | 3.70% | 1 | 7.69% |
steve grubb | steve grubb | 4 | 2.96% | 1 | 7.69% |
al viro | al viro | 1 | 0.74% | 1 | 7.69% |
greg kroah-hartman | greg kroah-hartman | 1 | 0.74% | 1 | 7.69% |
| Total | 135 | 100.00% | 13 | 100.00% |
/*
* Functions to convert between the kern_ipc_perm structure and the
* old/new ipc_perm structures
*/
/**
* kernel_to_ipc64_perm - convert kernel ipc permissions to user
* @in: kernel permissions
* @out: new style ipc permissions
*
* Turn the kernel object @in into a set of permissions descriptions
* for returning to userspace (@out).
*/
void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out)
{
out->key = in->key;
out->uid = from_kuid_munged(current_user_ns(), in->uid);
out->gid = from_kgid_munged(current_user_ns(), in->gid);
out->cuid = from_kuid_munged(current_user_ns(), in->cuid);
out->cgid = from_kgid_munged(current_user_ns(), in->cgid);
out->mode = in->mode;
out->seq = in->seq;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 71 | 74.74% | 1 | 50.00% |
eric w. biederman | eric w. biederman | 24 | 25.26% | 1 | 50.00% |
| Total | 95 | 100.00% | 2 | 100.00% |
/**
* ipc64_perm_to_ipc_perm - convert new ipc permissions to old
* @in: new style ipc permissions
* @out: old style ipc permissions
*
* Turn the new style permissions object @in into a compatibility
* object and store it into the @out pointer.
*/
void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out)
{
out->key = in->key;
SET_UID(out->uid, in->uid);
SET_GID(out->gid, in->gid);
SET_UID(out->cuid, in->cuid);
SET_GID(out->cgid, in->cgid);
out->mode = in->mode;
out->seq = in->seq;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 71 | 85.54% | 1 | 50.00% |
andi kleen | andi kleen | 12 | 14.46% | 1 | 50.00% |
| Total | 83 | 100.00% | 2 | 100.00% |
/**
* ipc_obtain_object
* @ids: ipc identifier set
* @id: ipc id to look for
*
* Look for an id in the ipc ids idr and return associated ipc object.
*
* Call inside the RCU critical section.
* The ipc object is *not* locked on exit.
*/
struct kern_ipc_perm *ipc_obtain_object_idr(struct ipc_ids *ids, int id)
{
struct kern_ipc_perm *out;
int lid = ipcid_to_idx(id);
out = idr_find(&ids->ipcs_idr, lid);
if (!out)
return ERR_PTR(-EINVAL);
return out;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew morton | andrew morton | 34 | 61.82% | 2 | 25.00% |
nadia derbey | nadia derbey | 15 | 27.27% | 3 | 37.50% |
davidlohr bueso | davidlohr bueso | 5 | 9.09% | 2 | 25.00% |
paul e. mckenney | paul e. mckenney | 1 | 1.82% | 1 | 12.50% |
| Total | 55 | 100.00% | 8 | 100.00% |
/**
* ipc_lock - lock an ipc structure without rwsem held
* @ids: ipc identifier set
* @id: ipc id to look for
*
* Look for an id in the ipc ids idr and lock the associated ipc object.
*
* The ipc object is locked on successful exit.
*/
struct kern_ipc_perm *ipc_lock(struct ipc_ids *ids, int id)
{
struct kern_ipc_perm *out;
rcu_read_lock();
out = ipc_obtain_object_idr(ids, id);
if (IS_ERR(out))
goto err;
spin_lock(&out->lock);
/*
* ipc_rmid() may have already freed the ID while ipc_lock()
* was spinning: here verify that the structure is still valid.
* Upon races with RMID, return -EIDRM, thus indicating that
* the ID points to a removed identifier.
*/
if (ipc_valid_object(out))
return out;
spin_unlock(&out->lock);
out = ERR_PTR(-EIDRM);
err:
rcu_read_unlock();
return out;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
davidlohr bueso | davidlohr bueso | 58 | 68.24% | 3 | 60.00% |
andrew morton | andrew morton | 24 | 28.24% | 1 | 20.00% |
rafael aquini | rafael aquini | 3 | 3.53% | 1 | 20.00% |
| Total | 85 | 100.00% | 5 | 100.00% |
/**
* ipc_obtain_object_check
* @ids: ipc identifier set
* @id: ipc id to look for
*
* Similar to ipc_obtain_object_idr() but also checks
* the ipc object reference counter.
*
* Call inside the RCU critical section.
* The ipc object is *not* locked on exit.
*/
struct kern_ipc_perm *ipc_obtain_object_check(struct ipc_ids *ids, int id)
{
struct kern_ipc_perm *out = ipc_obtain_object_idr(ids, id);
if (IS_ERR(out))
goto out;
if (ipc_checkid(out, id))
return ERR_PTR(-EINVAL);
out:
return out;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
davidlohr bueso | davidlohr bueso | 49 | 84.48% | 3 | 60.00% |
andrew morton | andrew morton | 5 | 8.62% | 1 | 20.00% |
nadia derbey | nadia derbey | 4 | 6.90% | 1 | 20.00% |
| Total | 58 | 100.00% | 5 | 100.00% |
/**
* ipcget - Common sys_*get() code
* @ns: namespace
* @ids: ipc identifier set
* @ops: operations to be called on ipc object creation, permission checks
* and further checks
* @params: the parameters needed by the previous operations.
*
* Common routine called by sys_msgget(), sys_semget() and sys_shmget().
*/
int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids,
const struct ipc_ops *ops, struct ipc_params *params)
{
if (params->key == IPC_PRIVATE)
return ipcget_new(ns, ids, ops, params);
else
return ipcget_public(ns, ids, ops, params);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pavel emelianov | pavel emelianov | 58 | 98.31% | 1 | 50.00% |
mathias krause | mathias krause | 1 | 1.69% | 1 | 50.00% |
| Total | 59 | 100.00% | 2 | 100.00% |
/**
* ipc_update_perm - update the permissions of an ipc object
* @in: the permission given as input.
* @out: the permission of the ipc to set.
*/
int ipc_update_perm(struct ipc64_perm *in, struct kern_ipc_perm *out)
{
kuid_t uid = make_kuid(current_user_ns(), in->uid);
kgid_t gid = make_kgid(current_user_ns(), in->gid);
if (!uid_valid(uid) || !gid_valid(gid))
return -EINVAL;
out->uid = uid;
out->gid = gid;
out->mode = (out->mode & ~S_IRWXUGO)
| (in->mode & S_IRWXUGO);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
eric w. biederman | eric w. biederman | 48 | 50.53% | 1 | 50.00% |
pierre peiffer | pierre peiffer | 47 | 49.47% | 1 | 50.00% |
| Total | 95 | 100.00% | 2 | 100.00% |
/**
* ipcctl_pre_down_nolock - retrieve an ipc and check permissions for some IPC_XXX cmd
* @ns: ipc namespace
* @ids: the table of ids where to look for the ipc
* @id: the id of the ipc to retrieve
* @cmd: the cmd to check
* @perm: the permission to set
* @extra_perm: one extra permission parameter used by msq
*
* This function does some common audit and permissions check for some IPC_XXX
* cmd and is called from semctl_down, shmctl_down and msgctl_down.
* It must be called without any lock held and
* - retrieves the ipc with the given id in the given table.
* - performs some audit and permission check, depending on the given cmd
* - returns a pointer to the ipc object or otherwise, the corresponding error.
*
* Call holding the both the rwsem and the rcu read lock.
*/
struct kern_ipc_perm *ipcctl_pre_down_nolock(struct ipc_namespace *ns,
struct ipc_ids *ids, int id, int cmd,
struct ipc64_perm *perm, int extra_perm)
{
kuid_t euid;
int err = -EPERM;
struct kern_ipc_perm *ipcp;
ipcp = ipc_obtain_object_check(ids, id);
if (IS_ERR(ipcp)) {
err = PTR_ERR(ipcp);
goto err;
}
audit_ipc_obj(ipcp);
if (cmd == IPC_SET)
audit_ipc_set_perm(extra_perm, perm->uid,
perm->gid, perm->mode);
euid = current_euid();
if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid) ||
ns_capable(ns->user_ns, CAP_SYS_ADMIN))
return ipcp; /* successful lookup */
err:
return ERR_PTR(err);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pierre peiffer | pierre peiffer | 84 | 57.14% | 1 | 16.67% |
davidlohr bueso | davidlohr bueso | 42 | 28.57% | 2 | 33.33% |
eric w. biederman | eric w. biederman | 9 | 6.12% | 1 | 16.67% |
david howells | david howells | 7 | 4.76% | 1 | 16.67% |
serge hallyn | serge hallyn | 5 | 3.40% | 1 | 16.67% |
| Total | 147 | 100.00% | 6 | 100.00% |
#ifdef CONFIG_ARCH_WANT_IPC_PARSE_VERSION
/**
* ipc_parse_version - ipc call version
* @cmd: pointer to command
*
* Return IPC_64 for new style IPC and IPC_OLD for old style IPC.
* The @cmd value is turned from an encoding command and version into
* just the command code.
*/
int ipc_parse_version(int *cmd)
{
if (*cmd & IPC_64) {
*cmd ^= IPC_64;
return IPC_64;
} else {
return IPC_OLD;
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 32 | 100.00% | 1 | 100.00% |
| Total | 32 | 100.00% | 1 | 100.00% |
#endif /* CONFIG_ARCH_WANT_IPC_PARSE_VERSION */
#ifdef CONFIG_PROC_FS
struct ipc_proc_iter {
struct ipc_namespace *ns;
struct ipc_proc_iface *iface;
};
/*
* This routine locks the ipc structure found at least at position pos.
*/
static struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos,
loff_t *new_pos)
{
struct kern_ipc_perm *ipc;
int total, id;
total = 0;
for (id = 0; id < pos && total < ids->in_use; id++) {
ipc = idr_find(&ids->ipcs_idr, id);
if (ipc != NULL)
total++;
}
if (total >= ids->in_use)
return NULL;
for (; pos < IPCMNI; pos++) {
ipc = idr_find(&ids->ipcs_idr, pos);
if (ipc != NULL) {
*new_pos = pos + 1;
rcu_read_lock();
ipc_lock_object(ipc);
return ipc;
}
}
/* Out of range - return NULL to terminate iteration */
return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nadia derbey | nadia derbey | 136 | 96.45% | 1 | 33.33% |
davidlohr bueso | davidlohr bueso | 4 | 2.84% | 1 | 33.33% |
adrian bunk | adrian bunk | 1 | 0.71% | 1 | 33.33% |
| Total | 141 | 100.00% | 3 | 100.00% |
static void *sysvipc_proc_next(struct seq_file *s, void *it, loff_t *pos)
{
struct ipc_proc_iter *iter = s->private;
struct ipc_proc_iface *iface = iter->iface;
struct kern_ipc_perm *ipc = it;
/* If we had an ipc id locked before, unlock it */
if (ipc && ipc != SEQ_START_TOKEN)
ipc_unlock(ipc);
return sysvipc_find_ipc(&iter->ns->ids[iface->ids], *pos, pos);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
mike waychison | mike waychison | 55 | 68.75% | 1 | 25.00% |
nadia derbey | nadia derbey | 13 | 16.25% | 1 | 25.00% |
eric w. biederman | eric w. biederman | 11 | 13.75% | 1 | 25.00% |
pierre peiffer | pierre peiffer | 1 | 1.25% | 1 | 25.00% |
| Total | 80 | 100.00% | 4 | 100.00% |
/*
* File positions: pos 0 -> header, pos n -> ipc id = n - 1.
* SeqFile iterator: iterator value locked ipc pointer or SEQ_TOKEN_START.
*/
static void *sysvipc_proc_start(struct seq_file *s, loff_t *pos)
{
struct ipc_proc_iter *iter = s->private;
struct ipc_proc_iface *iface = iter->iface;
struct ipc_ids *ids;
ids = &iter->ns->ids[iface->ids];
/*
* Take the lock - this will be released by the corresponding
* call to stop().
*/
down_read(&ids->rwsem);
/* pos < 0 is invalid */
if (*pos < 0)
return NULL;
/* pos == 0 means header */
if (*pos == 0)
return SEQ_START_TOKEN;
/* Find the (pos-1)th ipc */
return sysvipc_find_ipc(ids, *pos - 1, pos);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
mike waychison | mike waychison | 61 | 62.24% | 1 | 14.29% |
kirill korotaev | kirill korotaev | 15 | 15.31% | 1 | 14.29% |
eric w. biederman | eric w. biederman | 13 | 13.27% | 1 | 14.29% |
nadia derbey | nadia derbey | 7 | 7.14% | 2 | 28.57% |
pierre peiffer | pierre peiffer | 1 | 1.02% | 1 | 14.29% |
davidlohr bueso | davidlohr bueso | 1 | 1.02% | 1 | 14.29% |
| Total | 98 | 100.00% | 7 | 100.00% |
static void sysvipc_proc_stop(struct seq_file *s, void *it)
{
struct kern_ipc_perm *ipc = it;
struct ipc_proc_iter *iter = s->private;
struct ipc_proc_iface *iface = iter->iface;
struct ipc_ids *ids;
/* If we had a locked structure, release it */
if (ipc && ipc != SEQ_START_TOKEN)
ipc_unlock(ipc);
ids = &iter->ns->ids[iface->ids];
/* Release the lock we took in start() */
up_read(&ids->rwsem);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
mike waychison | mike waychison | 49 | 59.76% | 1 | 14.29% |
kirill korotaev | kirill korotaev | 16 | 19.51% | 1 | 14.29% |
eric w. biederman | eric w. biederman | 13 | 15.85% | 1 | 14.29% |
nadia derbey | nadia derbey | 2 | 2.44% | 2 | 28.57% |
pierre peiffer | pierre peiffer | 1 | 1.22% | 1 | 14.29% |
davidlohr bueso | davidlohr bueso | 1 | 1.22% | 1 | 14.29% |
| Total | 82 | 100.00% | 7 | 100.00% |
static int sysvipc_proc_show(struct seq_file *s, void *it)
{
struct ipc_proc_iter *iter = s->private;
struct ipc_proc_iface *iface = iter->iface;
if (it == SEQ_START_TOKEN) {
seq_puts(s, iface->header);
return 0;
}
return iface->show(s, it);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
mike waychison | mike waychison | 47 | 74.60% | 1 | 33.33% |
eric w. biederman | eric w. biederman | 11 | 17.46% | 1 | 33.33% |
joe perches | joe perches | 5 | 7.94% | 1 | 33.33% |
| Total | 63 | 100.00% | 3 | 100.00% |
static const struct seq_operations sysvipc_proc_seqops = {
.start = sysvipc_proc_start,
.stop = sysvipc_proc_stop,
.next = sysvipc_proc_next,
.show = sysvipc_proc_show,
};
static int sysvipc_proc_open(struct inode *inode, struct file *file)
{
struct ipc_proc_iter *iter;
iter = __seq_open_private(file, &sysvipc_proc_seqops, sizeof(*iter));
if (!iter)
return -ENOMEM;
iter->iface = PDE_DATA(inode);
iter->ns = get_ipc_ns(current->nsproxy->ipc_ns);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
eric w. biederman | eric w. biederman | 38 | 53.52% | 1 | 25.00% |
mike waychison | mike waychison | 21 | 29.58% | 1 | 25.00% |
rob jones | rob jones | 11 | 15.49% | 1 | 25.00% |
al viro | al viro | 1 | 1.41% | 1 | 25.00% |
| Total | 71 | 100.00% | 4 | 100.00% |
static int sysvipc_proc_release(struct inode *inode, struct file *file)
{
struct seq_file *seq = file->private_data;
struct ipc_proc_iter *iter = seq->private;
put_ipc_ns(iter->ns);
return seq_release_private(inode, file);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
eric w. biederman | eric w. biederman | 48 | 97.96% | 1 | 50.00% |
mike waychison | mike waychison | 1 | 2.04% | 1 | 50.00% |
| Total | 49 | 100.00% | 2 | 100.00% |
static const struct file_operations sysvipc_proc_fops = {
.open = sysvipc_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = sysvipc_proc_release,
};
#endif /* CONFIG_PROC_FS */
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nadia derbey | nadia derbey | 659 | 23.06% | 8 | 9.52% |
pre-git | pre-git | 572 | 20.01% | 13 | 15.48% |
mike waychison | mike waychison | 446 | 15.61% | 1 | 1.19% |
eric w. biederman | eric w. biederman | 242 | 8.47% | 2 | 2.38% |
davidlohr bueso | davidlohr bueso | 229 | 8.01% | 13 | 15.48% |
pierre peiffer | pierre peiffer | 148 | 5.18% | 5 | 5.95% |
andrew morton | andrew morton | 136 | 4.76% | 6 | 7.14% |
pavel emelianov | pavel emelianov | 63 | 2.20% | 2 | 2.38% |
stanislav kinsbursky | stanislav kinsbursky | 54 | 1.89% | 1 | 1.19% |
manfred spraul | manfred spraul | 52 | 1.82% | 2 | 2.38% |
kirill korotaev | kirill korotaev | 36 | 1.26% | 1 | 1.19% |
al viro | al viro | 32 | 1.12% | 3 | 3.57% |
linus torvalds | linus torvalds | 30 | 1.05% | 2 | 2.38% |
serge hallyn | serge hallyn | 24 | 0.84% | 1 | 1.19% |
tejun heo | tejun heo | 17 | 0.59% | 1 | 1.19% |
david howells | david howells | 16 | 0.56% | 1 | 1.19% |
rik van riel | rik van riel | 13 | 0.45% | 1 | 1.19% |
andi kleen | andi kleen | 12 | 0.42% | 1 | 1.19% |
rob jones | rob jones | 11 | 0.38% | 1 | 1.19% |
paul e. mckenney | paul e. mckenney | 10 | 0.35% | 1 | 1.19% |
stephen d. smalley | stephen d. smalley | 8 | 0.28% | 1 | 1.19% |
steve grubb | steve grubb | 7 | 0.24% | 1 | 1.19% |
denis v. lunev | denis v. lunev | 7 | 0.24% | 1 | 1.19% |
rafael aquini | rafael aquini | 5 | 0.17% | 1 | 1.19% |
joe perches | joe perches | 5 | 0.17% | 1 | 1.19% |
mathias krause | mathias krause | 4 | 0.14% | 1 | 1.19% |
masanari iida | masanari iida | 3 | 0.10% | 1 | 1.19% |
randy dunlap | randy dunlap | 3 | 0.10% | 1 | 1.19% |
tetsuo handa | tetsuo handa | 2 | 0.07% | 1 | 1.19% |
arjan van de ven | arjan van de ven | 2 | 0.07% | 1 | 1.19% |
eric sesterhenn | eric sesterhenn | 2 | 0.07% | 1 | 1.19% |
will deacon | will deacon | 2 | 0.07% | 1 | 1.19% |
james morris | james morris | 1 | 0.03% | 1 | 1.19% |
lai jiangshan | lai jiangshan | 1 | 0.03% | 1 | 1.19% |
greg kroah-hartman | greg kroah-hartman | 1 | 0.03% | 1 | 1.19% |
pekka j enberg | pekka j enberg | 1 | 0.03% | 1 | 1.19% |
adrian bunk | adrian bunk | 1 | 0.03% | 1 | 1.19% |
paul mcquade | paul mcquade | 1 | 0.03% | 1 | 1.19% |
| Total | 2858 | 100.00% | 84 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.