Skip to content

Commit

Permalink
ipc/shm.c: avoid ipc_rcu_putref for failed ipc_addid()
Browse files Browse the repository at this point in the history
Loosely based on a patch from Kees Cook <[email protected]>:
 - id and error can be merged
 - if operations before ipc_addid() fail, then use call_rcu() directly.

The difference is that call_rcu is used for failures after
security_shm_alloc(), to continue to guaranteed an rcu delay for
security_sem_free().

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Manfred Spraul <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
manfred-colorfu authored and torvalds committed Jul 12, 2017
1 parent 2ec55f8 commit a2642f8
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
size_t numpages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
struct file *file;
char name[13];
int id;
vm_flags_t acctflag = 0;

if (size < SHMMIN || size > ns->shm_ctlmax)
Expand Down Expand Up @@ -617,11 +616,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
shp->shm_file = file;
shp->shm_creator = current;

id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni);
if (id < 0) {
error = id;
error = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni);
if (error < 0)
goto no_id;
}

list_add(&shp->shm_clist, &current->sysvshm.shm_clist);

Expand All @@ -643,7 +640,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
user_shm_unlock(size, shp->mlock_user);
fput(file);
no_file:
ipc_rcu_putref(&shp->shm_perm, shm_rcu_free);
call_rcu(&shp->shm_perm.rcu, shm_rcu_free);
return error;
}

Expand Down

0 comments on commit a2642f8

Please sign in to comment.