Skip to content

ci: add CodeQL query to enforce OpenSSL return code handling (#1867)#2415

Open
Vishnu2707 wants to merge 4 commits intoopen-quantum-safe:mainfrom
Vishnu2707:codeql-openssl-return-check
Open

ci: add CodeQL query to enforce OpenSSL return code handling (#1867)#2415
Vishnu2707 wants to merge 4 commits intoopen-quantum-safe:mainfrom
Vishnu2707:codeql-openssl-return-check

Conversation

@Vishnu2707
Copy link
Copy Markdown
Contributor

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_GUARD
macro. 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 workflow

Files modified

  • .github/workflows/pr.yml — adds codeql job to PR checks

Background

Trail of Bits identified unchecked EVP_* return values during their
audit 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

  • Does this PR change the input/output behaviour of a cryptographic algorithm? No
  • Does this PR change the list of algorithms available? No

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>
Comment thread .github/workflows/codeql.yml Fixed
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>
@coveralls
Copy link
Copy Markdown

coveralls commented May 2, 2026

Coverage Status

coverage: 82.272% (+0.002%) from 82.27% — Vishnu2707:codeql-openssl-return-check into open-quantum-safe:main

Vishnu2707 added 2 commits May 5, 2026 15:43
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>
@Vishnu2707
Copy link
Copy Markdown
Contributor Author

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?

@baentsch
Copy link
Copy Markdown
Member

baentsch commented May 6, 2026

Hi @Vishnu2707 Thanks very much for the PR and helping us reduce our backlog!

or should the workflow be restructured to work alongside default setup?

The latter: We want to keep the current checks. Copilot suggested this change (plus, removal of the new codeql-config.yml from the PR):

- name: Initialize CodeQL
  uses: github/codeql-action/init@4e828ff8d448a8a6e532957b1811f387a63867e8 # v3
  with:
    languages: cpp
    queries: security-and-quality,./.github/codeql/openssl-return-check.ql

Could you please try this / whether this gets the PR across the finish line?

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.

Add CodeQL query to enforce OpenSSL return code handling

4 participants