Skip to content

Commit d5520b8

Browse files
committed
Merged PR 10578579: Fixed debug assertion failure in AES-GCM with nonce < 12 bytes when ASM is disabled
`SymCryptGHashAppendDataC` has an assertion `SYMCRYPT_ASSERT(cbData >= SYMCRYPT_GF128_BLOCK_SIZE)`, because the function does nothing if the length of the provided data is less than the block size. However, `SymCryptGcmSetNonce` was unconditionally calling `SymCryptGHashAppendData` for the first `(cbNonce - cbNonceRemainder)` bytes of the nonce, even if the nonce was less than the block size. In this case, `(cbNonce - cbNonceRemainder) == 0`, so the assertion fails. This is not a functional issue, because the subsequent call will append the remaining bytes, padded to the block size. But it does cause an assertion failure in debug builds when ASM is disabled, so it should be fixed. This wasn't caught earlier because we don't normally run tests on debug builds without ASM optimizations. Since this is a gap in our testing, I also added a new pipeline which will be run nightly and include more thorough testing. Tested: symcryptunittest, CI
1 parent f518786 commit d5520b8

File tree

8 files changed

+252
-7
lines changed

8 files changed

+252
-7
lines changed

.pipelines/OneBranch.Official.yml

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
#################################################################################
2+
# OneBranch Pipelines #
3+
# This pipeline was created by EasyStart from a sample located at: #
4+
# https://aka.ms/obpipelines/easystart/samples #
5+
# Documentation: https://aka.ms/obpipelines #
6+
# Yaml Schema: https://aka.ms/obpipelines/yaml/schema #
7+
# Retail Tasks: https://aka.ms/obpipelines/tasks #
8+
# Support: https://aka.ms/onebranchsup #
9+
#################################################################################
10+
11+
trigger: none
12+
13+
variables:
14+
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
15+
LinuxContainerImage: 'onebranch.azurecr.io/linux/ubuntu-2004:latest' # Docker image which is used to build the project https://aka.ms/obpipelines/containers
16+
WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022@sha256:a3083215a4675bad774ec88005dcf57436b3423584d0db3e82b6de3f780213ba'
17+
18+
resources:
19+
repositories:
20+
- repository: templates
21+
type: git
22+
name: OneBranch.Pipelines/GovernedTemplates
23+
ref: refs/heads/main
24+
25+
extends:
26+
template: v2/OneBranch.Official.CrossPlat.yml@templates # https://aka.ms/obpipelines/templates
27+
parameters:
28+
featureFlags:
29+
needExceptionForUbuntuUsage: true # Mariner does not currently support all of our cross-compilation targets
30+
LinuxHostVersion:
31+
Distribution: Ubuntu # Mariner kernel is incompatible with Ubuntu container; causes infinite loop in ASAN https://github.com/actions/runner-images/issues/9524
32+
globalSdl: # https://aka.ms/obpipelines/sdl
33+
tsa:
34+
enabled: false # Disable TSA to force build breaks
35+
policheck:
36+
break: true # always break the build on policheck issues.
37+
binskim:
38+
enabled: false # Temporarily disable binskim until we sort out BA2018 errors
39+
40+
stages:
41+
- stage: Set_Version
42+
jobs:
43+
- job: set_version
44+
displayName: Set Version
45+
pool:
46+
type: linux
47+
variables:
48+
ob_outputDirectory: $(Build.SourcesDirectory)/bin
49+
steps:
50+
- task: PythonScript@0
51+
displayName: 'Set version number'
52+
name: verStep
53+
inputs:
54+
scriptSource: 'filePath'
55+
scriptPath: scripts/version.py
56+
arguments: '--devops'
57+
workingDirectory: $(Build.SourcesDirectory)
58+
- task: onebranch.pipeline.version@1
59+
inputs:
60+
system: 'Custom'
61+
customVersion: '$(verStep.VER_MAJOR).$(verStep.VER_MINOR).$(verStep.VER_PATCH)-$(Build.BuildId)'
62+
63+
- stage: Build_Windows
64+
displayName: Build Windows
65+
jobs:
66+
- template: .pipelines/templates/build-windows-cmake.yml@self
67+
parameters:
68+
arch: 'AMD64'
69+
config: 'Debug'
70+
sign: true
71+
additionalArgs: '--test-legacy-impl'
72+
- template: .pipelines/templates/build-windows-cmake.yml@self
73+
parameters:
74+
arch: 'AMD64'
75+
config: 'Release'
76+
sign: true
77+
additionalArgs: '--test-legacy-impl'
78+
- template: .pipelines/templates/build-windows-cmake.yml@self
79+
parameters:
80+
arch: 'X86'
81+
config: 'Debug'
82+
sign: true
83+
additionalArgs: '--test-legacy-impl'
84+
- template: .pipelines/templates/build-windows-cmake.yml@self
85+
parameters:
86+
arch: 'X86'
87+
config: 'Release'
88+
sign: true
89+
additionalArgs: '--test-legacy-impl'
90+
- template: .pipelines/templates/build-windows-cmake.yml@self
91+
parameters:
92+
arch: 'AMD64'
93+
config: 'Release'
94+
sign: true
95+
additionalArgs: '--no-asm'
96+
identifier: 'NoAsm'
97+
- template: .pipelines/templates/build-windows-cmake.yml@self
98+
parameters:
99+
arch: 'X86'
100+
config: 'Release'
101+
sign: true
102+
additionalArgs: '--no-asm'
103+
identifier: 'NoAsm'
104+
105+
- stage: Build_Linux
106+
displayName: Build Linux
107+
jobs:
108+
- template: .pipelines/templates/build-linux.yml@self
109+
parameters:
110+
arch: 'AMD64'
111+
config: 'Debug'
112+
cc: 'gcc'
113+
cxx: 'g++'
114+
openssl: true
115+
- template: .pipelines/templates/build-linux.yml@self
116+
parameters:
117+
arch: 'AMD64'
118+
config: 'Sanitize'
119+
cc: 'gcc'
120+
cxx: 'g++'
121+
openssl: true
122+
- template: .pipelines/templates/build-linux.yml@self
123+
parameters:
124+
arch: 'AMD64'
125+
config: 'Release'
126+
cc: 'gcc'
127+
cxx: 'g++'
128+
openssl: true
129+
- template: .pipelines/templates/build-linux.yml@self
130+
parameters:
131+
arch: 'AMD64'
132+
config: 'Debug'
133+
cc: 'clang'
134+
cxx: 'clang++'
135+
openssl: true
136+
- template: .pipelines/templates/build-linux.yml@self
137+
parameters:
138+
arch: 'AMD64'
139+
config: 'Sanitize'
140+
cc: 'clang'
141+
cxx: 'clang++'
142+
openssl: true
143+
- template: .pipelines/templates/build-linux.yml@self
144+
parameters:
145+
arch: 'AMD64'
146+
config: 'Release'
147+
cc: 'clang'
148+
cxx: 'clang++'
149+
openssl: true
150+
- template: .pipelines/templates/build-linux.yml@self
151+
parameters:
152+
arch: 'AMD64'
153+
config: 'Release'
154+
cc: 'gcc'
155+
cxx: 'g++'
156+
additionalArgs: '--no-asm'
157+
openssl: true
158+
identifier: 'NoAsm'
159+
- template: .pipelines/templates/build-linux.yml@self
160+
parameters:
161+
arch: 'AMD64'
162+
config: 'Release'
163+
cc: 'clang'
164+
cxx: 'clang++'
165+
additionalArgs: '--no-asm'
166+
openssl: true
167+
identifier: 'NoAsm'
168+
- template: .pipelines/templates/build-linux.yml@self
169+
parameters:
170+
arch: 'X86'
171+
config: 'Release'
172+
cc: 'gcc'
173+
cxx: 'g++'
174+
additionalArgs: '--no-asm --no-fips'
175+
identifier: 'NoAsm'
176+
- template: .pipelines/templates/build-linux.yml@self
177+
parameters:
178+
arch: 'X86'
179+
config: 'Release'
180+
cc: 'clang'
181+
cxx: 'clang++'
182+
additionalArgs: '--no-asm --no-fips'
183+
identifier: 'NoAsm'
184+
- template: .pipelines/templates/build-linux.yml@self
185+
parameters:
186+
arch: 'ARM64'
187+
config: 'Debug'
188+
cc: 'clang'
189+
cxx: 'clang++'
190+
additionalArgs: '--toolchain=cmake-configs/Toolchain-Clang-ARM64.cmake'
191+
- template: .pipelines/templates/build-linux.yml@self
192+
parameters:
193+
arch: 'ARM64'
194+
config: 'Release'
195+
cc: 'clang'
196+
cxx: 'clang++'
197+
additionalArgs: '--toolchain=cmake-configs/Toolchain-Clang-ARM64.cmake'
198+
- template: .pipelines/templates/build-linux.yml@self
199+
parameters:
200+
arch: 'ARM'
201+
config: 'Debug'
202+
cc: 'gcc'
203+
cxx: 'g++'
204+
additionalArgs: '--toolchain=cmake-configs/Toolchain-GCC-ARM.cmake'
205+
- template: .pipelines/templates/build-linux.yml@self
206+
parameters:
207+
arch: 'ARM'
208+
config: 'Release'
209+
cc: 'gcc'
210+
cxx: 'g++'
211+
additionalArgs: '--toolchain=cmake-configs/Toolchain-GCC-ARM.cmake'

.pipelines/OneBranch.PullRequest.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ extends:
3030
LinuxHostVersion:
3131
Distribution: Ubuntu # Mariner kernel is incompatible with Ubuntu container; causes infinite loop in ASAN https://github.com/actions/runner-images/issues/9524
3232
globalSdl: # https://aka.ms/obpipelines/sdl
33+
tsa:
34+
enabled: false # Disable TSA to force build breaks
3335
policheck:
3436
break: true # always break the build on policheck issues.
3537
binskim:

.pipelines/OneBranch.WindowsUndocked.Official.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ extends:
6969
platform:
7070
name: 'windows_undocked'
7171
globalSdl:
72-
# Disable TSA to force build breaks
7372
tsa:
74-
enabled: false
73+
enabled: false # Disable TSA to force build breaks
7574
featureFlags:
7675
WindowsHostVersion: '1ESWindows2022'
7776
stages:

.pipelines/OneBranch.WindowsUndocked.PullRequest.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ extends:
3535
platform:
3636
name: 'windows_undocked'
3737
globalSdl:
38-
# Disable TSA to force build breaks
3938
tsa:
40-
enabled: false
39+
enabled: false # Disable TSA to force build breaks
4140
featureFlags:
4241
WindowsHostVersion: '1ESWindows2022'
4342
stages:

.pipelines/templates/build-linux.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,27 @@ jobs:
178178
workingDirectory: $(Build.SourcesDirectory)
179179

180180
- task: PythonScript@0
181-
displayName: 'Package build output'
181+
displayName: 'Package generic Linux module'
182182
inputs:
183183
scriptSource: 'filePath'
184184
scriptPath: scripts/package.py
185185
arguments: 'bin ${{ parameters.arch }} ${{ parameters.config }} generic bin'
186186
workingDirectory: $(Build.SourcesDirectory)
187+
188+
- task: Bash@3
189+
displayName: 'Check if OpenEnclave module exists'
190+
inputs:
191+
targetType: inline
192+
script: |
193+
if [ -d bin/module/oe_full ]; then
194+
echo "##vso[task.setVariable variable=PACKAGE_OE]true"
195+
fi
196+
197+
- task: PythonScript@0
198+
displayName: 'Package OpenEnclave module'
199+
condition: eq(variables.PACKAGE_OE, 'true')
200+
inputs:
201+
scriptSource: 'filePath'
202+
scriptPath: scripts/package.py
203+
arguments: 'bin ${{ parameters.arch }} ${{ parameters.config }} oe_full bin'
204+
workingDirectory: $(Build.SourcesDirectory)

.pipelines/templates/build-windows-cmake.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ parameters:
2020
- name: identifier # Additional identifier for job name
2121
type: string
2222
default: ''
23+
- name: sign # Sign user-mode binaries. Required by Guardian, even though we don't publish Windows binaries from CMake
24+
type: boolean
25+
default: false
2326

2427
jobs:
2528

@@ -71,3 +74,12 @@ jobs:
7174
scriptPath: scripts\test.py
7275
arguments: 'bin dynamic:bin\exe\symcrypttestmodule.dll noperftests'
7376
workingDirectory: $(Build.SourcesDirectory)
77+
78+
- task: onebranch.pipeline.signing@1 # https://aka.ms/obpipelines/signing
79+
displayName: 'Sign Binaries'
80+
condition: eq('${{ parameters.sign }}', true)
81+
inputs:
82+
command: 'sign'
83+
signing_profile: 'external_distribution'
84+
files_to_sign: '**\*.exe;**\*.dll' # Only supports user mode binaries
85+
search_root: 'bin'

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ prior to the creation of a new release, based on the changes contained in that r
99
- Fix tweak lower 64 bit overflow calculation in SYMCRYPT_XtsAesXxx
1010
- Add OpenSSL implementation for XtsAes to symcryptunittest
1111
- Add Windows user mode DLL
12+
- Fixed debug assertion failure in AES-GCM with nonce < 12 bytes when ASM is disabled
1213

1314
# Version 103.4.1
1415
- Add retpoline guard flags for undocked Windows build

lib/gcm.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,11 @@ SymCryptGcmSetNonce(
353353
BYTE buf[SYMCRYPT_GF128_BLOCK_SIZE];
354354
SIZE_T cbNonceRemainder = cbNonce & 0xf;
355355

356-
SymCryptGHashAppendData( &pState->pKey->ghashKey, &pState->ghashState, pbNonce,
357-
cbNonce - cbNonceRemainder );
356+
if(cbNonce >= SYMCRYPT_GF128_BLOCK_SIZE)
357+
{
358+
SymCryptGHashAppendData( &pState->pKey->ghashKey, &pState->ghashState, pbNonce,
359+
cbNonce - cbNonceRemainder );
360+
}
358361

359362
// If the nonce length is not a multiple of 128 bits, it needs to be padded with zeros
360363
// until it is, as GHASH is only defined on multiples of 128 bits.

0 commit comments

Comments
 (0)