Merge branch 'next'

This commit is contained in:
Peter Korsgaard
2019-09-03 15:03:02 +02:00
250 changed files with 1196 additions and 2213 deletions

View File

@@ -55,6 +55,15 @@ def download(dldir, filename):
return finalpath
def run_cmd_on_host(builddir, cmd):
"""Call subprocess.check_output and return the text output."""
out = subprocess.check_output(cmd,
stderr=open(os.devnull, "w"),
cwd=builddir,
env={"LANG": "C"})
return out
def get_elf_arch_tag(builddir, prefix, fpath, tag):
"""
Runs the cross readelf on 'fpath', then extracts the value of tag 'tag'.
@@ -66,7 +75,7 @@ def get_elf_arch_tag(builddir, prefix, fpath, tag):
"""
cmd = ["host/bin/{}-readelf".format(prefix),
"-A", os.path.join("target", fpath)]
out = subprocess.check_output(cmd, cwd=builddir, env={"LANG": "C"})
out = run_cmd_on_host(builddir, cmd)
regexp = re.compile("^ {}: (.*)$".format(tag))
for line in out.splitlines():
m = regexp.match(line)
@@ -93,7 +102,7 @@ def get_elf_prog_interpreter(builddir, prefix, fpath):
"""
cmd = ["host/bin/{}-readelf".format(prefix),
"-l", os.path.join("target", fpath)]
out = subprocess.check_output(cmd, cwd=builddir, env={"LANG": "C"})
out = run_cmd_on_host(builddir, cmd)
regexp = re.compile("^ *\[Requesting program interpreter: (.*)\]$")
for line in out.splitlines():
m = regexp.match(line)

View File

@@ -1,5 +1,4 @@
import os
import subprocess
import json
import infra.basetest
@@ -30,10 +29,7 @@ class TestHardeningBase(infra.basetest.BRTest):
"--file={}".format(filepath)]
# Checksec is being used for elf file analysis only. There are no
# assumptions of target/run-time checks as part of this testing.
ret = subprocess.check_output(cmd,
stderr=open(os.devnull, "w"),
cwd=self.builddir,
env={"LANG": "C"})
ret = infra.run_cmd_on_host(self.builddir, cmd)
return json.loads(ret)

View File

@@ -0,0 +1,36 @@
import os
import infra.basetest
from crypt import crypt
class TestRootPassword(infra.basetest.BRTest):
password = "foo"
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
"""
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ENABLE_ROOT_LOGIN=y
BR2_TARGET_GENERIC_ROOT_PASSWD="{}"
""".format(password)
def test_run(self):
# 1. Test by looking hash in the /etc/shadow
shadow = os.path.join(self.builddir, "target", "etc", "shadow")
with open(shadow, "r") as f:
users = f.readlines()
for user in users:
s = user.split(":")
n, h = s[0], s[1]
if n == "root":
# Fail if the account is disabled or no password is required
self.assertTrue(h not in ["", "*"])
# Fail if the hash isn't right
self.assertEqual(crypt(self.password, h), h)
# 2. Test by attempting to login
cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
try:
self.emulator.boot(arch="armv7", kernel="builtin",
options=["-initrd", cpio_file])
self.emulator.login(self.password)
except SystemError:
self.fail("Unable to login with the password")

View File

@@ -1,5 +1,4 @@
import os
import subprocess
import infra.basetest
@@ -15,10 +14,7 @@ CHECK_FS_TYPE_CMD = "mount | grep '/dev/root on / type {}'"
def dumpe2fs_run(builddir, image):
cmd = ["host/sbin/dumpe2fs", os.path.join("images", image)]
ret = subprocess.check_output(cmd,
stderr=open(os.devnull, "w"),
cwd=builddir,
env={"LANG": "C"})
ret = infra.run_cmd_on_host(builddir, cmd)
return ret.strip().splitlines()

View File

@@ -1,5 +1,4 @@
import os
import subprocess
import infra.basetest
@@ -29,9 +28,7 @@ class TestF2FS(infra.basetest.BRTest):
def test_run(self):
img = os.path.join(self.builddir, "images", "rootfs.f2fs")
out = subprocess.check_output(["host/sbin/dump.f2fs", img],
cwd=self.builddir,
env={"LANG": "C"})
out = infra.run_cmd_on_host(self.builddir, ["host/sbin/dump.f2fs", img])
out = out.splitlines()
prop = dumpf2fs_getprop(out, "Info: total sectors")
self.assertEqual(prop, "262144 (128 MB)")

View File

@@ -1,5 +1,4 @@
import os
import subprocess
import infra.basetest
@@ -30,9 +29,8 @@ class TestJffs2(infra.basetest.BRTest):
def test_run(self):
img = os.path.join(self.builddir, "images", "rootfs.jffs2")
out = subprocess.check_output(["host/sbin/jffs2dump", "-c", img],
cwd=self.builddir,
env={"LANG": "C"})
cmd = ["host/sbin/jffs2dump", "-c", img]
out = infra.run_cmd_on_host(self.builddir, cmd)
out = out.splitlines()
self.assertTrue(jffs2dump_find_file(out, "busybox"))

View File

@@ -15,9 +15,7 @@ class TestSquashfs(infra.basetest.BRTest):
def test_run(self):
unsquashfs_cmd = ["host/bin/unsquashfs", "-s", "images/rootfs.squashfs"]
out = subprocess.check_output(unsquashfs_cmd,
cwd=self.builddir,
env={"LANG": "C"})
out = infra.run_cmd_on_host(self.builddir, unsquashfs_cmd)
out = out.splitlines()
self.assertEqual(out[0],
"Found a valid SQUASHFS 4:0 superblock on images/rootfs.squashfs.")

View File

@@ -21,10 +21,9 @@ class TestUbi(infra.basetest.BRTest):
# To be investigated.
def test_run(self):
img = os.path.join(self.builddir, "images", "rootfs.ubi")
out = subprocess.check_output(["file", img],
cwd=self.builddir,
env={"LANG": "C"})
out = infra.run_cmd_on_host(self.builddir, ["file", img])
out = out.splitlines()
self.assertIn("UBI image, version 1", out[0])
subprocess.call(["truncate", "-s 128M", img])

View File

@@ -9,6 +9,6 @@ data = {
}
}
serialized = cbor.dumps(data)
print(serialized)
print(serialized.decode(errors="ignore"))
with open("/tmp/data.cbor", "wb") as f:
f.write(serialized)