Commit 8f4a3809c18ff3107bdbb1fabe3f4e5d2a928321

Authored by Pierre Peiffer
Committed by Linus Torvalds
1 parent 016d7132f2

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>

Showing 5 changed files with 17 additions and 12 deletions Side-by-side Diff

... ... @@ -484,10 +484,7 @@
484 484  
485 485 msq->q_qbytes = msqid64.msg_qbytes;
486 486  
487   - ipcp->uid = msqid64.msg_perm.uid;
488   - ipcp->gid = msqid64.msg_perm.gid;
489   - ipcp->mode = (ipcp->mode & ~S_IRWXUGO) |
490   - (S_IRWXUGO & msqid64.msg_perm.mode);
  487 + ipc_update_perm(&msqid64.msg_perm, ipcp);
491 488 msq->q_ctime = get_seconds();
492 489 /* sleeping receivers might be excluded by
493 490 * stricter permissions.
... ... @@ -913,10 +913,7 @@
913 913 freeary(ns, ipcp);
914 914 goto out_up;
915 915 case IPC_SET:
916   - ipcp->uid = semid64.sem_perm.uid;
917   - ipcp->gid = semid64.sem_perm.gid;
918   - ipcp->mode = (ipcp->mode & ~S_IRWXUGO)
919   - | (semid64.sem_perm.mode & S_IRWXUGO);
  916 + ipc_update_perm(&semid64.sem_perm, ipcp);
920 917 sma->sem_ctime = get_seconds();
921 918 break;
922 919 default:
... ... @@ -656,10 +656,7 @@
656 656 do_shm_rmid(ns, ipcp);
657 657 goto out_up;
658 658 case IPC_SET:
659   - ipcp->uid = shmid64.shm_perm.uid;
660   - ipcp->gid = shmid64.shm_perm.gid;
661   - ipcp->mode = (ipcp->mode & ~S_IRWXUGO)
662   - | (shmid64.shm_perm.mode & S_IRWXUGO);
  659 + ipc_update_perm(&shmid64.shm_perm, ipcp);
663 660 shp->shm_ctim = get_seconds();
664 661 break;
665 662 default:
... ... @@ -811,6 +811,19 @@
811 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 + */
  819 +void 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 827 #ifdef __ARCH_WANT_IPC_PARSE_VERSION
815 828  
816 829  
... ... @@ -112,6 +112,7 @@
112 112  
113 113 void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
114 114 void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out);
  115 +void ipc_update_perm(struct ipc64_perm *in, struct kern_ipc_perm *out);
115 116  
116 117 #if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__)
117 118 /* On IA-64, we always use the "64-bit version" of the IPC structures. */