Skip to content

Integrate Fuzz Introspector with coverage build#7060

Closed
Navidem wants to merge 2 commits intomasterfrom
FI_integration
Closed

Integrate Fuzz Introspector with coverage build#7060
Navidem wants to merge 2 commits intomasterfrom
FI_integration

Conversation

@Navidem
Copy link
Copy Markdown
Contributor

@Navidem Navidem commented Dec 23, 2021

Added build steps to the coverage build to integrate fuzz intrsopsector.

@Navidem Navidem requested a review from oliverchang January 5, 2022 22:46


def get_fuzz_introspector_steps(project, project_name, base_images_project,
config, coverage_url):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a docstring.

def get_fuzz_introspector_steps(project, project_name, base_images_project,
config, coverage_url):
build_steps = []
FI_dir = '/workspace/fuzz-introspector/'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use the full name. i.e. FUZZ_INTROSPECTOR_DIR, and put it above globally together with the other constants.

config, coverage_url):
build_steps = []
FI_dir = '/workspace/fuzz-introspector/'
oss_integration_dir = 'oss_fuzz_integration/'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also, let's not hardcode '/' in the directory constants.

Use os.path.join where needed. In this case though, we can skip the separator completely and just do

oss_fuzz_integration_dir = 'oss_fuzz_integration'

return build_steps


def get_fuzz_introspector_steps(project, project_name, base_images_project,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please write a test for this as well. See the existing build_and_run_coverage_test.py file for examples.

'args': [
'bash', '-c',
(f'cd {FI_dir} && cd {oss_integration_dir}'
' && sed -i \'s/\.\/infra\/base\-images\/all.sh/#\.\/infra\/base\-images\/all.sh/\''
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is very hacky and fragile.

Let's upstream changes and do things in the main oss-fuzz repo where we can rather than using sed.

Also is this actually still needed when we are building the customized build images in the base images build function?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+++1.
Also I don't like that this is relying on all.sh. As far as I know all.sh is meant for local development.

#adjust coverage url
cov_url_escaped = coverage_url.replace("/", "\/").replace(":", "\:")
set_cov_url = (
f'sed -i \'s/http\:\/\/localhost\:8008\/covreport\/linux/{cov_url_escaped}/\''
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this needed? Good to explain with a comment in cases like this.

Also, is there a better way to do this that doesn't involve using sed?

'HOME': '/root',
'OUT': build.out,
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: remove unnecessary change.

def get_compile_step(project, build, env, parallel):
"""Returns the GCB step for compiling |projects| fuzzers using |env|. The type
of build is specified by |build|."""
set_git_repo_env = '' #do nothing
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

no need for the comment here.

set_git_repo_env = '' #do nothing
if build.sanitizer == 'instrumentor':
set_git_repo_env = (
' && export GITHUB_REPO=$(grep -P -o "\S+github.com\S+" /workspace/oss-fuzz/projects/'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we do this in a less hacky way?

It's used by the helper.py script right?

We can instead modify the helper.py script to set this based on the main_repo property in project.yaml. e.g.

main_repo: 'https://github.com/alembic/alembic'
. Let's do all this in another PR which upstreams the patches from fuzz introspector.

This is slightly different from how the existing patch does it: https://github.com/ossf/fuzz-introspector/blob/a49f0ca54103e6dc0177700d22a166a727683334/oss_fuzz_integration/oss-fuzz-patches.diff#L194 but it's less hacky.

latest_report_info_url,
LATEST_REPORT_INFO_CONTENT_TYPE))

#currently fuzz introspector only supports c and c++
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

add a space after all '#'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And start every comment with a capital letter and end them with punctuation marks.


#currently fuzz introspector only supports c and c++
if project.fuzzing_language in ['c', 'c++']:
#removes index.html from the end of url
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

here too.

#currently fuzz introspector only supports c and c++
if project.fuzzing_language in ['c', 'c++']:
#removes index.html from the end of url
coverage_url = bucket.html_report_url[:-11]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what is -11? either calculate this from a len(CONSTANT) or do a CONSTANT = 11

@oliverchang
Copy link
Copy Markdown
Collaborator

@jonathanmetzman
Copy link
Copy Markdown
Contributor

CI is failing because of test and presubmit failures. Please fix them.

Copy link
Copy Markdown
Contributor

@jonathanmetzman jonathanmetzman left a comment

Choose a reason for hiding this comment

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

I think this PR needs some redesigning at a high-level before we proceed on fixing individual issues.
I'm most concerned with the interface between oss-fuzz and fuzz-introspector (as is, this code (which lives in oss-fuzz) clones fuzz-introspector, which clones oss-fuzz again.
I'm also concerned with the frequent use of sed here. I think it probably doens't need to be used at all.

f'/{upload_type}/{self.date}')


class IntrospectorBucket: # pylint: disable=too-few-public-methods
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's make a BaseBucket class that Bucket (which should be named CoverageBucket) and IntrospectorBucket can inherit from (or maybe we don't need 3 classes, maybe we can just have a bucket class and set the attributes that need to be different. Either way as is, this isn't good, it's basically duplicated code.

latest_report_info_url,
LATEST_REPORT_INFO_CONTENT_TYPE))

#currently fuzz introspector only supports c and c++
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And start every comment with a capital letter and end them with punctuation marks.


# Where code coverage reports need to be uploaded to.
COVERAGE_BUCKET_NAME = 'oss-fuzz-coverage'
INTROSPECTOR_BUCKET_NAME = 'oss-fuzz-introspector'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are these constants necessary?
We set these strings to be equal to them on lines 53 and 84 anyway.
Reuse them on lines 53 and 84 please.

@@ -36,6 +36,7 @@

# Where code coverage reports need to be uploaded to.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment doesn't apply to the constant you added.

config.test_image_suffix),
'env':
coverage_env,
'name': 'gcr.io/oss-fuzz-base/base-runner:introspector',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. Why did you make this change?
  2. Your change breaks testing, see how the actual function you get rid of is implemented
    def get_runner_image_name(base_images_project, test_image_suffix):
  3. It just seems very weird that a tag is used for the introspector version instead of base-introspector.
  4. Our current code allows changing oss-fuzz-base to something else (that's why base_images_project (defined here) is passed around. This breaks that. @oliverchang is this a feature worth keeping?

config.test_image_suffix),
'args': [
'bash', '-c',
(f'cd {FI_dir} && cd {oss_integration_dir}'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is very difficult to understand.
Instead of defining oss_integration_dir to implicitly be a subdir of FI_DIR make it an absolute path like so:

oss_integration_dir = os.path.join(FI_DIR, 'oss_fuzz_integration')

And then you will only have to cd once here.

config, coverage_url):
build_steps = []
FI_dir = '/workspace/fuzz-introspector/'
oss_integration_dir = 'oss_fuzz_integration/'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you explain what oss_integration_dir is in a comment?
I had to figure out what it is by going to the fuzz_introspector repo, can't expect readers to do this.

(f'cd {FI_dir} && cd {oss_integration_dir}'
' && sed -i \'s/\.\/infra\/base\-images\/all.sh/#\.\/infra\/base\-images\/all.sh/\''
' build_patched_oss_fuzz.sh'
' && ./build_patched_oss_fuzz.sh')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where is this file?

Comment on lines +288 to +299
' && ./build_patched_oss_fuzz.sh')
]
})

build_steps.append({
'name':
build_project.get_runner_image_name(base_images_project,
config.test_image_suffix),
'args': [
'bash', '-c',
('sed -i s/base-builder/base-builder:introspector/g '
f'{FI_dir}{oss_integration_dir}oss-fuzz/projects/{project_name}/Dockerfile'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK, I think I figured out what this is doing and I think this isn't well designed.
If I understand correctly, the highlighted lines calls build_patched_oss_fuzz.sh from our cloned copy of fuzz-introspector which then clones oss-fuzz again.
I think before we continue with this PR we should go back to the drawing board and describe at a high-level how this should work and then implement based on that spec.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To follow on this, there are some other thoughts on fuzz-introspector that I think makes sense to consider when integrating fuzz-introspector to oss-fuzz: #7059 (comment)

'-m',
'cp',
'-r',
os.path.join(build.out, 'inspector-tmp'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's inspector-tmp? Where does this come from?

@Navidem
Copy link
Copy Markdown
Contributor Author

Navidem commented Jan 20, 2022

Thanks for all the comments, closing this as #7162 is the one to move forward with.

@Navidem Navidem closed this Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants