selinux: avoid atomic_t usage in sidtab
authorOndrej Mosnacek <omosnace@redhat.com>
Wed, 14 Aug 2019 13:33:20 +0000 (15:33 +0200)
committerPaul Moore <paul@paul-moore.com>
Tue, 27 Aug 2019 17:26:13 +0000 (13:26 -0400)
commit116f21bb967fcef1fa360fe591a2947481788020
treeca8651656580e5c8e554128809530a4ed7a2b0ce
parentac5656d8a4cdd93cd2c74355ed12e5617817e0e7
selinux: avoid atomic_t usage in sidtab

As noted in Documentation/atomic_t.txt, if we don't need the RMW atomic
operations, we should only use READ_ONCE()/WRITE_ONCE() +
smp_rmb()/smp_wmb() where necessary (or the combined variants
smp_load_acquire()/smp_store_release()).

This patch converts the sidtab code to use regular u32 for the counter
and reverse lookup cache and use the appropriate operations instead of
atomic_get()/atomic_set(). Note that when reading/updating the reverse
lookup cache we don't need memory barriers as it doesn't need to be
consistent or accurate. We can now also replace some atomic ops with
regular loads (when under spinlock) and stores (for conversion target
fields that are always accessed under the master table's spinlock).

We can now also bump SIDTAB_MAX to U32_MAX as we can use the full u32
range again.

Suggested-by: Jann Horn <jannh@google.com>
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Jann Horn <jannh@google.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/sidtab.c
security/selinux/ss/sidtab.h