aboutsummaryrefslogtreecommitdiffstats
path: root/ipc
diff options
context:
space:
mode:
authorPierre Peiffer <pierre.peiffer@bull.net>2008-04-29 04:00:51 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-29 11:06:13 -0400
commit8f4a3809c18ff3107bdbb1fabe3f4e5d2a928321 (patch)
tree444ec369565052fde4b349c40b610caa69c93a25 /ipc
parent016d7132f246a05e6e34ccba157fa278a96c45ae (diff)
IPC: introduce ipc_update_perm()
The IPC_SET command performs the same permission setting for all IPCs. This patch introduces a common ipc_update_perm() function to update these permissions and makes use of it for all IPCs. Signed-off-by: Pierre Peiffer <pierre.peiffer@bull.net> Acked-by: Serge Hallyn <serue@us.ibm.com> Cc: Nadia Derbey <Nadia.Derbey@bull.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc')
-rw-r--r--ipc/msg.c5
-rw-r--r--ipc/sem.c5
-rw-r--r--ipc/shm.c5
-rw-r--r--ipc/util.c13
-rw-r--r--ipc/util.h1
5 files changed, 17 insertions, 12 deletions
diff --git a/ipc/msg.c b/ipc/msg.c
index 80375bf43d7b..87d8b3852300 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -484,10 +484,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,
484 484
485 msq->q_qbytes = msqid64.msg_qbytes; 485 msq->q_qbytes = msqid64.msg_qbytes;
486 486
487 ipcp->uid = msqid64.msg_perm.uid; 487 ipc_update_perm(&msqid64.msg_perm, ipcp);
488 ipcp->gid = msqid64.msg_perm.gid;
489 ipcp->mode = (ipcp->mode & ~S_IRWXUGO) |
490 (S_IRWXUGO & msqid64.msg_perm.mode);
491 msq->q_ctime = get_seconds(); 488 msq->q_ctime = get_seconds();
492 /* sleeping receivers might be excluded by 489 /* sleeping receivers might be excluded by
493 * stricter permissions. 490 * stricter permissions.
diff --git a/ipc/sem.c b/ipc/sem.c
index df98de290475..e803abec2b08 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -913,10 +913,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid,
913 freeary(ns, ipcp); 913 freeary(ns, ipcp);
914 goto out_up; 914 goto out_up;
915 case IPC_SET: 915 case IPC_SET:
916 ipcp->uid = semid64.sem_perm.uid; 916 ipc_update_perm(&semid64.sem_perm, ipcp);
917 ipcp->gid = semid64.sem_perm.gid;
918 ipcp->mode = (ipcp->mode & ~S_IRWXUGO)
919 | (semid64.sem_perm.mode & S_IRWXUGO);
920 sma->sem_ctime = get_seconds(); 917 sma->sem_ctime = get_seconds();
921 break; 918 break;
922 default: 919 default:
diff --git a/ipc/shm.c b/ipc/shm.c
index 5e296b04bd6b..20e03dfc6adb 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -656,10 +656,7 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,
656 do_shm_rmid(ns, ipcp); 656 do_shm_rmid(ns, ipcp);
657 goto out_up; 657 goto out_up;
658 case IPC_SET: 658 case IPC_SET:
659 ipcp->uid = shmid64.shm_perm.uid; 659 ipc_update_perm(&shmid64.shm_perm, ipcp);
660 ipcp->gid = shmid64.shm_perm.gid;
661 ipcp->mode = (ipcp->mode & ~S_IRWXUGO)
662 | (shmid64.shm_perm.mode & S_IRWXUGO);
663 shp->shm_ctim = get_seconds(); 660 shp->shm_ctim = get_seconds();
664 break; 661 break;
665 default: 662 default:
diff --git a/ipc/util.c b/ipc/util.c
index 7a5d5e393c4b..dc8943aa9719 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -811,6 +811,19 @@ int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids,
811 return ipcget_public(ns, ids, ops, params); 811 return ipcget_public(ns, ids, ops, params);
812} 812}
813 813
814/**
815 * ipc_update_perm - update the permissions of an IPC.
816 * @in: the permission given as input.
817 * @out: the permission of the ipc to set.
818 */
819void ipc_update_perm(struct ipc64_perm *in, struct kern_ipc_perm *out)
820{
821 out->uid = in->uid;
822 out->gid = in->gid;
823 out->mode = (out->mode & ~S_IRWXUGO)
824 | (in->mode & S_IRWXUGO);
825}
826
814#ifdef __ARCH_WANT_IPC_PARSE_VERSION 827#ifdef __ARCH_WANT_IPC_PARSE_VERSION
815 828
816 829
diff --git a/ipc/util.h b/ipc/util.h
index 0e3d79037a2a..12966913ebc6 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -112,6 +112,7 @@ struct kern_ipc_perm *ipc_lock(struct ipc_ids *, int);
112 112
113void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out); 113void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
114void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out); 114void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out);
115void ipc_update_perm(struct ipc64_perm *in, struct kern_ipc_perm *out);
115 116
116#if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__) 117#if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__)
117 /* On IA-64, we always use the "64-bit version" of the IPC structures. */ 118 /* On IA-64, we always use the "64-bit version" of the IPC structures. */