Skip to contentSkip to conversation

selinux: replace BUG_ONs with WARN_ONs in avc.c

PATCH Applied Ondrej Mosnacek 3 participants 3 messages Jan 28, 2019 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
security/selinux/avc.c +4 -2
index 3a27418b20d7..33863298a9b5 100644
@@ -1059,7 +1059,8 @@ int avc_has_extended_perms(struct selinux_state *state,
 	int rc = 0, rc2;
 
 	xp_node = &local_xp_node;
-	BUG_ON(!requested);
+	if (WARN_ON(!requested))
+		return -EACCES;
 
 	rcu_read_lock();
 
@@ -1149,7 +1150,8 @@ inline int avc_has_perm_noaudit(struct selinux_state *state,
 	int rc = 0;
 	u32 denied;
 
-	BUG_ON(!requested);
+	if (WARN_ON(!requested))
+		return -EACCES;
 
 	rcu_read_lock();
 
Signature · 1 line
2.20.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 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.

Quoted 29 lines
---
  security/selinux/avc.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
security/selinux/avc.c +4 -2
index 3a27418b20d7..33863298a9b5 100644
@@ -1059,7 +1059,8 @@ int avc_has_extended_perms(struct selinux_state *state,
  	int rc = 0, rc2;
 
  	xp_node = &local_xp_node;
-	BUG_ON(!requested);
+	if (WARN_ON(!requested))
+		return -EACCES;
 
  	rcu_read_lock();
 
@@ -1149,7 +1150,8 @@ inline int avc_has_perm_noaudit(struct selinux_state *state,
  	int rc = 0;
  	u32 denied;
 
-	BUG_ON(!requested);
+	if (WARN_ON(!requested))
+		return -EACCES;
 
  	rcu_read_lock();
 
maintainer Applied
#2 lore raw
In reply to Ondrej Mosnacek
Quoted 9 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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Merged, thanks.

Quoted 27 lines
security/selinux/avc.c +4 -3
index 3a27418b20d7..33863298a9b5 100644
@@ -1059,7 +1059,8 @@ int avc_has_extended_perms(struct selinux_state *state,
        int rc = 0, rc2;
 
        xp_node = &local_xp_node;
-       BUG_ON(!requested);
+       if (WARN_ON(!requested))
+               return -EACCES;
 
        rcu_read_lock();
 
@@ -1149,7 +1150,8 @@ inline int avc_has_perm_noaudit(struct selinux_state *state,
        int rc = 0;
        u32 denied;
 
-       BUG_ON(!requested);
+       if (WARN_ON(!requested))
+               return -EACCES;
 
        rcu_read_lock();
 
--

2.20.1

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