Davidlohr Bueso
e4243b8062
ipc/sem: play nicer with large nsops allocations
...
Replacing semop()'s kmalloc for kvmalloc was originally proposed by
Manfred on the premise that it can be called for large (than order-1)
sizes. For example, while Oracle recommends setting SEMOPM to a _minimum_
of 100, some distros[1] encourage the setting to be a factor of the amount
of db tasks (PROCESSES), which can get fishy for large systems (easily
going beyond 1000).
[1] An Example of Semaphore Settings
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/sect-Oracle_9i_and_10g_Tuning_Guide-Setting_Semaphores-An_Example_of_Semaphore_Settings.html
So let's just convert this to kvmalloc, just like the rest of the
allocations we do in ipc. While the fallback vmalloc obviously involves
more overhead, this by far the uncommon path, and it's better for the user
than just erroring out with kmalloc.
Link: http://lkml.kernel.org/r/20170803184136.13855-2-dave@stgolabs.net
Signed-off-by: Davidlohr Bueso <dbueso@suse.de >
Cc: Manfred Spraul <manfred@colorfullife.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-09-08 18:26:51 -07:00
Davidlohr Bueso
8419e64a0b
ipc/sem: drop sem_checkid helper
...
... 'tis not used.
Link: http://lkml.kernel.org/r/20170803184136.13855-1-dave@stgolabs.net
Signed-off-by: Davidlohr Bueso <dbueso@suse.de >
Cc: Manfred Spraul <manfred@colorfullife.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-09-08 18:26:51 -07:00
Elena Reshetova
9405c03ee7
ipc: convert kern_ipc_perm.refcount from atomic_t to refcount_t
...
refcount_t type and corresponding API should be used instead of atomic_t
when the variable is used as a reference counter. This allows to avoid
accidental refcounter overflows that might lead to use-after-free
situations.
Link: http://lkml.kernel.org/r/1499417992-3238-4-git-send-email-elena.reshetova@intel.com
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com >
Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com >
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: David Windsor <dwindsor@gmail.com >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
Cc: "Eric W. Biederman" <ebiederm@xmission.com >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: Alexey Dobriyan <adobriyan@gmail.com >
Cc: Serge Hallyn <serge@hallyn.com >
Cc: <arozansk@redhat.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Cc: Manfred Spraul <manfred@colorfullife.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-09-08 18:26:51 -07:00
Elena Reshetova
f74370b86e
ipc: convert sem_undo_list.refcnt from atomic_t to refcount_t
...
refcount_t type and corresponding API should be used instead of atomic_t
when the variable is used as a reference counter. This allows to avoid
accidental refcounter overflows that might lead to use-after-free
situations.
Link: http://lkml.kernel.org/r/1499417992-3238-3-git-send-email-elena.reshetova@intel.com
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com >
Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com >
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: David Windsor <dwindsor@gmail.com >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
Cc: "Eric W. Biederman" <ebiederm@xmission.com >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: Alexey Dobriyan <adobriyan@gmail.com >
Cc: Serge Hallyn <serge@hallyn.com >
Cc: <arozansk@redhat.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Cc: Manfred Spraul <manfred@colorfullife.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-09-08 18:26:51 -07:00
Elena Reshetova
a2e0602c36
ipc: convert ipc_namespace.count from atomic_t to refcount_t
...
refcount_t type and corresponding API should be used instead of atomic_t
when the variable is used as a reference counter. This allows to avoid
accidental refcounter overflows that might lead to use-after-free
situations.
Link: http://lkml.kernel.org/r/1499417992-3238-2-git-send-email-elena.reshetova@intel.com
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com >
Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com >
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: David Windsor <dwindsor@gmail.com >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
Cc: "Eric W. Biederman" <ebiederm@xmission.com >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: Alexey Dobriyan <adobriyan@gmail.com >
Cc: Serge Hallyn <serge@hallyn.com >
Cc: <arozansk@redhat.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Cc: Manfred Spraul <manfred@colorfullife.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-09-08 18:26:51 -07:00
Ingo Molnar
94edf6f3c2
Merge branch 'for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu into core/rcu
...
Pull RCU updates from Paul E. McKenney:
- Removal of spin_unlock_wait()
- SRCU updates
- Torture-test updates
- Documentation updates
- Miscellaneous fixes
- CPU-hotplug fixes
- Miscellaneous non-RCU fixes
Signed-off-by: Ingo Molnar <mingo@kernel.org >
2017-08-21 09:45:19 +02:00
Paul E. McKenney
e0892e086a
ipc: Replace spin_unlock_wait() with lock/unlock pair
...
There is no agreed-upon definition of spin_unlock_wait()'s semantics,
and it appears that all callers could do just as well with a lock/unlock
pair. This commit therefore replaces the spin_unlock_wait() call in
exit_sem() with spin_lock() followed immediately by spin_unlock().
This should be safe from a performance perspective because exit_sem()
is rarely invoked in production.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com >
Cc: Andrew Morton <akpm@linux-foundation.org >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Cc: Will Deacon <will.deacon@arm.com >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Alan Stern <stern@rowland.harvard.edu >
Cc: Andrea Parri <parri.andrea@gmail.com >
Cc: Linus Torvalds <torvalds@linux-foundation.org >
Acked-by: Manfred Spraul <manfred@colorfullife.com >
2017-08-17 08:08:57 -07:00
Kees Cook
ade9f91b32
ipc: add missing container_of()s for randstruct
...
When building with the randstruct gcc plugin, the layout of the IPC
structs will be randomized, which requires any sub-structure accesses to
use container_of(). The proc display handlers were missing the needed
container_of()s since the iterator is passing in the top-level struct
kern_ipc_perm.
This would lead to crashes when running the "lsipc" program after the
system had IPC registered (e.g. after starting up Gnome):
general protection fault: 0000 [#1 ] PREEMPT SMP
...
RIP: 0010:shm_add_rss_swap.isra.1+0x13/0xa0
...
Call Trace:
sysvipc_shm_proc_show+0x5e/0x150
sysvipc_proc_show+0x1a/0x30
seq_read+0x2e9/0x3f0
...
Link: http://lkml.kernel.org/r/20170730205950.GA55841@beast
Fixes: 3859a271a0 ("randstruct: Mark various structs for randomization")
Signed-off-by: Kees Cook <keescook@chromium.org >
Reported-by: Dominik Brodowski <linux@dominikbrodowski.net >
Acked-by: Davidlohr Bueso <dave@stgolabs.net >
Acked-by: Manfred Spraul <manfred@colorfullife.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-08-02 17:16:12 -07:00
Manfred Spraul
62b49c9908
ipc/util.h: update documentation for ipc_getref() and ipc_putref()
...
Now that ipc_rcu_alloc() and ipc_rcu_free() are removed, document when
it is valid to use ipc_getref() and ipc_putref().
Link: http://lkml.kernel.org/r/20170525185107.12869-21-manfred@colorfullife.com
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Cc: Kees Cook <keescook@chromium.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:02 -07:00
Kees Cook
e2029dfeef
ipc/sem: drop __sem_free()
...
The remaining users of __sem_free() can simply call kvfree() instead for
better readability.
[manfred@colorfullife.com: Rediff to keep rcu protection for security_sem_alloc()]
Link: http://lkml.kernel.org/r/20170525185107.12869-20-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:02 -07:00
Kees Cook
fb259c310f
ipc/msg: remove special msg_alloc/free
...
There is nothing special about the msg_alloc/free routines any more, so
remove them to make code more readable.
[manfred@colorfullife.com: Rediff to keep rcu protection for security_msg_queue_alloc()]
Link: http://lkml.kernel.org/r/20170525185107.12869-19-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:02 -07:00
Kees Cook
42e618f77d
ipc/shm: remove special shm_alloc/free
...
There is nothing special about the shm_alloc/free routines any more, so
remove them to make code more readable.
[manfred@colorfullife.com: Rediff, to continue to keep rcu for free calls after a successful security_shm_alloc()]
Link: http://lkml.kernel.org/r/20170525185107.12869-18-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:02 -07:00
Kees Cook
3d3653f973
ipc: move atomic_set() to where it is needed
...
Only after ipc_addid() has succeeded will refcounting be used, so move
initialization into ipc_addid() and remove from open-coded *_alloc()
routines.
Link: http://lkml.kernel.org/r/20170525185107.12869-17-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:02 -07:00
Manfred Spraul
51c23b7b7d
ipc/msg.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_msg_queue_free().
Link: http://lkml.kernel.org/r/20170525185107.12869-16-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 >
2017-07-12 16:26:02 -07:00
Manfred Spraul
a2642f8770
ipc/shm.c: avoid ipc_rcu_putref for failed ipc_addid()
...
Loosely based on a patch from Kees Cook <keescook@chromium.org >:
- 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/20170525185107.12869-15-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 >
2017-07-12 16:26:02 -07:00
Manfred Spraul
2ec55f8024
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 >
2017-07-12 16:26:02 -07:00
Kees Cook
c3f6fb6fe4
ipc/util: drop ipc_rcu_alloc()
...
No callers remain for ipc_rcu_alloc(). Drop the function.
[manfred@colorfullife.com: Rediff because the memset was temporarily inside ipc_rcu_free()]
Link: http://lkml.kernel.org/r/20170525185107.12869-13-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Kees Cook <keescook@chromium.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:02 -07:00
Kees Cook
52f908904e
ipc/msg: avoid ipc_rcu_alloc()
...
Instead of using ipc_rcu_alloc() which only performs the refcount bump,
open code it. This also allows for msg_queue structure layout to be
randomized in the future.
Link: http://lkml.kernel.org/r/20170525185107.12869-12-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:02 -07:00
Kees Cook
3e0c24042e
ipc/shm: avoid ipc_rcu_alloc()
...
Instead of using ipc_rcu_alloc() which only performs the refcount bump,
open code it. This also allows for shmid_kernel structure layout to be
randomized in the future.
Link: http://lkml.kernel.org/r/20170525185107.12869-11-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:01 -07:00
Kees Cook
101ede01df
ipc/sem: avoid ipc_rcu_alloc()
...
Instead of using ipc_rcu_alloc() which only performs the refcount bump,
open code it to perform better sem-specific checks. This also allows
for sem_array structure layout to be randomized in the future.
[manfred@colorfullife.com: Rediff, because the memset was temporarily inside ipc_rcu_alloc()]
Link: http://lkml.kernel.org/r/20170525185107.12869-10-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:01 -07:00
Kees Cook
5ccc8fb54f
ipc/util: drop ipc_rcu_free()
...
There are no more callers of ipc_rcu_free(), so remove it.
Link: http://lkml.kernel.org/r/20170525185107.12869-9-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:01 -07:00
Kees Cook
9ef5932f8a
ipc/msg: do not use ipc_rcu_free()
...
Avoid using ipc_rcu_free, since it just re-finds the original structure
pointer. For the pre-list-init failure path, there is no RCU needed,
since it was just allocated. It can be directly freed.
Link: http://lkml.kernel.org/r/20170525185107.12869-8-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:01 -07:00
Kees Cook
66470b1817
ipc/shm: do not use ipc_rcu_free()
...
Avoid using ipc_rcu_free, since it just re-finds the original structure
pointer. For the pre-list-init failure path, there is no RCU needed,
since it was just allocated. It can be directly freed.
Link: http://lkml.kernel.org/r/20170525185107.12869-7-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:01 -07:00
Kees Cook
1b4654ef72
ipc/sem: do not use ipc_rcu_free()
...
Avoid using ipc_rcu_free, since it just re-finds the original structure
pointer. For the pre-list-init failure path, there is no RCU needed,
since it was just allocated. It can be directly freed.
Link: http://lkml.kernel.org/r/20170525185107.12869-6-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:01 -07:00
Kees Cook
f8dbe8d290
ipc: drop non-RCU allocation
...
The only users of ipc_alloc() were ipc_rcu_alloc() and the on-heap
sem_io fall-back memory. Better to just open-code these to make things
easier to read.
[manfred@colorfullife.com: Rediff due to inclusion of memset() into ipc_rcu_alloc()]
Link: http://lkml.kernel.org/r/20170525185107.12869-5-manfred@colorfullife.com
Signed-off-by: Kees Cook <keescook@chromium.org >
Signed-off-by: Manfred Spraul <manfred@colorfullife.com >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2017-07-12 16:26:01 -07:00