Skip to content

Comments

The return value of RSA_*_{en,de}crypt() is signed#29323

Closed
vdukhovni wants to merge 1 commit intoopenssl:masterfrom
vdukhovni:fix-rsa-result-sign
Closed

The return value of RSA_*_{en,de}crypt() is signed#29323
vdukhovni wants to merge 1 commit intoopenssl:masterfrom
vdukhovni:fix-rsa-result-sign

Conversation

@vdukhovni
Copy link

The functions RSA_(public|private)_(en|de)crypt() return a signed result, in particular -1 may be returned on error, so the caller MUST treat the value as signed.

Checklist
  • documentation is added or updated
  • tests are added or updated

The functions RSA_(public|private)_(en|de)crypt() return a signed
result, in particular `-1` may be returned on error, so the caller
MUST treat the value as signed.
@vdukhovni vdukhovni force-pushed the fix-rsa-result-sign branch from 13aa6f1 to eee2273 Compare December 6, 2025 06:35
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Dec 6, 2025
Copy link
Contributor

@Sashan Sashan left a comment

Choose a reason for hiding this comment

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

looks good to me.

@Sashan Sashan added the approval: review pending This pull request needs review by a committer label Dec 8, 2025
Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

LGTM.

Side note: plaintext_len is changed to a signed type here to match the return value of RSA_size. AFAICT, that function never returns a negative value, although the documentation is silent about what happens on error. If it ever were to return a negative value, then the subsequent OPENSSL_calloc in this code would go wrong - attempting to allocate a very large positive value. But its probably fair to assume RSA_size will only return a value >=0.

@mattcaswell mattcaswell 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 Dec 8, 2025
@mattcaswell
Copy link
Member

What branches are we targeting this change for?

@vdukhovni
Copy link
Author

vdukhovni commented Dec 8, 2025

What branches are we targeting this change for?

I hadn't looked into backports, but the code that introduced the unsigned variables to handle the signed returned values was added in 3.4 as part of #23832

So we could backport to 3.4 if that seems appropriate.

@vdukhovni vdukhovni added branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 branch: 3.6 Applies to openssl-3.6 labels Dec 8, 2025
@t8m t8m added triaged: bug The issue/pr is/fixes a bug tests: exempted The PR is exempt from requirements for testing labels Dec 8, 2025
@slontis
Copy link
Member

slontis commented Dec 8, 2025

The change looks fine.
Note that I am not sure how easy it is to get to this path as it happens only AFTER a successful keygen call, which normally would mean that the parameters are correct (it would have to hit a malloc failure I presume)

@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.

@t8m t8m added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Dec 9, 2025
openssl-machine pushed a commit that referenced this pull request Dec 11, 2025
The functions RSA_(public|private)_(en|de)crypt() return a signed
result, in particular `-1` may be returned on error, so the caller
MUST treat the value as signed.

Reviewed-by: Saša Nedvědický <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #29323)
@t8m
Copy link
Member

t8m commented Dec 11, 2025

Merged to the master, 3.6, 3.5 and 3.4 branches. Thank you.

@t8m t8m closed this Dec 11, 2025
openssl-machine pushed a commit that referenced this pull request Dec 11, 2025
The functions RSA_(public|private)_(en|de)crypt() return a signed
result, in particular `-1` may be returned on error, so the caller
MUST treat the value as signed.

Reviewed-by: Saša Nedvědický <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #29323)

(cherry picked from commit f247d36)
openssl-machine pushed a commit that referenced this pull request Dec 11, 2025
The functions RSA_(public|private)_(en|de)crypt() return a signed
result, in particular `-1` may be returned on error, so the caller
MUST treat the value as signed.

Reviewed-by: Saša Nedvědický <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #29323)

(cherry picked from commit f247d36)
openssl-machine pushed a commit that referenced this pull request Dec 11, 2025
The functions RSA_(public|private)_(en|de)crypt() return a signed
result, in particular `-1` may be returned on error, so the caller
MUST treat the value as signed.

Reviewed-by: Saša Nedvědický <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #29323)

(cherry picked from commit f247d36)
cxx194832 pushed a commit to cxx194832/openssl that referenced this pull request Dec 12, 2025
The functions RSA_(public|private)_(en|de)crypt() return a signed
result, in particular `-1` may be returned on error, so the caller
MUST treat the value as signed.

Reviewed-by: Saša Nedvědický <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#29323)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 branch: 3.6 Applies to openssl-3.6 severity: fips change The pull request changes FIPS provider sources tests: exempted The PR is exempt from requirements for testing triaged: bug The issue/pr is/fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants