ipc/shm.c: check for overflows of shm_tot
[cascardo/linux.git] / ipc / shm.c
index dda8f1f..9e51bf2 100644 (file)
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -493,7 +493,8 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
        if (size < SHMMIN || size > ns->shm_ctlmax)
                return -EINVAL;
 
-       if (ns->shm_tot + numpages > ns->shm_ctlall)
+       if (ns->shm_tot + numpages < ns->shm_tot ||
+                       ns->shm_tot + numpages > ns->shm_ctlall)
                return -ENOSPC;
 
        shp = ipc_rcu_alloc(sizeof(*shp));