8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047

Changed variable declaration type to byte* from long* to fix SIGBUS error

Reviewed-by: ascarpino
This commit is contained in:
Valerie Peng 2019-02-20 19:16:45 +00:00
parent 315b7d0399
commit 9d263d4bc1
2 changed files with 17 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -106,7 +106,7 @@ abstract class P11Key implements Key, Length {
static { static {
PrivilegedAction<String> getKeyExtractionProp = PrivilegedAction<String> getKeyExtractionProp =
() -> System.getProperty( () -> System.getProperty(
"sun.security.pkcs11.disableKeyExtraction", "true"); "sun.security.pkcs11.disableKeyExtraction", "false");
String disableKeyExtraction = String disableKeyExtraction =
AccessController.doPrivileged(getKeyExtractionProp); AccessController.doPrivileged(getKeyExtractionProp);
DISABLE_NATIVE_KEYS_EXTRACTION = DISABLE_NATIVE_KEYS_EXTRACTION =

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
*/ */
/* Copyright (c) 2002 Graz University of Technology. All rights reserved. /* Copyright (c) 2002 Graz University of Technology. All rights reserved.
@ -151,14 +151,14 @@ Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo
unsigned int i = 0U; unsigned int i = 0U;
unsigned long totalDataSize = 0UL, attributesCount = 0UL; unsigned long totalDataSize = 0UL, attributesCount = 0UL;
unsigned long totalCkAttributesSize = 0UL, totalNativeKeyInfoArraySize = 0UL; unsigned long totalCkAttributesSize = 0UL, totalNativeKeyInfoArraySize = 0UL;
unsigned long* wrappedKeySizePtr = NULL; jbyte* wrappedKeySizePtr = NULL;
jbyte* nativeKeyInfoArrayRawCkAttributes = NULL; jbyte* nativeKeyInfoArrayRawCkAttributes = NULL;
jbyte* nativeKeyInfoArrayRawCkAttributesPtr = NULL; jbyte* nativeKeyInfoArrayRawCkAttributesPtr = NULL;
jbyte* nativeKeyInfoArrayRawDataPtr = NULL; jbyte* nativeKeyInfoArrayRawDataPtr = NULL;
CK_MECHANISM ckMechanism; CK_MECHANISM ckMechanism;
char iv[16] = {0x0}; char iv[16] = {0x0};
CK_ULONG ckWrappedKeyLength = 0U; CK_ULONG ckWrappedKeyLength = 0U;
unsigned long* wrappedKeySizeWrappedKeyArrayPtr = NULL; jbyte* wrappedKeySizeWrappedKeyArrayPtr = NULL;
CK_BYTE_PTR wrappedKeyBufferPtr = NULL; CK_BYTE_PTR wrappedKeyBufferPtr = NULL;
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
CK_OBJECT_CLASS class; CK_OBJECT_CLASS class;
@ -234,7 +234,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo
// * sizes are expressed in bytes and data type is unsigned long // * sizes are expressed in bytes and data type is unsigned long
totalCkAttributesSize = attributesCount * sizeof(CK_ATTRIBUTE); totalCkAttributesSize = attributesCount * sizeof(CK_ATTRIBUTE);
TRACE1("DEBUG: GetNativeKeyInfo attributesCount = %lu\n", attributesCount); TRACE1("DEBUG: GetNativeKeyInfo attributesCount = %lu\n", attributesCount);
TRACE1("DEBUG: GetNativeKeyInfo sizeof CK_ATTRIBUTE = %lu\n", sizeof(CK_ATTRIBUTE)); TRACE1("DEBUG: GetNativeKeyInfo sizeof CK_ATTRIBUTE = %zu\n", sizeof(CK_ATTRIBUTE));
TRACE1("DEBUG: GetNativeKeyInfo totalCkAttributesSize = %lu\n", totalCkAttributesSize); TRACE1("DEBUG: GetNativeKeyInfo totalCkAttributesSize = %lu\n", totalCkAttributesSize);
TRACE1("DEBUG: GetNativeKeyInfo totalDataSize = %lu\n", totalDataSize); TRACE1("DEBUG: GetNativeKeyInfo totalDataSize = %lu\n", totalDataSize);
@ -254,8 +254,8 @@ Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo
goto cleanup; goto cleanup;
} }
wrappedKeySizePtr = (unsigned long*)(nativeKeyInfoArrayRaw + wrappedKeySizePtr = nativeKeyInfoArrayRaw +
sizeof(unsigned long)*2 + totalCkAttributesSize + totalDataSize); sizeof(unsigned long)*2 + totalCkAttributesSize + totalDataSize;
memcpy(nativeKeyInfoArrayRaw, &totalCkAttributesSize, sizeof(unsigned long)); memcpy(nativeKeyInfoArrayRaw, &totalCkAttributesSize, sizeof(unsigned long));
memcpy(nativeKeyInfoArrayRaw + sizeof(unsigned long) + totalCkAttributesSize, memcpy(nativeKeyInfoArrayRaw + sizeof(unsigned long) + totalCkAttributesSize,
@ -330,15 +330,15 @@ Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo
memcpy(nativeKeyInfoWrappedKeyArrayRaw, nativeKeyInfoArrayRaw, memcpy(nativeKeyInfoWrappedKeyArrayRaw, nativeKeyInfoArrayRaw,
totalNativeKeyInfoArraySize); totalNativeKeyInfoArraySize);
wrappedKeySizeWrappedKeyArrayPtr = wrappedKeySizeWrappedKeyArrayPtr =
(unsigned long*)(nativeKeyInfoWrappedKeyArrayRaw + nativeKeyInfoWrappedKeyArrayRaw +
sizeof(unsigned long)*2 + totalCkAttributesSize + sizeof(unsigned long)*2 + totalCkAttributesSize +
totalDataSize); totalDataSize;
memcpy(wrappedKeySizeWrappedKeyArrayPtr, &ckWrappedKeyLength, sizeof(unsigned long)); memcpy(wrappedKeySizeWrappedKeyArrayPtr, &ckWrappedKeyLength, sizeof(unsigned long));
TRACE1("DEBUG: GetNativeKeyInfo 1st C_WrapKey wrappedKeyLength = %lu\n", ckWrappedKeyLength); TRACE1("DEBUG: GetNativeKeyInfo 1st C_WrapKey wrappedKeyLength = %lu\n", ckWrappedKeyLength);
wrappedKeyBufferPtr = wrappedKeyBufferPtr =
(unsigned char*)wrappedKeySizeWrappedKeyArrayPtr + (CK_BYTE_PTR) (wrappedKeySizeWrappedKeyArrayPtr +
sizeof(unsigned long); sizeof(unsigned long));
rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism, rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism,
jLongToCKULong(jWrappingKeyHandle),ckObjectHandle, jLongToCKULong(jWrappingKeyHandle),ckObjectHandle,
wrappedKeyBufferPtr, &ckWrappedKeyLength); wrappedKeyBufferPtr, &ckWrappedKeyLength);
@ -414,7 +414,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_createNativeKey
jbyte* nativeKeyInfoArrayRawCkAttributesPtr = NULL; jbyte* nativeKeyInfoArrayRawCkAttributesPtr = NULL;
jbyte* nativeKeyInfoArrayRawDataPtr = NULL; jbyte* nativeKeyInfoArrayRawDataPtr = NULL;
unsigned long totalDataSize = 0UL; unsigned long totalDataSize = 0UL;
unsigned long* wrappedKeySizePtr = NULL; jbyte* wrappedKeySizePtr = NULL;
unsigned int i = 0U; unsigned int i = 0U;
CK_MECHANISM ckMechanism; CK_MECHANISM ckMechanism;
char iv[16] = {0x0}; char iv[16] = {0x0};
@ -443,8 +443,8 @@ Java_sun_security_pkcs11_wrapper_PKCS11_createNativeKey
sizeof(unsigned long)); sizeof(unsigned long));
TRACE1("DEBUG: createNativeKey totalDataSize = %lu\n", totalDataSize); TRACE1("DEBUG: createNativeKey totalDataSize = %lu\n", totalDataSize);
wrappedKeySizePtr = (unsigned long*)(nativeKeyInfoArrayRaw + wrappedKeySizePtr = nativeKeyInfoArrayRaw +
sizeof(unsigned long)*2 + totalCkAttributesSize + totalDataSize); sizeof(unsigned long)*2 + totalCkAttributesSize + totalDataSize;
memcpy(&ckWrappedKeyLength, wrappedKeySizePtr, sizeof(unsigned long)); memcpy(&ckWrappedKeyLength, wrappedKeySizePtr, sizeof(unsigned long));
TRACE1("DEBUG: createNativeKey wrappedKeyLength = %lu\n", ckWrappedKeyLength); TRACE1("DEBUG: createNativeKey wrappedKeyLength = %lu\n", ckWrappedKeyLength);
@ -470,7 +470,8 @@ Java_sun_security_pkcs11_wrapper_PKCS11_createNativeKey
jMechanismToCKMechanism(env, jWrappingMech, &ckMechanism); jMechanismToCKMechanism(env, jWrappingMech, &ckMechanism);
rv = (*ckpFunctions->C_UnwrapKey)(ckSessionHandle, &ckMechanism, rv = (*ckpFunctions->C_UnwrapKey)(ckSessionHandle, &ckMechanism,
jLongToCKULong(jWrappingKeyHandle), jLongToCKULong(jWrappingKeyHandle),
(CK_BYTE_PTR)(wrappedKeySizePtr + 1), ckWrappedKeyLength, (CK_BYTE_PTR)(wrappedKeySizePtr + sizeof(unsigned long)),
ckWrappedKeyLength,
(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributes, (CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributes,
jLongToCKULong(nativeKeyInfoCkAttributesCount), jLongToCKULong(nativeKeyInfoCkAttributesCount),
&ckObjectHandle); &ckObjectHandle);