Skip to content

Commit

Permalink
ipc/shm: fix shmat() nil address after round-down when remapping
Browse files Browse the repository at this point in the history
shmat()'s SHM_REMAP option forbids passing a nil address for; this is in
fact the very first thing we check for.  Andrea reported that for
SHM_RND|SHM_REMAP cases we can end up bypassing the initial addr check,
but we need to check again if the address was rounded down to nil.  As
of this patch, such cases will return -EINVAL.

Link: http://lkml.kernel.org/r/20180503204934.kk63josdu6u53fbd@linux-n805
Signed-off-by: Davidlohr Bueso <[email protected]>
Reported-by: Andrea Arcangeli <[email protected]>
Cc: Joe Lawrence <[email protected]>
Cc: Manfred Spraul <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Davidlohr Bueso authored and torvalds committed May 26, 2018
1 parent a73ab24 commit 8f89c00
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,9 +1363,17 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg,

if (addr) {
if (addr & (shmlba - 1)) {
if (shmflg & SHM_RND)
if (shmflg & SHM_RND) {
addr &= ~(shmlba - 1); /* round down */
else

/*
* Ensure that the round-down is non-nil
* when remapping. This can happen for
* cases when addr < shmlba.
*/
if (!addr && (shmflg & SHM_REMAP))
goto out;
} else
#ifndef __ARCH_FORCE_SHMLBA
if (addr & ~PAGE_MASK)
#endif
Expand Down

0 comments on commit 8f89c00

Please sign in to comment.