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

S2E kprobe support + alternative image generation #510

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions s2e_env/commands/new_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ def add_arguments(self, parser):
help='If a project with the given name already '
'exists, replace it')

parser.add_argument("--debootstrap", action='store_true', required=False, default=False,
help='Enables the use for the all-in-one generic debootstrap image')

def handle(self, *args, **options):
if not validate_arguments(options):
return
Expand Down
15 changes: 9 additions & 6 deletions s2e_env/commands/project_creation/abstract_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _is_valid_image(self, target, os_desc):
# Image helper methods
#

def _select_image(self, target, image=None, download_image=True):
def _select_image(self, target, image=None, download_image=True, debootstrap=False):
"""
Select an image to use for this project.

Expand All @@ -234,17 +234,20 @@ def _select_image(self, target, image=None, download_image=True):
# Don't do any validation on app images yet.
return self._get_or_download_image(img_templates, image, download_image)

if image not in img_templates:
raise CommandError(f'Unknown guest image {image}. Run s2e image_build for a list of supported images.')
if not debootstrap:
if image not in img_templates:
raise CommandError(f'Unknown guest image {image}. Run s2e image_build for a list of supported images.')

supported_images = self.get_usable_images(target, img_templates)
if not supported_images:
raise CommandError('No suitable image available for this target.')

if image not in supported_images:
raise CommandError(f'Chosen image {image} is not compatbile with the target.')
if not debootstrap:
if image not in supported_images:
raise CommandError(f'Chosen image {image} is not compatible with the target.')

check_host_incompatibility(img_templates, base_image_name)

check_host_incompatibility(img_templates, base_image_name, debootstrap)
return self._get_or_download_image(img_templates, image, download_image)

def _guess_image(self, target, img_templates):
Expand Down
7 changes: 5 additions & 2 deletions s2e_env/commands/project_creation/base_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _configure(self, target, *args, **options):
img_desc = self._image_override
else:
img_desc = self._select_image(target, options.get('image'),
options.get('download_image', False))
options.get('download_image', False), options.get("debootstrap"))

# Check architecture consistency (if the target has been specified)
if target.path and not is_valid_arch(target.arch, img_desc['os']):
Expand Down Expand Up @@ -179,7 +179,9 @@ def _configure(self, target, *args, **options):
'enable_tickler': options.get('enable_tickler', False),

'single_path': options.get('single_path', False),
'custom_lua_string': options.get('custom_lua_string', '')
'custom_lua_string': options.get('custom_lua_string', ''),

'debootstrap': options.get('debootstrap', False)
}

# Do some basic analysis on the target (if it exists)
Expand Down Expand Up @@ -352,6 +354,7 @@ def _create_bootstrap(self, project_dir, config):
context = config.copy()
context['target_bootstrap_template'] = self._bootstrap_template
context['image_arch'] = config['image']['os']['arch']
context['debootstrap'] = config['debootstrap']

template = 'bootstrap.sh'
output_path = os.path.join(project_dir, template)
Expand Down
4 changes: 4 additions & 0 deletions s2e_env/templates/bootstrap.linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ function execute_target {
# Nothing more to initialize on Linux
function target_init {
# Start the LinuxMonitor kernel module
{% if debootstrap == true %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think bootstrap.sh could auto-detect the type of Linux distro it's running on. If the kprobe module exists, use it instead of s2e. That would avoid having to pass the debootstrap around.

sudo insmod /root/s2e-kprobe/s2e-`uname -r`/s2e-kprobe.ko > /dev/ttyS0
{% else %}
sudo modprobe s2e
{% endif %}
}

# Returns Linux-specific tools
Expand Down
8 changes: 6 additions & 2 deletions s2e_env/utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def select_best_image(base_templates, image_names):
return image_names[0]


def check_host_incompatibility(base_templates, image_name):
def check_host_incompatibility(base_templates, image_name, debootstrap=False):
"""
Warn users when the selected image may not work properly with binaries
built on the host.
Expand All @@ -280,7 +280,11 @@ def check_host_incompatibility(base_templates, image_name):
id_name, version, _ = distro.linux_distribution(full_distribution_name=False)
id_name = id_name.lower()

tpl = base_templates[image_name]
if not debootstrap:
tpl = base_templates[image_name]
else:
tpl = base_templates['debootstrap']

guest_name = tpl.get('os').get('name')
guest_version = tpl.get('os').get('version')
if guest_name == id_name and guest_version.startswith(version):
Expand Down