Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions
util.c File Reference
#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/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"

Go to the source code of this file.

Data Structures

struct  ipc_proc_iface
 
struct  ipc_rcu_hdr
 
struct  ipc_rcu_grace
 
struct  ipc_rcu_sched
 

Macros

#define HDRLEN_KMALLOC
 
#define HDRLEN_VMALLOC
 

Functions

 __initcall (ipc_init)
 
void ipc_init_ids (struct ipc_ids *ids)
 
int ipc_get_maxid (struct ipc_ids *ids)
 
int ipc_addid (struct ipc_ids *ids, struct kern_ipc_perm *new, int size)
 
void ipc_rmid (struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
 
voidipc_alloc (int size)
 
void ipc_free (void *ptr, int size)
 
voidipc_rcu_alloc (int size)
 
void ipc_rcu_getref (void *ptr)
 
void ipc_rcu_putref (void *ptr)
 
int ipcperms (struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
 
void kernel_to_ipc64_perm (struct kern_ipc_perm *in, struct ipc64_perm *out)
 
void ipc64_perm_to_ipc_perm (struct ipc64_perm *in, struct ipc_perm *out)
 
struct kern_ipc_permipc_lock (struct ipc_ids *ids, int id)
 
struct kern_ipc_permipc_lock_check (struct ipc_ids *ids, int id)
 
int ipcget (struct ipc_namespace *ns, struct ipc_ids *ids, struct ipc_ops *ops, struct ipc_params *params)
 
int ipc_update_perm (struct ipc64_perm *in, struct kern_ipc_perm *out)
 
struct kern_ipc_permipcctl_pre_down (struct ipc_namespace *ns, struct ipc_ids *ids, int id, int cmd, struct ipc64_perm *perm, int extra_perm)
 

Macro Definition Documentation

#define HDRLEN_KMALLOC
Value:
(sizeof(struct ipc_rcu_grace) > sizeof(struct ipc_rcu_hdr) ? \
sizeof(struct ipc_rcu_grace) : sizeof(struct ipc_rcu_hdr))

Definition at line 504 of file util.c.

#define HDRLEN_VMALLOC
Value:

Definition at line 506 of file util.c.

Function Documentation

__initcall ( ipc_init  )
void ipc64_perm_to_ipc_perm ( struct ipc64_perm in,
struct ipc_perm out 
)

ipc64_perm_to_ipc_perm - convert new ipc permissions to old : new style IPC permissions : old style IPC permissions

Turn the new style permissions object into a compatibility object and store it into the pointer.

Definition at line 663 of file util.c.

int ipc_addid ( struct ipc_ids ids,
struct kern_ipc_perm new,
int  size 
)

ipc_addid - add an IPC identifier : IPC identifier set : new IPC permission set : 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 ipc_ids.rw_mutex held as a writer.

Definition at line 250 of file util.c.

void* ipc_alloc ( int  size)

ipc_alloc - allocate ipc space : size desired

Allocate memory from the appropriate pools and return a pointer to it. NULL is returned if the allocation fails

Definition at line 445 of file util.c.

void ipc_free ( void ptr,
int  size 
)

ipc_free - free ipc space : pointer returned by ipc_alloc : size of block

Free a block created with ipc_alloc(). The caller must know the size used in the allocation call.

Definition at line 464 of file util.c.

int ipc_get_maxid ( struct ipc_ids ids)

ipc_get_maxid - get the last assigned id : IPC identifier set

Called with ipc_ids.rw_mutex held.

Definition at line 212 of file util.c.

void ipc_init_ids ( struct ipc_ids ids)

ipc_init_ids - initialise IPC identifiers : Identifier set

Set up the sequence range to use for the ipc identifier range (limited below IPCMNI) then initialise the ids idr.

Definition at line 119 of file util.c.

struct kern_ipc_perm* ipc_lock ( struct ipc_ids ids,
int  id 
)
read

ipc_lock - Lock an ipc structure without rw_mutex held : IPC identifier set : 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 exit.

Definition at line 684 of file util.c.

struct kern_ipc_perm* ipc_lock_check ( struct ipc_ids ids,
int  id 
)
read

Definition at line 710 of file util.c.

void* ipc_rcu_alloc ( int  size)

ipc_rcu_alloc - allocate ipc and rcu space : size desired

Allocate memory for the rcu header structure + the object. Returns the pointer to the object. NULL is returned if the allocation fails.

Definition at line 526 of file util.c.

void ipc_rcu_getref ( void ptr)

Definition at line 552 of file util.c.

void ipc_rcu_putref ( void ptr)

Definition at line 582 of file util.c.

void ipc_rmid ( struct ipc_ids ids,
struct kern_ipc_perm ipcp 
)

ipc_rmid - remove an IPC identifier : IPC identifier set : ipc perm structure containing the identifier to remove

ipc_ids.rw_mutex (as a writer) and the spinlock for this ID are held before this function is called, and remain locked on the exit.

Definition at line 424 of file util.c.

int ipc_update_perm ( struct ipc64_perm in,
struct kern_ipc_perm out 
)

ipc_update_perm - update the permissions of an IPC. : the permission given as input. : the permission of the ipc to set.

Definition at line 750 of file util.c.

struct kern_ipc_perm* ipcctl_pre_down ( struct ipc_namespace ns,
struct ipc_ids ids,
int  id,
int  cmd,
struct ipc64_perm perm,
int  extra_perm 
)
read

ipcctl_pre_down - retrieve an ipc and check permissions for some IPC_XXX cmd : the ipc namespace : the table of ids where to look for the ipc : the id of the ipc to retrieve : the cmd to check : the permission to set : 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 the ipc with both ipc and rw_mutex locks held in case of success or an err-code without any lock held otherwise.

Definition at line 782 of file util.c.

int ipcget ( struct ipc_namespace ns,
struct ipc_ids ids,
struct ipc_ops ops,
struct ipc_params params 
)

ipcget - Common sys_*get() code : namsepace : IPC identifier set : operations to be called on ipc object creation, permission checks and further checks : the parameters needed by the previous operations.

Common routine called by sys_msgget(), sys_semget() and sys_shmget().

Definition at line 736 of file util.c.

int ipcperms ( struct ipc_namespace ns,
struct kern_ipc_perm ipcp,
short  flag 
)

ipcperms - check IPC permissions : IPC namespace : IPC permission set : desired permission set.

Check user, group, other permissions for access to ipc resources. return 0 if allowed

will most probably be 0 or S_...UGO from <linux/stat.h>

Definition at line 607 of file util.c.

void kernel_to_ipc64_perm ( struct kern_ipc_perm in,
struct ipc64_perm out 
)

kernel_to_ipc64_perm - convert kernel ipc permissions to user : kernel permissions : new style IPC permissions

Turn the kernel object into a set of permissions descriptions for returning to userspace ().

Definition at line 643 of file util.c.