userns: Convert ipc to use kuid and kgid where appropriate
[firefly-linux-kernel-4.4.55.git] / ipc / shm.c
index 41c1285d697a6f19a3c9b945691346c9b45ade47..dff40c9f73c9df09544c057f7325004726d27715 100644 (file)
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -758,7 +758,9 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,
                do_shm_rmid(ns, ipcp);
                goto out_up;
        case IPC_SET:
-               ipc_update_perm(&shmid64.shm_perm, ipcp);
+               err = ipc_update_perm(&shmid64.shm_perm, ipcp);
+               if (err)
+                       goto out_unlock;
                shp->shm_ctim = get_seconds();
                break;
        default:
@@ -893,10 +895,10 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
                audit_ipc_obj(&(shp->shm_perm));
 
                if (!ns_capable(ns->user_ns, CAP_IPC_LOCK)) {
-                       uid_t euid = current_euid();
+                       kuid_t euid = current_euid();
                        err = -EPERM;
-                       if (euid != shp->shm_perm.uid &&
-                           euid != shp->shm_perm.cuid)
+                       if (!uid_eq(euid, shp->shm_perm.uid) &&
+                           !uid_eq(euid, shp->shm_perm.cuid))
                                goto out_unlock;
                        if (cmd == SHM_LOCK && !rlimit(RLIMIT_MEMLOCK))
                                goto out_unlock;
@@ -953,7 +955,8 @@ out:
  * "raddr" thing points to kernel space, and there has to be a wrapper around
  * this.
  */
-long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
+long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
+             unsigned long shmlba)
 {
        struct shmid_kernel *shp;
        unsigned long addr;
@@ -973,9 +976,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
        if (shmid < 0)
                goto out;
        else if ((addr = (ulong)shmaddr)) {
-               if (addr & (SHMLBA-1)) {
+               if (addr & (shmlba - 1)) {
                        if (shmflg & SHM_RND)
-                               addr &= ~(SHMLBA-1);       /* round down */
+                               addr &= ~(shmlba - 1);     /* round down */
                        else
 #ifndef __ARCH_FORCE_SHMLBA
                                if (addr & ~PAGE_MASK)
@@ -1107,7 +1110,7 @@ SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg)
        unsigned long ret;
        long err;
 
-       err = do_shmat(shmid, shmaddr, shmflg, &ret);
+       err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
        if (err)
                return err;
        force_successful_syscall_return();
@@ -1219,6 +1222,7 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
 #ifdef CONFIG_PROC_FS
 static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
 {
+       struct user_namespace *user_ns = seq_user_ns(s);
        struct shmid_kernel *shp = it;
        unsigned long rss = 0, swp = 0;
 
@@ -1241,10 +1245,10 @@ static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
                          shp->shm_cprid,
                          shp->shm_lprid,
                          shp->shm_nattch,
-                         shp->shm_perm.uid,
-                         shp->shm_perm.gid,
-                         shp->shm_perm.cuid,
-                         shp->shm_perm.cgid,
+                         from_kuid_munged(user_ns, shp->shm_perm.uid),
+                         from_kgid_munged(user_ns, shp->shm_perm.gid),
+                         from_kuid_munged(user_ns, shp->shm_perm.cuid),
+                         from_kgid_munged(user_ns, shp->shm_perm.cgid),
                          shp->shm_atim,
                          shp->shm_dtim,
                          shp->shm_ctim,