Skip to contentSkip to conversation

python/semanage: do not leak an audit fd per logger instance

PATCH Superseded Stephen Smalley 1 participant 1 message Jun 16 SELinux security module

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH v3 1/1 python/semanage: do not leak an audit fd per logger instance

semanageRecords.__init__() constructs a logger() for every instance, and semanage import constructs a fresh object for every line of the import file. With the audit-backed logger class, each logger() opens its own audit netlink socket via audit.audit_open() and never closes it, so a large export/import round-trip leaks one fd per line and can hit RLIMIT_NOFILE.

Open the audit socket once and store it as a class attribute, the same way semanageRecords already caches the semanage handle.

---
v3 drops the setting of self.audit_fd entirely; later references to it will resolve to the class atttribute now.

 python/semanage/seobject.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
python/semanage/seobject.py +5 -1
index 9ef99be3..93c7f690 100644
@@ -106,9 +106,13 @@ try:
     audit.audit_close(audit.audit_open())
 
     class logger:
+        audit_fd = None
 
         def __init__(self):
-            self.audit_fd = audit.audit_open()
+            if logger.audit_fd is None:
+                logger.audit_fd = audit.audit_open()
+
+            self.audit_fd = logger.audit_fd
             self.log_list = []
             self.log_change_list = []
 
Signature · 1 line
2.54.0