diff options
author | Manfred Spraul <manfred@colorfullife.com> | 2017-07-12 17:35:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-12 19:26:02 -0400 |
commit | 2ec55f8024db859d70f14c26e91ca044328dd50d (patch) | |
tree | 8e37263fd21347b0f173d38697f856547ea829b7 /ipc | |
parent | c3f6fb6fe4e638a58eae558cb209c463cd46c2fc (diff) |
ipc/sem.c: avoid ipc_rcu_putref for failed ipc_addid()
Loosely based on a patch from Kees Cook <keescook@chromium.org>:
- id and retval can be merged
- if ipc_addid() fails, then use call_rcu() directly.
The difference is that call_rcu is used for failed ipc_addid() calls, to
continue to guaranteed an rcu delay for security_sem_free().
Link: http://lkml.kernel.org/r/20170525185107.12869-14-manfred@colorfullife.com
Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/sem.c | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -479,7 +479,6 @@ static struct sem_array *sem_alloc(size_t nsems) | |||
479 | */ | 479 | */ |
480 | static int newary(struct ipc_namespace *ns, struct ipc_params *params) | 480 | static int newary(struct ipc_namespace *ns, struct ipc_params *params) |
481 | { | 481 | { |
482 | int id; | ||
483 | int retval; | 482 | int retval; |
484 | struct sem_array *sma; | 483 | struct sem_array *sma; |
485 | key_t key = params->key; | 484 | key_t key = params->key; |
@@ -520,10 +519,10 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params) | |||
520 | sma->sem_nsems = nsems; | 519 | sma->sem_nsems = nsems; |
521 | sma->sem_ctime = get_seconds(); | 520 | sma->sem_ctime = get_seconds(); |
522 | 521 | ||
523 | id = ipc_addid(&sem_ids(ns), &sma->sem_perm, ns->sc_semmni); | 522 | retval = ipc_addid(&sem_ids(ns), &sma->sem_perm, ns->sc_semmni); |
524 | if (id < 0) { | 523 | if (retval < 0) { |
525 | ipc_rcu_putref(&sma->sem_perm, sem_rcu_free); | 524 | call_rcu(&sma->sem_perm.rcu, sem_rcu_free); |
526 | return id; | 525 | return retval; |
527 | } | 526 | } |
528 | ns->used_sems += nsems; | 527 | ns->used_sems += nsems; |
529 | 528 | ||