Skip to content

kdf: put back argument null checks #28204

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

paulidale
Copy link
Contributor

No description provided.

@paulidale paulidale self-assigned this Aug 8, 2025
@paulidale paulidale added branch: master Merge to master branch approval: review pending This pull request needs review by a committer tests: exempted The PR is exempt from requirements for testing labels Aug 8, 2025
@paulidale paulidale requested a review from a team August 8, 2025 04:04
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Aug 8, 2025
@vdukhovni
Copy link

Can you provide a plausible rationale for these? The provider context is allocated in the "new" callback and a non-null value is passed to all the other methods by the EVP layer, I am not aware of any opportunities for a NULL value in the vctx.

@esyr
Copy link
Contributor

esyr commented Aug 8, 2025

Why "back"? I can't find any commit that removed them, they seem to be absent from the commits the added the respective KDFs.

@paulidale
Copy link
Contributor Author

These checks were added in the various recent generated decoder PRs I done. The PR removing them (#28176) was merged yesterday. Before they were added, it was a hodgepodge where some implementations did these checks and some didn't. The decoder work changed them all to include the check because this was specifically requested by a reviewer of some of the initial effort. Now that a few checks have been removed, we're back to a less than ideal inconsistent state.

The rationale is that these are a public API and we make an effort to check arguments in public APIs. I know that libcrypto does the right thing and never passes nulls to providers but that doesn't mean other callers will be so diligent. I'm aware of several providers that directly call other providers without involving libcrypto:

  • We've got one in our test suite.
  • There was work towards a load balancing provider a while back.
  • A proxy provider was being done.
  • The DRBGs directly call their parents for various things.

There is also nothing stopping an application from calling providers directly: the APIs in question are public and stable after all. Hyrum’s law is almost certainly in effect.

I've raised an issue (#28202) to have a committer discussion about this. We either want them everywhere or nowhere. I don't much care which but we need to choose one way or the other and make all of the required changes. This PR represents the easier path.

@esyr
Copy link
Contributor

esyr commented Aug 8, 2025

I see, thank you for the explanation. As these are public API, I'd suggest to expressly annotate the relevant arguments with __attribute__((nonnull)), both in function definitions/declarations and the callback fields definitions, if they are expected to be non-NULL, or indeed put back these checks otherwise.

@vdukhovni
Copy link

I see, thank you for the explanation. As these are public API, I'd suggest to expressly annotate the relevant arguments with __attribute__((nonnull)), both in function definitions/declarations and the callback fields definitions, if they are expected to be non-NULL, or indeed put back these checks otherwise.

If we're now in the C99 business, I'd prefer the attribute approach over reintroducing the checks. Let the compiler do the work (better). Essentially these become akin to C++ call by reference, which is largely avoids NPEs by having the call site syntax specify an object rather than its address, though one can of course bypass the safety with foo *x = NULL; func(*x, ...), which calls func() with a null pointer, and the crash happens inside func() when the referenced object is used.

@paulidale
Copy link
Contributor Author

Can you please point me to where in the C99 standard, attributes are introduced?
I'm unable to find them.

@t-j-h
Copy link
Member

t-j-h commented Aug 10, 2025

The null checks should be added. The attribute check for non-null args is definitely not universal. And we should be consistent as per Paul's comments. It significantly reduces support issues and it also helps reduce certain types of crashes.

Copy link
Member

@InfoHunter InfoHunter left a comment

Choose a reason for hiding this comment

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

If nulll-checks are consistent across the library, then I support to add those checks here.

@paulidale paulidale added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: done This pull request has the required number of approvals branch: master Merge to master branch severity: fips change The pull request changes FIPS provider sources tests: exempted The PR is exempt from requirements for testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants