python/semanage: do not leak an audit fd per logger instance
Stephen Smalley
maintainerPATCH v2 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.
Signed-off-by Stephen Smalley <[email protected]>
---
v2 fixes the code to set logger.audit_fd exactly once and then assign self.audit_fd from it.
python/semanage/seobject.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
python/semanage/seobject.py +5 -1
@@ -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