Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[device/quanta] Mitigation for security vulnerability #11867

Merged
merged 13 commits into from
Oct 19, 2022
43 changes: 25 additions & 18 deletions device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ def show_log(txt):
return


def exec_cmd(cmd, show):
def exec_cmd(cmd_args, out_file, show):
cmd = ' '.join(cmd_args) + ' > ' + out_file
logging.info('Run :'+cmd)
try:
output = subprocess.check_output(cmd, shell=True, universal_newlines=True)
show_log(cmd + "output:"+str(output))
with open(out_file, 'w') as f:
output = subprocess.run(cmd_args, stdout=f, universal_newlines=True, check=True).stdout
show_log(cmd + "output:"+str(output))
except subprocess.CalledProcessError as e:
logging.info("Failed :"+cmd)
if show:
Expand All @@ -40,13 +42,18 @@ def my_log(txt):
return


def log_os_system(cmd, show):
def log_os_system(cmd1_args, cmd2_args, show):
cmd = ' '.join(cmd1_args) + ' | ' + ' '.join(cmd2_args)
logging.info('Run :'+cmd)
status = 1
output = ""
try:
output = subprocess.check_output(cmd, shell=True, universal_newlines=True)
my_log(cmd + "output:"+str(output))
with subprocess.Popen(cmd1_args, universal_newlines=True, stdout=subprocess.PIPE) as p1:
with subprocess.Popen(cmd2_args, universal_newlines=True, stdin=p1.stdout, stdout=subprocess.PIPE) as p2:
output = p2.communicate()[0]
if p2.returncode == 1:
raise subprocess.CalledProcessError(returncode=p2.returncode, cmd=cmd, output=output)
my_log(cmd + "output:"+str(output))
except subprocess.CalledProcessError as e:
logging.info('Failed :'+cmd)
if show:
Expand All @@ -55,28 +62,28 @@ def log_os_system(cmd, show):


def gpio16_exist():
ls = log_os_system("ls /sys/class/gpio/ | grep gpio16", 0)
ls = log_os_system(["ls", "/sys/class/gpio/"], ["grep", "gpio16"], 0)
logging.info('mods:'+ls)
if len(ls) == 0:
return False


def gpio17_exist():
ls = log_os_system("ls /sys/class/gpio/ | grep gpio17", 0)
ls = log_os_system(["ls", "/sys/class/gpio/"], ["grep", "gpio17"], 0)
logging.info('mods:'+ls)
if len(ls) == 0:
return False


def gpio19_exist():
ls = log_os_system("ls /sys/class/gpio/ | grep gpio19", 0)
ls = log_os_system(["ls", "/sys/class/gpio/"], ["grep", "gpio19"], 0)
logging.info('mods:'+ls)
if len(ls) == 0:
return False


def gpio20_exist():
ls = log_os_system("ls /sys/class/gpio/ | grep gpio20", 0)
ls = log_os_system(["ls", "/sys/class/gpio/"], ["grep", "gpio20"], 0)
logging.info('mods:'+ls)
if len(ls) == 0:
return False
Expand All @@ -95,20 +102,20 @@ def __init__(self):
PsuBase.__init__(self)

if gpio16_exist() == False:
output = exec_cmd("echo 16 > /sys/class/gpio/export ", 1)
output = exec_cmd("echo in > /sys/class/gpio/gpio16/direction ", 1)
output = exec_cmd(["echo", "16"], "/sys/class/gpio/export", 1)
output = exec_cmd(["echo", "in"], "/sys/class/gpio/gpio16/direction", 1)

if gpio17_exist() == False:
output = exec_cmd("echo 17 > /sys/class/gpio/export ", 1)
output = exec_cmd("echo in > /sys/class/gpio/gpio17/direction ", 1)
output = exec_cmd(["echo", "17"], "/sys/class/gpio/export", 1)
output = exec_cmd(["echo", "in"], "/sys/class/gpio/gpio17/direction", 1)

if gpio19_exist() == False:
output = exec_cmd("echo 19 > /sys/class/gpio/export ", 1)
output = exec_cmd("echo in > /sys/class/gpio/gpio19/direction ", 1)
output = exec_cmd(["echo", "19"], "/sys/class/gpio/export", 1)
output = exec_cmd(["echo", "in"], "/sys/class/gpio/gpio19/direction", 1)

if gpio20_exist() == False:
output = exec_cmd("echo 20 > /sys/class/gpio/export ", 1)
output = exec_cmd("echo in > /sys/class/gpio/gpio20/direction ", 1)
output = exec_cmd(["echo", "20"], "/sys/class/gpio/export", 1)
output = exec_cmd(["echo", "in"], "/sys/class/gpio/gpio20/direction", 1)

# Get sysfs attribute
def get_attr_value(self, attr_path):
Expand Down