Skip to content

fix potential null pointer dereference in cms_main function in apps/cms.c #26941 #27044

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 3 commits into
base: master
Choose a base branch
from

Conversation

glorious064
Copy link

Checklist

How the Null Pointer Derefrence Happens:
in the cms_main function in the apps/cms.c file
At lines 1013-1015, the following code snippet is present:
pctx = CMS_RecipientInfo_get0_pkey_ctx(ri); if (kparam != NULL) { if (!cms_set_pkey_param(pctx, kparam->param))

The assignment pctx = CMS_RecipientInfo_get0_pkey_ctx(ri); suggests that pctx might be NULL. However, in the subsequent call chain:
(!cms_set_pkey_param(pctx, kparam->param))
-> pkey_ctrl_string(pctx, keyopt)
-> rv = EVP_PKEY_CTX_ctrl_str(ctx, stmp, vtmp)
-> ret = evp_pkey_ctx_store_cached_data(ctx, -1, -1, -1, name, value, strlen(value) + 1)
-> evp_pkey_ctx_state(ctx)

There are dereference operations involving pctx, which may pose a potential risk if pctx is NULL. So I add a null check:
if (pctx && !cms_set_pkey_param(pctx, kparam->param))

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label Mar 12, 2025
@vdukhovni vdukhovni changed the title fix potential null pointer derefrence in cms_main function in apps/cms.c #26941 fix potential null pointer dereference in cms_main function in apps/cms.c #26941 Mar 13, 2025
@vdukhovni vdukhovni added cla: trivial One of the commits is marked as 'CLA: trivial' and removed hold: cla required The contributor needs to submit a license agreement labels Mar 13, 2025
Copy link

@vdukhovni vdukhovni left a comment

Choose a reason for hiding this comment

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

Fine, but please make the suggested change.

conform the project code style

Co-authored-by: Viktor Dukhovni <viktor1ghub@dukhovni.org>
@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label Mar 13, 2025
vdukhovni
vdukhovni previously approved these changes Mar 13, 2025
InfoHunter
InfoHunter previously approved these changes Apr 1, 2025
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.

Agreed it's trivial.

@InfoHunter InfoHunter added the approval: done This pull request has the required number of approvals label Apr 1, 2025
@InfoHunter
Copy link
Member

Wait, I noticed there is one other place that has the same issue: CMS_SignerInfo_get0_pkey_ctx

@InfoHunter
Copy link
Member

@glorious064 Would you like to fix that incidentally?

@InfoHunter
Copy link
Member

InfoHunter commented Apr 1, 2025

openssl/apps/cms.c

Lines 1137 to 1142 in 516e974

if (kparam != NULL) {
EVP_PKEY_CTX *pctx;
pctx = CMS_SignerInfo_get0_pkey_ctx(si);
if (!cms_set_pkey_param(pctx, kparam->param))
goto end;
}

@InfoHunter InfoHunter added branch: master Merge to master branch triaged: bug The issue/pr is/fixes a bug branch: 3.0 Merge to openssl-3.0 branch branch: 3.2 Merge to openssl-3.2 branch: 3.3 Merge to openssl-3.3 branch: 3.4 Merge to openssl-3.4 branch: 3.5 Merge to openssl-3.5 labels Apr 1, 2025
@glorious064
Copy link
Author

@glorious064 Would you like to fix that incidentally?

Sure, should I submit a new pull request?

paulidale
paulidale previously approved these changes Apr 1, 2025
@openssl-machine
Copy link
Collaborator

24 hours has passed since 'approval: done' was set, but as this PR has been updated in that time the label 'approval: ready to merge' is not being automatically set. Please review the updates and set the label manually.

@InfoHunter
Copy link
Member

Sure, should I submit a new pull request?

I don't think so, you can add new commits to this pull request.

@InfoHunter
Copy link
Member

And you need to write a CLA: trivial line in the commit message.

@glorious064
Copy link
Author

glorious064 commented Apr 2, 2025 via email

Add a null check to avoid potential null pointer dereference.

CLA: trivial
@glorious064 glorious064 dismissed stale reviews from InfoHunter and vdukhovni via 20f368f April 8, 2025 01:16
@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Apr 8, 2025
@glorious064
Copy link
Author

And you need to write a CLA: trivial line in the commit message.

I have submitted a new commit. Please review it. The message includes CLA: trivial as requested.

@mattcaswell mattcaswell added approval: review pending This pull request needs review by a committer and removed approval: done This pull request has the required number of approvals labels Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: review pending This pull request needs review by a committer branch: master Merge to master branch branch: 3.0 Merge to openssl-3.0 branch branch: 3.2 Merge to openssl-3.2 branch: 3.3 Merge to openssl-3.3 branch: 3.4 Merge to openssl-3.4 branch: 3.5 Merge to openssl-3.5 cla: trivial One of the commits is marked as 'CLA: trivial' triaged: bug The issue/pr is/fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants