Note: This bug is displayed in read-only format because
the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
.Using CryptBlocks multiple times over the same input stream leads to incorrect encryption
When Go FIPS mode is enabled, AES CBC CryptBlocks incorrectly re-initializes the initialization vector. As a result, using CryptBlocks multiple times over the input stream encrypts files incorrectly. To work around this issue, do not reinitialize IV in the `aes-cbc` interface. This action allows files to be encrypted correctly.
Description of problem:
When FIPS mode is enabled with GOLANG_FIPS=1 environment variable, AES CBC is broken.
In the Golang-src package, source file crypto/internal/boring/aes.go function `func (x *aesCBC) CryptBlocks(dst, src []byte)`, _goboringcrypto_EVP_CipherInit_ex is being called unnecessarily with the IV.
The OpenSSL context already got the IV initialized properly in function `NewCBCEncrypter`. The reinitializing of the IV causes the first block of each successive `CryptBlocks()` call to be XOR'ed with an incorrect value, vs chaining the block encryption correctly from the previous context state.
The fix is pretty simple, just remove the extra `C._goboringcrypto_EVP_CipherInit_ex` call from `CryptBlocks`.
```
159a160,167
> if C._goboringcrypto_EVP_CipherInit_ex(
> x.ctx,
> nil, nil, nil,
> (*C.uchar)(unsafe.Pointer(&x.iv[0])),
> -1) != 1 {
> panic("crypto/cipher: CipherInit_ex failed")
> }
> runtime.KeepAlive(x)
```
Version-Release number of selected component (if applicable):
go version go1.15.7 linux/amd64
How reproducible:
Run AES CBC EncryptBlocks with two successive calls.
Example test program
```
func TestBlobEncryptBasicBlockEncryption(t *testing.T) {
key := []byte{0x24, 0xcd, 0x8b, 0x13, 0x37, 0xc5, 0xc1, 0xb1, 0x0, 0xbb, 0x27, 0x40, 0x4f, 0xab, 0x5f, 0x7b, 0x2d, 0x0, 0x20, 0xf5, 0x1, 0x84, 0x4, 0xbf, 0xe3, 0xbd, 0xa1, 0xc4, 0xbf, 0x61, 0x2f, 0xc5}
iv := []byte{0x91, 0xc7, 0xa7, 0x54, 0x52, 0xef, 0x10, 0xdb, 0x91, 0xa8, 0x6c, 0xf9, 0x79, 0xd5, 0xac, 0x74}
block, err := aes.NewCipher(key)
require.NoError(t, err)
blockSize := block.BlockSize()
require.Equal(t, 16, blockSize)
encryptor := cipher.NewCBCEncrypter(block, iv)
require.NotNil(t, encryptor)
encrypted := make([]byte, 32)
// First block. 16 bytes.
srcBlock1 := bytes.Repeat([]byte{0x01}, 16)
encryptor.CryptBlocks(encrypted, srcBlock1)
require.Equal(t, []byte{
0x14, 0xb7, 0x3e, 0x2f, 0xd9, 0xe7, 0x69, 0x7e, 0xb7, 0xd2, 0xc3, 0x5b, 0x31, 0x9c, 0xf0, 0x59,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}, encrypted)
// Second block. 16 bytes.
srcBlock2 := bytes.Repeat([]byte{0x02}, 16)
encryptor.CryptBlocks(encrypted[16:], srcBlock2)
require.Equal(t, []byte{
0x14, 0xb7, 0x3e, 0x2f, 0xd9, 0xe7, 0x69, 0x7e, 0xb7, 0xd2, 0xc3, 0x5b, 0x31, 0x9c, 0xf0, 0x59,
0xbb, 0xd4, 0x95, 0x25, 0x21, 0x56, 0x87, 0x3b, 0xe6, 0x22, 0xe8, 0xd0, 0x19, 0xa8, 0xed, 0xcd,
}, encrypted)
}
```
Steps to Reproduce:
1. Turn on FIPS mode with env variable GOLANG_FIPS=1
2. Run the encryption test
3. Verify that test passes
Actual results:
Test fails because the second call to CryptBlocks() is doing incorrect block chaining due to re-initializing the context with the IV again.
Expected results:
Test should pass
Additional info:
Hi guys,
Is the fix we proposed the correct fix for this problem?
We would like to know whether this patch is correct (or if you guys are fixing it some other way) and pre-apply it to our internal build without needing to wait for the full RHEL release cycle.
This is a blocker for us at the moment.
Thanks!
Di
*** Bug 1979100 has been marked as a duplicate of this bug. ***
Comment 12Eva-Lotte Gebhardt
2021-08-05 14:16:43 UTC
Hi Alejandro,
would you please let me know what needs to be mentioned about this bugfix in the release note?
Thank you,
Eva
Comment 13Eva-Lotte Gebhardt
2021-08-18 15:40:36 UTC
Hi Alejandro,
sorry, I didn't see you already provided the info in the doctext field!
Here is my first draft of this RN. Please let me know what can to be improved:
.Using CryptBlocks multiple times over the same input stream leads to incorrect encryption
When Go FIPS mode is enabled, AES CBC CryptBlocks incorrectly re-initialize IV. As a result, using CryptBlocks multiple times over the input stream encrypts files incorrectly. To work around this issue, do not reinitialize IV in the `aes-cbc` interface. As a result, files are encrypted correctly.
Could you please let me know what "IV" is, in this context?
Thank you very much!
(In reply to Eva-Lotte Gebhardt from comment #13)
> Hi Alejandro,
>
> sorry, I didn't see you already provided the info in the doctext field!
>
> Here is my first draft of this RN. Please let me know what can to be
> improved:
>
>
> .Using CryptBlocks multiple times over the same input stream leads to
> incorrect encryption
>
> When Go FIPS mode is enabled, AES CBC CryptBlocks incorrectly re-initialize
> IV. As a result, using CryptBlocks multiple times over the input stream
> encrypts files incorrectly. To work around this issue, do not reinitialize
> IV in the `aes-cbc` interface. As a result, files are encrypted correctly.
That sounds great.
>
> Could you please let me know what "IV" is, in this context?
"Initialization vector"
>
> Thank you very much!
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory (Moderate: go-toolset:rhel8 security, bug fix, and enhancement update), and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.
https://access.redhat.com/errata/RHSA-2021:4156
Description of problem: When FIPS mode is enabled with GOLANG_FIPS=1 environment variable, AES CBC is broken. In the Golang-src package, source file crypto/internal/boring/aes.go function `func (x *aesCBC) CryptBlocks(dst, src []byte)`, _goboringcrypto_EVP_CipherInit_ex is being called unnecessarily with the IV. The OpenSSL context already got the IV initialized properly in function `NewCBCEncrypter`. The reinitializing of the IV causes the first block of each successive `CryptBlocks()` call to be XOR'ed with an incorrect value, vs chaining the block encryption correctly from the previous context state. The fix is pretty simple, just remove the extra `C._goboringcrypto_EVP_CipherInit_ex` call from `CryptBlocks`. ``` 159a160,167 > if C._goboringcrypto_EVP_CipherInit_ex( > x.ctx, > nil, nil, nil, > (*C.uchar)(unsafe.Pointer(&x.iv[0])), > -1) != 1 { > panic("crypto/cipher: CipherInit_ex failed") > } > runtime.KeepAlive(x) ``` Version-Release number of selected component (if applicable): go version go1.15.7 linux/amd64 How reproducible: Run AES CBC EncryptBlocks with two successive calls. Example test program ``` func TestBlobEncryptBasicBlockEncryption(t *testing.T) { key := []byte{0x24, 0xcd, 0x8b, 0x13, 0x37, 0xc5, 0xc1, 0xb1, 0x0, 0xbb, 0x27, 0x40, 0x4f, 0xab, 0x5f, 0x7b, 0x2d, 0x0, 0x20, 0xf5, 0x1, 0x84, 0x4, 0xbf, 0xe3, 0xbd, 0xa1, 0xc4, 0xbf, 0x61, 0x2f, 0xc5} iv := []byte{0x91, 0xc7, 0xa7, 0x54, 0x52, 0xef, 0x10, 0xdb, 0x91, 0xa8, 0x6c, 0xf9, 0x79, 0xd5, 0xac, 0x74} block, err := aes.NewCipher(key) require.NoError(t, err) blockSize := block.BlockSize() require.Equal(t, 16, blockSize) encryptor := cipher.NewCBCEncrypter(block, iv) require.NotNil(t, encryptor) encrypted := make([]byte, 32) // First block. 16 bytes. srcBlock1 := bytes.Repeat([]byte{0x01}, 16) encryptor.CryptBlocks(encrypted, srcBlock1) require.Equal(t, []byte{ 0x14, 0xb7, 0x3e, 0x2f, 0xd9, 0xe7, 0x69, 0x7e, 0xb7, 0xd2, 0xc3, 0x5b, 0x31, 0x9c, 0xf0, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, encrypted) // Second block. 16 bytes. srcBlock2 := bytes.Repeat([]byte{0x02}, 16) encryptor.CryptBlocks(encrypted[16:], srcBlock2) require.Equal(t, []byte{ 0x14, 0xb7, 0x3e, 0x2f, 0xd9, 0xe7, 0x69, 0x7e, 0xb7, 0xd2, 0xc3, 0x5b, 0x31, 0x9c, 0xf0, 0x59, 0xbb, 0xd4, 0x95, 0x25, 0x21, 0x56, 0x87, 0x3b, 0xe6, 0x22, 0xe8, 0xd0, 0x19, 0xa8, 0xed, 0xcd, }, encrypted) } ``` Steps to Reproduce: 1. Turn on FIPS mode with env variable GOLANG_FIPS=1 2. Run the encryption test 3. Verify that test passes Actual results: Test fails because the second call to CryptBlocks() is doing incorrect block chaining due to re-initializing the context with the IV again. Expected results: Test should pass Additional info: