Skip to contentSkip to conversation

libselinux: audit2why: clear static variables on init failure

PATCH In review Stephen Smalley 2 participants 3 messages Jun 4 – Jun 5 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 libselinux: audit2why: clear static variables on init failure

Clear the boollist and avc after freeing them to avoid potential UAF on a subsequent call.

---
 libselinux/src/audit2why.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
libselinux/src/audit2why.c +3 -2
index 4e3fdc1c..2275ffbd 100644
@@ -275,14 +275,15 @@ static int __policy_init(const char *init_path)
 	return 0;
 
 err:
-	if (boollist)
-		free(boollist);
+	free(boollist);
+	boollist = NULL;
 	if (avc) {
 		if (avc->handle)
 			sepol_handle_destroy(avc->handle);
 		if (avc->policydb)
 			sepol_policydb_free(avc->policydb);
 		free(avc);
+		avc = NULL;
 	}
 	if (pf)
 		sepol_policy_file_free(pf);
Signature · 1 line
2.54.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Stephen Smalley

Clear the boollist and avc after freeing them to avoid potential UAF on a subsequent call.

Quoted 29 lines
---
 libselinux/src/audit2why.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
libselinux/src/audit2why.c +3 -3
index 4e3fdc1c..2275ffbd 100644
@@ -275,14 +275,15 @@ static int __policy_init(const char *init_path)
        return 0;
 
 err:
-       if (boollist)
-               free(boollist);
+       free(boollist);
+       boollist = NULL;
        if (avc) {
                if (avc->handle)
                        sepol_handle_destroy(avc->handle);
                if (avc->policydb)
                        sepol_policydb_free(avc->policydb);
                free(avc);
+               avc = NULL;
        }
        if (pf)
                sepol_policy_file_free(pf);
--

2.54.0

author maintainer
#2 lore raw
Quoted 10 lines · James Carter
Quoted 5 lines · Stephen Smalley

Clear the boollist and avc after freeing them to avoid potential UAF on a subsequent call.

Merged.

Quoted 30 lines
Quoted 30 lines
---
 libselinux/src/audit2why.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
libselinux/src/audit2why.c +3 -3
index 4e3fdc1c..2275ffbd 100644
@@ -275,14 +275,15 @@ static int __policy_init(const char *init_path)
        return 0;
 
 err:
-       if (boollist)
-               free(boollist);
+       free(boollist);
+       boollist = NULL;
        if (avc) {
                if (avc->handle)
                        sepol_handle_destroy(avc->handle);
                if (avc->policydb)
                        sepol_policydb_free(avc->policydb);
                free(avc);
+               avc = NULL;
        }
        if (pf)
                sepol_policy_file_free(pf);
--

2.54.0