Skip to contentSkip to conversation

selinux: check sidtab limit before adding a new entry

PATCH In review Ondrej Mosnacek 3 participants 3 messages Jul 23, 2019 – Jul 24, 2019 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selinux: check sidtab limit before adding a new entry

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.

Fixes ee1a84fdfeed ("selinux: overhaul sidtab to fix bug and improve performance")
---
 security/selinux/ss/sidtab.c | 5 +++++
 1 file changed, 5 insertions(+)
security/selinux/ss/sidtab.c +5 -0
index e63a90ff2728..1f0a6eaa2d6a 100644
@@ -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);
Signature · 1 line
2.21.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Ondrej Mosnacek

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.

Fixes ee1a84fdfeed ("selinux: overhaul sidtab to fix bug and improve performance")

-Kees

Quoted 23 lines
---
 security/selinux/ss/sidtab.c | 5 +++++
 1 file changed, 5 insertions(+)
security/selinux/ss/sidtab.c +5 -0
index e63a90ff2728..1f0a6eaa2d6a 100644
@@ -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);
Signature · 1 line
2.21.0
Signature · 1 line
Kees Cook
maintainer
#2 lore raw
In reply to Ondrej Mosnacek
Quoted 10 lines · Ondrej Mosnacek

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.

Fixes ee1a84fdfeed ("selinux: overhaul sidtab to fix bug and improve performance")
---
 security/selinux/ss/sidtab.c | 5 +++++
 1 file changed, 5 insertions(+)

Thanks. This looks like -stable material to me so I've marked it as such and merged it into selinux/stable-5.3; assuming it passes testing, and as long as I don't hear any objections, I'll send it up to Linus later this week.

Quoted 18 lines
security/selinux/ss/sidtab.c +5 -1
index e63a90ff2728..1f0a6eaa2d6a 100644
@@ -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);
--

2.21.0

Signature · 2 lines
paul moore
www.paul-moore.com