Skip to content

Commit

Permalink
ipc: constify ipc_ops
Browse files Browse the repository at this point in the history
There is no need to recreate the very same ipc_ops structure on every
kernel entry for msgget/semget/shmget.  Just declare it static and be
done with it.  While at it, constify it as we don't modify the structure
at runtime.

Found in the PaX patch, written by the PaX Team.

Signed-off-by: Mathias Krause <[email protected]>
Cc: PaX Team <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Cc: Manfred Spraul <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
minipli authored and torvalds committed Jun 6, 2014
1 parent 3e4e0f0 commit eb66ec4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
9 changes: 4 additions & 5 deletions ipc/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,14 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
{
struct ipc_namespace *ns;
struct ipc_ops msg_ops;
static const struct ipc_ops msg_ops = {
.getnew = newque,
.associate = msg_security,
};
struct ipc_params msg_params;

ns = current->nsproxy->ipc_ns;

msg_ops.getnew = newque;
msg_ops.associate = msg_security;
msg_ops.more_checks = NULL;

msg_params.key = key;
msg_params.flg = msgflg;

Expand Down
10 changes: 5 additions & 5 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,18 +564,18 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
{
struct ipc_namespace *ns;
struct ipc_ops sem_ops;
static const struct ipc_ops sem_ops = {
.getnew = newary,
.associate = sem_security,
.more_checks = sem_more_checks,
};
struct ipc_params sem_params;

ns = current->nsproxy->ipc_ns;

if (nsems < 0 || nsems > ns->sc_semmsl)
return -EINVAL;

sem_ops.getnew = newary;
sem_ops.associate = sem_security;
sem_ops.more_checks = sem_more_checks;

sem_params.key = key;
sem_params.flg = semflg;
sem_params.u.nsems = nsems;
Expand Down
10 changes: 5 additions & 5 deletions ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,15 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
{
struct ipc_namespace *ns;
struct ipc_ops shm_ops;
static const struct ipc_ops shm_ops = {
.getnew = newseg,
.associate = shm_security,
.more_checks = shm_more_checks,
};
struct ipc_params shm_params;

ns = current->nsproxy->ipc_ns;

shm_ops.getnew = newseg;
shm_ops.associate = shm_security;
shm_ops.more_checks = shm_more_checks;

shm_params.key = key;
shm_params.flg = shmflg;
shm_params.u.size = size;
Expand Down
8 changes: 4 additions & 4 deletions ipc/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int size)
* when the key is IPC_PRIVATE.
*/
static int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids,
struct ipc_ops *ops, struct ipc_params *params)
const struct ipc_ops *ops, struct ipc_params *params)
{
int err;

Expand All @@ -344,7 +344,7 @@ static int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids,
*/
static int ipc_check_perms(struct ipc_namespace *ns,
struct kern_ipc_perm *ipcp,
struct ipc_ops *ops,
const struct ipc_ops *ops,
struct ipc_params *params)
{
int err;
Expand Down Expand Up @@ -375,7 +375,7 @@ static int ipc_check_perms(struct ipc_namespace *ns,
* On success, the ipc id is returned.
*/
static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
struct ipc_ops *ops, struct ipc_params *params)
const struct ipc_ops *ops, struct ipc_params *params)
{
struct kern_ipc_perm *ipcp;
int flg = params->flg;
Expand Down Expand Up @@ -678,7 +678,7 @@ struct kern_ipc_perm *ipc_obtain_object_check(struct ipc_ids *ids, int id)
* Common routine called by sys_msgget(), sys_semget() and sys_shmget().
*/
int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids,
struct ipc_ops *ops, struct ipc_params *params)
const struct ipc_ops *ops, struct ipc_params *params)
{
if (params->key == IPC_PRIVATE)
return ipcget_new(ns, ids, ops, params);
Expand Down
2 changes: 1 addition & 1 deletion ipc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static inline bool ipc_valid_object(struct kern_ipc_perm *perm)

struct kern_ipc_perm *ipc_obtain_object_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);
const struct ipc_ops *ops, struct ipc_params *params);
void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
void (*free)(struct ipc_namespace *, struct kern_ipc_perm *));
#endif

0 comments on commit eb66ec4

Please sign in to comment.