From d5b1d349b868e66a4001c23dae7afa05daaca907 Mon Sep 17 00:00:00 2001 From: Pavel Moravec Date: Wed, 22 Aug 2018 10:35:58 +0200 Subject: [archive] Dont copystat /sys and /proc paths Stop copying extended attributes of files under /sys and /proc that can raise SELinux denials on that attempt. Resolves: #1399 Signed-off-by: Pavel Moravec --- sos/archive.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sos/archive.py b/sos/archive.py index fdf6f9a8..5d99170f 100644 --- a/sos/archive.py +++ b/sos/archive.py @@ -251,16 +251,17 @@ class FileCacheArchive(Archive): pass else: self.log_info("caught '%s' copying '%s'" % (e, src)) - try: - shutil.copystat(src, dest) - except OSError: - # SELinux xattrs in /proc and /sys throw this - pass + # copy file attributes, skip SELinux xattrs for /sys and /proc try: stat = os.stat(src) + if src.startswith("/sys/") or src.startswith("/proc/"): + shutil.copymode(src, dest) + os.utime(dest, ns=(stat.st_atime_ns, stat.st_mtime_ns)) + else: + shutil.copystat(src, dest) os.chown(dest, stat.st_uid, stat.st_gid) except Exception as e: - self.log_debug("caught '%s' setting ownership of '%s'" + self.log_debug("caught '%s' setting attributes of '%s'" % (e, dest)) file_name = "'%s'" % src else: -- cgit