selinux: check sidtab limit before adding a new entry
authorOndrej Mosnacek <omosnace@redhat.com>
Tue, 23 Jul 2019 06:50:59 +0000 (08:50 +0200)
committerPaul Moore <paul@paul-moore.com>
Wed, 24 Jul 2019 15:13:34 +0000 (11:13 -0400)
We need to error out when trying to add an entry above SIDTAB_MAX in
sidtab_reverse_lookup() to avoid overflow on the odd chance that this
happens.

Cc: stable@vger.kernel.org
Fixes: ee1a84fdfeed ("selinux: overhaul sidtab to fix bug and improve performance")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/sidtab.c

index e63a90ff27285fdd885240d03ea720dd9972d063..1f0a6eaa2d6a139188b88803aa43c8c9eb445792 100644 (file)
@@ -286,6 +286,11 @@ static int sidtab_reverse_lookup(struct sidtab *s, struct context *context,
                ++count;
        }
 
+       /* bail out if we already reached max entries */
+       rc = -EOVERFLOW;
+       if (count >= SIDTAB_MAX)
+               goto out_unlock;
+
        /* insert context into new entry */
        rc = -ENOMEM;
        dst = sidtab_do_lookup(s, count, 1);