Skip to content

Fix incorrect error return in ppc_aes_gcm_cipher_update decrypt path#30452

Closed
Scottcjn wants to merge 1 commit intoopenssl:masterfrom
Scottcjn:fix/ppc-gcm-decrypt-error-return
Closed

Fix incorrect error return in ppc_aes_gcm_cipher_update decrypt path#30452
Scottcjn wants to merge 1 commit intoopenssl:masterfrom
Scottcjn:fix/ppc-gcm-decrypt-error-return

Conversation

@Scottcjn
Copy link
Copy Markdown
Contributor

Summary

Fix incorrect -1 error return in the PPC AES-GCM decrypt pre-alignment path. The function contract is to return 1 on success and 0 on failure, but the decrypt path returned -1.

Problem

In ppc_aes_gcm_cipher_update(), the decrypt pre-alignment check at line 122 returns -1 when CRYPTO_gcm128_decrypt() fails:

// Decrypt path (WRONG — was returning -1):
if (CRYPTO_gcm128_decrypt(&ctx->gcm, in, out, res))
    return -1;

// Encrypt path (CORRECT — returns 0):
if (CRYPTO_gcm128_encrypt(&ctx->gcm, in, out, res))
    return 0;

The caller at ciphercommon_gcm.c:460 checks if (!hw->cipherupdate(...)). Since !(-1) evaluates to 0 (false in C), the goto err branch is not taken and GCM processing continues with potentially corrupt state.

This is the only return -1 in all GCM cipher implementation files. All five other error returns in the same function correctly return 0.

Fix

Change return -1 to return 0 to match the encrypt path and the function's documented contract.

Fixes #30380

CLA: Signed (on file from PR #9932 on wolfSSL, also applicable here — OpenSSL CLA was completed for #30437).

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label Mar 16, 2026
@nhorman
Copy link
Copy Markdown
Contributor

nhorman commented Mar 16, 2026

You don't appear to have a CLA on file, #30437 was marked as trivial (though it perhaps shouldn't have been), while #9932 was not authored by you.

@t8m
Copy link
Copy Markdown
Member

t8m commented Mar 16, 2026

Please amend the commit message so it contains CLA: trivial. As this is AI generated you're lucky that this is within the CLA: trivial limit. Otherwise it would not be an acceptable contribution.

@t8m t8m added approval: review pending This pull request needs review by a committer branch: master Applies to master branch triaged: bug The issue/pr is/fixes a bug tests: exempted The PR is exempt from requirements for testing branch: 3.3 Applies to openssl-3.3 branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 branch: 3.6 Applies to openssl-3.6 branch: 4.0 Applies to openssl-4.0 labels Mar 16, 2026
ppc_aes_gcm_cipher_update() returns 1 on success and 0 on failure.
The decrypt pre-alignment path (line 122) incorrectly returned -1
instead of 0 when CRYPTO_gcm128_decrypt() failed.

Since the caller checks `if (!hw->cipherupdate(...))`, and !(-1)
evaluates to 0 (false) in C, the error was silently swallowed and
GCM processing continued with potentially corrupt state.

The encrypt path at line 98 correctly returns 0. This was likely a
copy-paste error when the decrypt path was added.

Fixes openssl#30380

CLA: trivial
@Scottcjn Scottcjn force-pushed the fix/ppc-gcm-decrypt-error-return branch from 12be1bc to dae1e23 Compare March 16, 2026 19:15
@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Mar 16, 2026
@Scottcjn
Copy link
Copy Markdown
Contributor Author

Done — amended commit message to include CLA: trivial. Thank you @t8m and @nhorman for the guidance.

Copy link
Copy Markdown
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

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

Okay with trivial

@paulidale paulidale added the cla: trivial One of the commits is marked as 'CLA: trivial' label Mar 16, 2026
@esyr
Copy link
Copy Markdown
Member

esyr commented Mar 17, 2026

Fixes: 9ab6b64ac856 "Fix AES-GCM on Power 8 CPUs"

Copy link
Copy Markdown
Member

@esyr esyr left a comment

Choose a reason for hiding this comment

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

OK with CLA: trivial.

@openssl-machine openssl-machine added approval: done This pull request has the required number of approvals approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: review pending This pull request needs review by a committer approval: done This pull request has the required number of approvals labels Mar 17, 2026
@openssl-machine
Copy link
Copy Markdown
Collaborator

This pull request is ready to merge

openssl-machine pushed a commit that referenced this pull request Mar 18, 2026
ppc_aes_gcm_cipher_update() returns 1 on success and 0 on failure.
The decrypt pre-alignment path (line 122) incorrectly returned -1
instead of 0 when CRYPTO_gcm128_decrypt() failed.

Since the caller checks `if (!hw->cipherupdate(...))`, and !(-1)
evaluates to 0 (false) in C, the error was silently swallowed and
GCM processing continued with potentially corrupt state.

The encrypt path at line 98 correctly returns 0. This was likely a
copy-paste error when the decrypt path was added.

Fixes #30380

CLA: trivial

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Eugene Syromiatnikov <[email protected]>
MergeDate: Wed Mar 18 07:03:41 2026
(Merged from #30452)
openssl-machine pushed a commit that referenced this pull request Mar 18, 2026
ppc_aes_gcm_cipher_update() returns 1 on success and 0 on failure.
The decrypt pre-alignment path (line 122) incorrectly returned -1
instead of 0 when CRYPTO_gcm128_decrypt() failed.

Since the caller checks `if (!hw->cipherupdate(...))`, and !(-1)
evaluates to 0 (false) in C, the error was silently swallowed and
GCM processing continued with potentially corrupt state.

The encrypt path at line 98 correctly returns 0. This was likely a
copy-paste error when the decrypt path was added.

Fixes #30380

CLA: trivial

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Eugene Syromiatnikov <[email protected]>
MergeDate: Wed Mar 18 07:04:47 2026
(Merged from #30452)
openssl-machine pushed a commit that referenced this pull request Mar 18, 2026
ppc_aes_gcm_cipher_update() returns 1 on success and 0 on failure.
The decrypt pre-alignment path (line 122) incorrectly returned -1
instead of 0 when CRYPTO_gcm128_decrypt() failed.

Since the caller checks `if (!hw->cipherupdate(...))`, and !(-1)
evaluates to 0 (false) in C, the error was silently swallowed and
GCM processing continued with potentially corrupt state.

The encrypt path at line 98 correctly returns 0. This was likely a
copy-paste error when the decrypt path was added.

Fixes #30380

CLA: trivial

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Eugene Syromiatnikov <[email protected]>
MergeDate: Wed Mar 18 07:05:52 2026
(Merged from #30452)
openssl-machine pushed a commit that referenced this pull request Mar 18, 2026
ppc_aes_gcm_cipher_update() returns 1 on success and 0 on failure.
The decrypt pre-alignment path (line 122) incorrectly returned -1
instead of 0 when CRYPTO_gcm128_decrypt() failed.

Since the caller checks `if (!hw->cipherupdate(...))`, and !(-1)
evaluates to 0 (false) in C, the error was silently swallowed and
GCM processing continued with potentially corrupt state.

The encrypt path at line 98 correctly returns 0. This was likely a
copy-paste error when the decrypt path was added.

Fixes #30380

CLA: trivial

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Eugene Syromiatnikov <[email protected]>
MergeDate: Wed Mar 18 07:05:12 2026
(Merged from #30452)
openssl-machine pushed a commit that referenced this pull request Mar 18, 2026
ppc_aes_gcm_cipher_update() returns 1 on success and 0 on failure.
The decrypt pre-alignment path (line 122) incorrectly returned -1
instead of 0 when CRYPTO_gcm128_decrypt() failed.

Since the caller checks `if (!hw->cipherupdate(...))`, and !(-1)
evaluates to 0 (false) in C, the error was silently swallowed and
GCM processing continued with potentially corrupt state.

The encrypt path at line 98 correctly returns 0. This was likely a
copy-paste error when the decrypt path was added.

Fixes #30380

CLA: trivial

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Eugene Syromiatnikov <[email protected]>
MergeDate: Wed Mar 18 07:05:30 2026
(Merged from #30452)
@jogme
Copy link
Copy Markdown
Contributor

jogme commented Mar 18, 2026

Merged to branches 3.3<=. Thank you!

@jogme jogme closed this Mar 18, 2026
openssl-machine pushed a commit that referenced this pull request Mar 18, 2026
ppc_aes_gcm_cipher_update() returns 1 on success and 0 on failure.
The decrypt pre-alignment path (line 122) incorrectly returned -1
instead of 0 when CRYPTO_gcm128_decrypt() failed.

Since the caller checks `if (!hw->cipherupdate(...))`, and !(-1)
evaluates to 0 (false) in C, the error was silently swallowed and
GCM processing continued with potentially corrupt state.

The encrypt path at line 98 correctly returns 0. This was likely a
copy-paste error when the decrypt path was added.

Fixes #30380

CLA: trivial

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Eugene Syromiatnikov <[email protected]>
MergeDate: Wed Mar 18 07:06:12 2026
(Merged from #30452)
@Scottcjn
Copy link
Copy Markdown
Contributor Author

Thank you to @paulidale, @esyr, @jogme, and @t8m for the reviews and merge. This complements #30437 by fixing the decrypt return path in the same AES-GCM code. Appreciate the guidance on the CLA process as well — lesson learned for next time.

— Scott Boudreaux, Elyan Labs

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: master Applies to master branch branch: 3.3 Applies to openssl-3.3 branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 branch: 3.6 Applies to openssl-3.6 branch: 4.0 Applies to openssl-4.0 cla: trivial One of the commits is marked as 'CLA: trivial' 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.

Incorrect error return in ppc_aes_gcm_cipher_update

7 participants