Commit 1376327c authored by Manfred Spraul's avatar Manfred Spraul Committed by Linus Torvalds

ipc/shm.c: check for integer overflow during shmget.

SHMMAX is the upper limit for the size of a shared memory segment, counted
in bytes.  The actual allocation is that size, rounded up to the next full

Add a check that prevents the creation of segments where the rounded up
size causes an integer overflow.
Signed-off-by: default avatarManfred Spraul <>
Acked-by: default avatarDavidlohr Bueso <>
Acked-by: default avatarKOSAKI Motohiro <>
Acked-by: default avatarMichael Kerrisk <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 09c6eb1f
......@@ -493,6 +493,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
if (size < SHMMIN || size > ns->shm_ctlmax)
return -EINVAL;
if (numpages << PAGE_SHIFT < size)
return -ENOSPC;
if (ns->shm_tot + numpages < ns->shm_tot ||
ns->shm_tot + numpages > ns->shm_ctlall)
return -ENOSPC;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment