Skip to contentSkip to conversation

selinux: replace BUG_ONs with WARN_ONs in avc.c

PATCH Superseded Ondrej Mosnacek 3 participants 4 messages Jan 26, 2019 – Jan 28, 2019 SELinux security module

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux: replace BUG_ONs with WARN_ONs in avc.c

These checks are only guarding against programming errors that could silently grant too many permissions. These cases are better handled with WARN_ON(), since it doesn't really help much to crash the machine in this case.

---
 security/selinux/avc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/selinux/avc.c +2 -2
index 3a27418b20d7..84f108f4100a 100644
@@ -1059,7 +1059,7 @@ int avc_has_extended_perms(struct selinux_state *state,
 	int rc = 0, rc2;
 
 	xp_node = &local_xp_node;
-	BUG_ON(!requested);
+	WARN_ON(!requested);
 
 	rcu_read_lock();
 
@@ -1149,7 +1149,7 @@ inline int avc_has_perm_noaudit(struct selinux_state *state,
 	int rc = 0;
 	u32 denied;
 
-	BUG_ON(!requested);
+	WARN_ON(!requested);
 
 	rcu_read_lock();
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 15 lines · Ondrej Mosnacek

These checks are only guarding against programming errors that could silently grant too many permissions. These cases are better handled with WARN_ON(), since it doesn't really help much to crash the machine in this case.

---
  security/selinux/avc.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
security/selinux/avc.c +0 -0
index 3a27418b20d7..84f108f4100a 100644

security/selinux/avc.c int avc_has_extended_perms(struct selinux_state *state, · line 1062

Quoted 5 lines
security/selinux/avc.c +1 -1
@@ -1059,7 +1059,7 @@ int avc_has_extended_perms(struct selinux_state *state,
  	int rc = 0, rc2;
 
  	xp_node = &local_xp_node;
-	BUG_ON(!requested);
+	WARN_ON(!requested);

Should this be:

	if (WARN_ON(!requested))
		return -EACCES;

security/selinux/avc.c inline int avc_has_perm_noaudit(struct selinux_state *state, · line 1152

Quoted 9 lines
security/selinux/avc.c +1 -1
  	rcu_read_lock();
 
@@ -1149,7 +1149,7 @@ inline int avc_has_perm_noaudit(struct selinux_state *state,
  	int rc = 0;
  	u32 denied;
 
-	BUG_ON(!requested);
+	WARN_ON(!requested);

And likewise

Quoted 4 lines
security/selinux/avc.c +0 -0
  	rcu_read_lock();
 
 
maintainer
#2 lore raw
Quoted 18 lines · Stephen Smalley
Quoted 17 lines · Ondrej Mosnacek

These checks are only guarding against programming errors that could silently grant too many permissions. These cases are better handled with WARN_ON(), since it doesn't really help much to crash the machine in this case.

---
  security/selinux/avc.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
security/selinux/avc.c +0 -0
index 3a27418b20d7..84f108f4100a 100644
@@ -1059,7 +1059,7 @@ int avc_has_extended_perms(struct selinux_state *state,
      int rc = 0, rc2;
 
Quoted 7 lines

security/selinux/avc.c int avc_has_extended_perms(struct selinux_state *state, · line 1062

Quoted 3 lines
security/selinux/avc.c +1 -1
      xp_node = &local_xp_node;
-     BUG_ON(!requested);
+     WARN_ON(!requested);

Should this be:

        if (WARN_ON(!requested))
                return -EACCES;

I think so, it would be bad not to return an error in this case (and the similar one below).

Quoted 16 lines

security/selinux/avc.c inline int avc_has_perm_noaudit(struct selinux_state *state, · line 1152

Quoted 9 lines
security/selinux/avc.c +1 -1
      rcu_read_lock();
 
@@ -1149,7 +1149,7 @@ inline int avc_has_perm_noaudit(struct selinux_state *state,
      int rc = 0;
      u32 denied;
 
-     BUG_ON(!requested);
+     WARN_ON(!requested);

And likewise

Quoted 4 lines
security/selinux/avc.c +0 -0
      rcu_read_lock();
 
 
Signature · 2 lines
paul moore
www.paul-moore.com
#3 lore raw
Quoted 27 lines · Paul Moore
Quoted 18 lines · Stephen Smalley
Quoted 17 lines · Ondrej Mosnacek

These checks are only guarding against programming errors that could silently grant too many permissions. These cases are better handled with WARN_ON(), since it doesn't really help much to crash the machine in this case.

---
  security/selinux/avc.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
security/selinux/avc.c +0 -0
index 3a27418b20d7..84f108f4100a 100644
@@ -1059,7 +1059,7 @@ int avc_has_extended_perms(struct selinux_state *state,
      int rc = 0, rc2;
 
Quoted 7 lines

security/selinux/avc.c int avc_has_extended_perms(struct selinux_state *state, · line 1062

Quoted 3 lines
security/selinux/avc.c +1 -1
      xp_node = &local_xp_node;
-     BUG_ON(!requested);
+     WARN_ON(!requested);

Should this be:

        if (WARN_ON(!requested))
                return -EACCES;
Quoted 2 lines

I think so, it would be bad not to return an error in this case (and the similar one below).

Makes sense... will send a v2 right away.

Quoted 21 lines
Quoted 4 lines
Quoted 4 lines
security/selinux/avc.c +0 -0
      rcu_read_lock();
 
Quoted 13 lines

security/selinux/avc.c inline int avc_has_perm_noaudit(struct selinux_state *state, · line 1152

Quoted 6 lines
security/selinux/avc.c +1 -1
@@ -1149,7 +1149,7 @@ inline int avc_has_perm_noaudit(struct selinux_state *state,
      int rc = 0;
      u32 denied;
 
-     BUG_ON(!requested);
+     WARN_ON(!requested);

And likewise

Quoted 4 lines
security/selinux/avc.c +0 -0
      rcu_read_lock();
 
 

--
paul moore
www.paul-moore.com

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Associate Software Engineer, Security Technologies
Red Hat, Inc.