#!/usr/bin/env python3

import os.path
import sys

# File in /sys seem to vary between Linux systems. Thus, try a few candidates
# and use the first one that exists. What we want is any file under /sys with
# permissions root:root -rw-------.
sys_file = None
for f in ("/sys/devices/cpu/rdpmc",
          "/sys/kernel/mm/page_idle/bitmap",
          "/sys/kernel/slab/request_sock_TCP/red_zone"):
   if (os.path.exists(f)):
      sys_file = f
      break

if (sys_file is None):
   print("ERROR\tno test candidates in /sys exist")
   sys.exit(1)

problem_ct = 0
for f in ("/dev/mem", "/proc/kcore", sys_file):
   try:
      open(f, "rb").read(1)
      print("RISK\t%s: read allowed" % f)
      problem_ct += 1
   except PermissionError:
      print("SAFE\t%s: read not allowed" % f)
   except OSError as x:
      print("ERROR\t%s: exception: %s" % (f, x))
      problem_ct += 1

sys.exit(problem_ct != 0)

#!/usr/bin/env python3

import os.path
import sys

# File in /sys seem to vary between Linux systems. Thus, try a few candidates
# and use the first one that exists. What we want is any file under /sys with
# permissions root:root -rw-------.
sys_file = None
for f in ("/sys/devices/cpu/rdpmc",
          "/sys/kernel/mm/page_idle/bitmap",
          "/sys/kernel/slab/request_sock_TCP/red_zone",
	  "sys/kernel/debug/kprobes/enabled"):
   if (os.path.exists(f)):
      sys_file = f
      break

if (sys_file is None):
   print("ERROR\tno test candidates in /sys exist")
   sys.exit(1)

problem_ct = 0
for f in ("/dev/mem", "/proc/kcore", sys_file):
   try:
      open(f, "rb").read(1)
      print("RISK\t%s: read allowed" % f)
      problem_ct += 1
   except PermissionError:
      print("SAFE\t%s: read not allowed" % f)
   except OSError as x:
      print("ERROR\t%s: exception: %s" % (f, x))
      problem_ct += 1

sys.exit(problem_ct != 0)

Add a further path inside /sys to test
Add a further path inside /sys to test

On (at least) a Debian "stretch" system, the charliecloud image contains
none of the tested paths inside /sys. This patch adds one that does
exist there.

Signed-off-by: Matthew Vernon <d2337109245c21c6e400ba5f0470cfb01956d9f2@sanger.ac.uk>
