Skip to content

Commit f518786

Browse files
Shachar Levysamuel-lee-msft
authored andcommitted
Merged PR 10534989: Fix CallBackAlloc to adjust the nBytes in case the size is not aligned.
## Description: SymCryptCallBackAlloc failed as part of a call to SymCryptRsakeyGenerate with the new SymCrypt. After investigation, the failure occurs since we changed the API from "posix_alloc" to "aligned_alloc". aligned_alloc - expect to get the number of bytes to allocate as an integral multiple of the alignment. So, when passing not a multiple of the alignment number the function failed. I suspect this issue is important since the regular Linux product use the API without the check of the size alignment. Hence, I created this PR with a fix that adjust the size we receive to be aligned. ## Admin Checklist: - [ ] You have updated documentation in symcrypt.h to reflect any changes in behavior - [ ] You have updated CHANGELOG.md to reflect any changes in behavior - [ ] You have updated symcryptunittest to exercise any new functionality - [ ] If you have introduced any symbols in symcrypt.h you have updated production and test dynamic export symbols (exports.ver / exports.def / symcrypt.src) and tested the updated dynamic modules with symcryptunittest - [ ] If you have introduced functionality that varies based on CPU features, you have manually tested with and without relevant features - [ ] If you have made significant changes to a particular algorithm, you have checked that performance numbers reported by symcryptunittest are in line with expectations - [ ] If you have added new algorithms/modes, you have updated the status indicator text for the associated modules if necessary Fix CallBackAlloc to adjust the nBytes for allocation in case the size is not aligned Signed-off-by: v-shlevy <[email protected]> Related work items: #49419416
1 parent d02569c commit f518786

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

modules/linux/common/callbacks_pthread.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ PVOID
1212
SYMCRYPT_CALL
1313
SymCryptCallbackAlloc( SIZE_T nBytes )
1414
{
15-
return aligned_alloc(SYMCRYPT_ASYM_ALIGN_VALUE, nBytes);
15+
// aligned_alloc requires size to be integer multiple of alignment
16+
SIZE_T cbAllocation = (nBytes + (SYMCRYPT_ASYM_ALIGN_VALUE - 1)) & ~(SYMCRYPT_ASYM_ALIGN_VALUE - 1);
17+
18+
return aligned_alloc(SYMCRYPT_ASYM_ALIGN_VALUE, cbAllocation);
1619
}
1720

1821
VOID

modules/linux/common/callbacks_singlethreaded.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ PVOID
1111
SYMCRYPT_CALL
1212
SymCryptCallbackAlloc( SIZE_T nBytes )
1313
{
14-
return aligned_alloc(SYMCRYPT_ASYM_ALIGN_VALUE, nBytes);;
14+
// aligned_alloc requires size to be integer multiple of alignment
15+
SIZE_T cbAllocation = (nBytes + (SYMCRYPT_ASYM_ALIGN_VALUE - 1)) & ~(SYMCRYPT_ASYM_ALIGN_VALUE - 1);
16+
17+
return aligned_alloc(SYMCRYPT_ASYM_ALIGN_VALUE, cbAllocation);
1518
}
1619

1720
VOID

0 commit comments

Comments
 (0)