Commit 27c331a1 authored by Manfred Spraul's avatar Manfred Spraul Committed by Linus Torvalds

ipc/util.c: further variable name cleanups

The varable names got a mess, thus standardize them again:

id: user space id. Called semid, shmid, msgid if the type is known.
    Most functions use "id" already.
idx: "index" for the idr lookup
    Right now, some functions use lid, ipc_addid() already uses idx as
    the variable name.
seq: sequence number, to avoid quick collisions of the user space id
key: user space key, used for the rhash tree

Link: http://lkml.kernel.org/r/20180712185241.4017-12-manfred@colorfullife.comSigned-off-by: default avatarManfred Spraul <manfred@colorfullife.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Davidlohr Bueso <dbueso@suse.de>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Kees Cook <keescook@chromium.org>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Michal Hocko <mhocko@suse.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent eae04d25
...@@ -18,7 +18,7 @@ struct ipc_ids { ...@@ -18,7 +18,7 @@ struct ipc_ids {
unsigned short seq; unsigned short seq;
struct rw_semaphore rwsem; struct rw_semaphore rwsem;
struct idr ipcs_idr; struct idr ipcs_idr;
int max_id; int max_idx;
#ifdef CONFIG_CHECKPOINT_RESTORE #ifdef CONFIG_CHECKPOINT_RESTORE
int next_id; int next_id;
#endif #endif
......
...@@ -456,7 +456,7 @@ static int msgctl_info(struct ipc_namespace *ns, int msqid, ...@@ -456,7 +456,7 @@ static int msgctl_info(struct ipc_namespace *ns, int msqid,
int cmd, struct msginfo *msginfo) int cmd, struct msginfo *msginfo)
{ {
int err; int err;
int max_id; int max_idx;
/* /*
* We must not return kernel stack data. * We must not return kernel stack data.
...@@ -483,9 +483,9 @@ static int msgctl_info(struct ipc_namespace *ns, int msqid, ...@@ -483,9 +483,9 @@ static int msgctl_info(struct ipc_namespace *ns, int msqid,
msginfo->msgpool = MSGPOOL; msginfo->msgpool = MSGPOOL;
msginfo->msgtql = MSGTQL; msginfo->msgtql = MSGTQL;
} }
max_id = ipc_get_maxid(&msg_ids(ns)); max_idx = ipc_get_maxidx(&msg_ids(ns));
up_read(&msg_ids(ns).rwsem); up_read(&msg_ids(ns).rwsem);
return (max_id < 0) ? 0 : max_id; return (max_idx < 0) ? 0 : max_idx;
} }
static int msgctl_stat(struct ipc_namespace *ns, int msqid, static int msgctl_stat(struct ipc_namespace *ns, int msqid,
......
...@@ -1294,7 +1294,7 @@ static int semctl_info(struct ipc_namespace *ns, int semid, ...@@ -1294,7 +1294,7 @@ static int semctl_info(struct ipc_namespace *ns, int semid,
int cmd, void __user *p) int cmd, void __user *p)
{ {
struct seminfo seminfo; struct seminfo seminfo;
int max_id; int max_idx;
int err; int err;
err = security_sem_semctl(NULL, cmd); err = security_sem_semctl(NULL, cmd);
...@@ -1318,11 +1318,11 @@ static int semctl_info(struct ipc_namespace *ns, int semid, ...@@ -1318,11 +1318,11 @@ static int semctl_info(struct ipc_namespace *ns, int semid,
seminfo.semusz = SEMUSZ; seminfo.semusz = SEMUSZ;
seminfo.semaem = SEMAEM; seminfo.semaem = SEMAEM;
} }
max_id = ipc_get_maxid(&sem_ids(ns)); max_idx = ipc_get_maxidx(&sem_ids(ns));
up_read(&sem_ids(ns).rwsem); up_read(&sem_ids(ns).rwsem);
if (copy_to_user(p, &seminfo, sizeof(struct seminfo))) if (copy_to_user(p, &seminfo, sizeof(struct seminfo)))
return -EFAULT; return -EFAULT;
return (max_id < 0) ? 0 : max_id; return (max_idx < 0) ? 0 : max_idx;
} }
static int semctl_setval(struct ipc_namespace *ns, int semid, int semnum, static int semctl_setval(struct ipc_namespace *ns, int semid, int semnum,
......
...@@ -948,7 +948,7 @@ static int shmctl_ipc_info(struct ipc_namespace *ns, ...@@ -948,7 +948,7 @@ static int shmctl_ipc_info(struct ipc_namespace *ns,
shminfo->shmall = ns->shm_ctlall; shminfo->shmall = ns->shm_ctlall;
shminfo->shmmin = SHMMIN; shminfo->shmmin = SHMMIN;
down_read(&shm_ids(ns).rwsem); down_read(&shm_ids(ns).rwsem);
err = ipc_get_maxid(&shm_ids(ns)); err = ipc_get_maxidx(&shm_ids(ns));
up_read(&shm_ids(ns).rwsem); up_read(&shm_ids(ns).rwsem);
if (err < 0) if (err < 0)
err = 0; err = 0;
...@@ -968,7 +968,7 @@ static int shmctl_shm_info(struct ipc_namespace *ns, ...@@ -968,7 +968,7 @@ static int shmctl_shm_info(struct ipc_namespace *ns,
shm_info->shm_tot = ns->shm_tot; shm_info->shm_tot = ns->shm_tot;
shm_info->swap_attempts = 0; shm_info->swap_attempts = 0;
shm_info->swap_successes = 0; shm_info->swap_successes = 0;
err = ipc_get_maxid(&shm_ids(ns)); err = ipc_get_maxidx(&shm_ids(ns));
up_read(&shm_ids(ns).rwsem); up_read(&shm_ids(ns).rwsem);
if (err < 0) if (err < 0)
err = 0; err = 0;
......
...@@ -119,7 +119,7 @@ void ipc_init_ids(struct ipc_ids *ids) ...@@ -119,7 +119,7 @@ void ipc_init_ids(struct ipc_ids *ids)
init_rwsem(&ids->rwsem); init_rwsem(&ids->rwsem);
rhashtable_init(&ids->key_ht, &ipc_kht_params); rhashtable_init(&ids->key_ht, &ipc_kht_params);
idr_init(&ids->ipcs_idr); idr_init(&ids->ipcs_idr);
ids->max_id = -1; ids->max_idx = -1;
#ifdef CONFIG_CHECKPOINT_RESTORE #ifdef CONFIG_CHECKPOINT_RESTORE
ids->next_id = -1; ids->next_id = -1;
#endif #endif
...@@ -237,7 +237,7 @@ static inline int ipc_idr_alloc(struct ipc_ids *ids, struct kern_ipc_perm *new) ...@@ -237,7 +237,7 @@ static inline int ipc_idr_alloc(struct ipc_ids *ids, struct kern_ipc_perm *new)
* @limit: limit for the number of used ids * @limit: limit for the number of used ids
* *
* Add an entry 'new' to the ipc ids idr. The permissions object is * 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 * initialised and the first free entry is set up and the index assigned
* is returned. The 'new' entry is returned in a locked state on success. * 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. * On failure the entry is not locked and a negative err-code is returned.
...@@ -291,8 +291,8 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int limit) ...@@ -291,8 +291,8 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int limit)
} }
ids->in_use++; ids->in_use++;
if (idx > ids->max_id) if (idx > ids->max_idx)
ids->max_id = idx; ids->max_idx = idx;
return idx; return idx;
} }
...@@ -431,20 +431,20 @@ static void ipc_kht_remove(struct ipc_ids *ids, struct kern_ipc_perm *ipcp) ...@@ -431,20 +431,20 @@ static void ipc_kht_remove(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
*/ */
void ipc_rmid(struct ipc_ids *ids, struct kern_ipc_perm *ipcp) void ipc_rmid(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
{ {
int lid = ipcid_to_idx(ipcp->id); int idx = ipcid_to_idx(ipcp->id);
idr_remove(&ids->ipcs_idr, lid); idr_remove(&ids->ipcs_idr, idx);
ipc_kht_remove(ids, ipcp); ipc_kht_remove(ids, ipcp);
ids->in_use--; ids->in_use--;
ipcp->deleted = true; ipcp->deleted = true;
if (unlikely(lid == ids->max_id)) { if (unlikely(idx == ids->max_idx)) {
do { do {
lid--; idx--;
if (lid == -1) if (idx == -1)
break; break;
} while (!idr_find(&ids->ipcs_idr, lid)); } while (!idr_find(&ids->ipcs_idr, idx));
ids->max_id = lid; ids->max_idx = idx;
} }
} }
...@@ -564,9 +564,9 @@ void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out) ...@@ -564,9 +564,9 @@ void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out)
struct kern_ipc_perm *ipc_obtain_object_idr(struct ipc_ids *ids, int id) struct kern_ipc_perm *ipc_obtain_object_idr(struct ipc_ids *ids, int id)
{ {
struct kern_ipc_perm *out; struct kern_ipc_perm *out;
int lid = ipcid_to_idx(id); int idx = ipcid_to_idx(id);
out = idr_find(&ids->ipcs_idr, lid); out = idr_find(&ids->ipcs_idr, idx);
if (!out) if (!out)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
......
...@@ -113,12 +113,12 @@ void ipc_set_key_private(struct ipc_ids *, struct kern_ipc_perm *); ...@@ -113,12 +113,12 @@ void ipc_set_key_private(struct ipc_ids *, struct kern_ipc_perm *);
int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flg); int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flg);
/** /**
* ipc_get_maxid - get the last assigned id * ipc_get_maxidx - get the highest assigned index
* @ids: ipc identifier set * @ids: ipc identifier set
* *
* Called with ipc_ids.rwsem held for reading. * Called with ipc_ids.rwsem held for reading.
*/ */
static inline int ipc_get_maxid(struct ipc_ids *ids) static inline int ipc_get_maxidx(struct ipc_ids *ids)
{ {
if (ids->in_use == 0) if (ids->in_use == 0)
return -1; return -1;
...@@ -126,7 +126,7 @@ static inline int ipc_get_maxid(struct ipc_ids *ids) ...@@ -126,7 +126,7 @@ static inline int ipc_get_maxid(struct ipc_ids *ids)
if (ids->in_use == IPCMNI) if (ids->in_use == IPCMNI)
return IPCMNI - 1; return IPCMNI - 1;
return ids->max_id; return ids->max_idx;
} }
/* /*
...@@ -172,9 +172,9 @@ extern struct msg_msg *load_msg(const void __user *src, size_t len); ...@@ -172,9 +172,9 @@ extern struct msg_msg *load_msg(const void __user *src, size_t len);
extern struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst); extern struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst);
extern int store_msg(void __user *dest, struct msg_msg *msg, size_t len); extern int store_msg(void __user *dest, struct msg_msg *msg, size_t len);
static inline int ipc_checkid(struct kern_ipc_perm *ipcp, int uid) static inline int ipc_checkid(struct kern_ipc_perm *ipcp, int id)
{ {
return uid / SEQ_MULTIPLIER != ipcp->seq; return ipcid_to_seqx(id) != ipcp->seq;
} }
static inline void ipc_lock_object(struct kern_ipc_perm *perm) static inline void ipc_lock_object(struct kern_ipc_perm *perm)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment