ci: add CodeQL query to enforce OpenSSL return code handling (#1867) - #2415
ci: add CodeQL query to enforce OpenSSL return code handling (#1867)#2415Vishnu2707 wants to merge 9 commits into
Conversation
|
The query runs successfully, CodeQL scanned 200 C files with no errors. The remaining failure is CodeQL analyses from advanced configurations cannot be processed when the default setup is enabled, which indicates the repo has CodeQL default setup active in settings. This conflicts with the custom workflow SARIF upload. @dstebila @baentsch, would it be possible to disable default setup in the repository's Code Security settings to allow the custom workflow to run, or should the workflow be restructured to work alongside default setup? |
|
Hi @Vishnu2707 Thanks very much for the PR and helping us reduce our backlog!
The latter: We want to keep the current checks. Copilot suggested this change (plus, removal of the new codeql-config.yml from the PR): Could you please try this / whether this gets the PR across the finish line? |
8794e47 to
f9133ba
Compare
xuganyu96
left a comment
There was a problem hiding this comment.
I took a look at the logs of a workflow run but had a hard time figuring out where I should look for positive/negative output, especially with regard to the pattern presented in this pull request.
Could you please provide some documentation on where the maintainers should look for "CodeQL catching bad examples matching this pattern?" This could be a section in CONTRIBUTING.md, or a "expect-fail" test case in pytest/GitHub Actions. Thank you.
@baentsch it looks like your suggestion has been implemented. Could you please review this pull request? Thank you. |
Indeed, it has. Thanks for the heads up @xuganyu96 and to @Vishnu2707 for the improvement and closing a long-standing issue! So I'm approving, too, but would like to support this suggestion
as a further improvement to the PR before merge. Would you be able to add something like that @Vishnu2707 ? Otherwise, we'll blindly trust the CI to flag errors as and when they occur/get re-introduced :) |
Adds a custom CodeQL query (.github/codeql/openssl-return-check.ql) that detects calls to OpenSSL EVP_* functions whose return value is not guarded by the OQS_OPENSSL_GUARD macro. Integrates the query into a new CodeQL workflow (.github/workflows/codeql.yml) that runs on every PR and push to main. The query was originally written by Trail of Bits during their audit of liboqs and reported in issue open-quantum-safe#1867. Closes open-quantum-safe#1867 Signed-off-by: Vishnu Ajith <27vishnu07@gmail.com>
Addresses Scorecard Token-Permissions finding: security-events write permission scoped to codeql job only, not workflow level. Signed-off-by: Vishnu Ajith <27vishnu07@gmail.com>
Replace inline queries: path with a codeql-config.yml config file. The CodeQL init action requires local queries to be referenced via a config file rather than a direct relative path in the queries field. Signed-off-by: Vishnu Ajith <27vishnu07@gmail.com>
The CodeQL cpp extractor pre-finalize script crashes with exit code 134 when the trapCaches/cpp/tarballs directory does not exist on the runner. Disabling TRAP caching avoids the crash. Signed-off-by: Vishnu Ajith <27vishnu07@gmail.com>
Replace config-file approach with inline queries field combining security-and-quality suite with the custom EVP return check query, as suggested by @baentsch. Remove codeql-config.yml. Signed-off-by: Vishnu Ajith <27vishnu07@gmail.com>
Signed-off-by: Vishnu Ajith <27vishnu07@gmail.com>
Adding upload: false to the analyze step prevents the SARIF conflict with GitHub's default CodeQL setup which is enabled on this repo. The query still runs and catches issues but does not upload results. Signed-off-by: Vishnu Ajith <27vishnu07@gmail.com>
Add bad example at .github/codeql/test/openssl-return-check-bad.c to confirm the query catches unchecked EVP_* calls. Document verification steps in CONTRIBUTING.md. Signed-off-by: Vishnu Ajith <27vishnu07@gmail.com>
f9133ba to
7846e61
Compare
Signed-off-by: Vishnu Ajith <27vishnu07@gmail.com>
baentsch
left a comment
There was a problem hiding this comment.
Thanks for the negative test & documentation update @Vishnu2707 ! Ready to merge if you agree @xuganyu96 (and CI passes, of course),
I'm still a little confused about where to look for errors resulting from this. |
@dstebila - The bad example is at .github/codeql/test/openssl-return-check-bad.c. if CodeQL is running correctly, that file should produce an alert for the unchecked EVP_DigestInit_ex call. For day-to-day use, any new unchecked EVP_* call introduced in a PR will show up as a code scanning alert blocking merge. |
| uses: github/codeql-action/analyze@4e828ff8d448a8a6e532957b1811f387a63867e8 # v3 | ||
| with: | ||
| category: "/language:cpp" | ||
| upload: false |
There was a problem hiding this comment.
This doesn't look exactly right. With upload: false, the analyze step will not upload the scanning results to Code Scanning. I tried running it with upload set to true (and with default CodeQL setup disabled), the workflow reported successful upload, but I still could not find the corresponding entries in Code Scanning.
The liboqs repository currently enables the default CodeQL setup, which blocks code scanning results uploads from REST API (i.e. GitHub Actions) and CodeQL CLI. If we want to proceed with adding custom CodeQL queries, the default setup must be disabled, and to preserve existing code scanning we will need to manually add a codeql.yml workflow. Given how this touches privileged settings of the liboqs repository, I'm afraid that configuring custom CodeQL queries is beyond the authorization of external contributors.
cc: @dstebila
References:
There was a problem hiding this comment.
Thanks @xuganyu96 for checking this out. Disabling the default CodeQL setup needs admin access so that's on your end. @dstebila @baentsch let me know how you want to proceed, happy either way.
Closes #1867
What this PR does
Adds a custom CodeQL query that detects calls to OpenSSL
EVP_*functions whose return value is not guarded by the
OQS_OPENSSL_GUARDmacro. Integrates the query into a new CodeQL workflow that runs on
every PR and push to main.
Files added
.github/codeql/openssl-return-check.ql— custom CodeQL query.github/workflows/codeql.yml— CodeQL workflowFiles modified
.github/workflows/pr.yml— addscodeqljob to PR checksBackground
Trail of Bits identified unchecked
EVP_*return values during theiraudit of liboqs (issue #1862, fixed in #1869). This query makes that
class of bug permanently detectable in CI, preventing new instances
from being introduced.
The query was originally written by Trail of Bits and provided in
issue #1867.
Checklist