Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialized array variable #23298

Closed
wants to merge 2 commits into from
Closed

Conversation

shashankmca80
Copy link
Contributor

array"key" is uninitialized and it is being read directly in function SipHash_Init() as per the below statements making a way for the garbage values : uint64_t k0 = U8TO64_LE(k);
uint64_t k1 = U8TO64_LE(k + 8);

CLA: trivial

Checklist
  • documentation is added or updated
  • tests are added or updated

array"key" is uninitialized and it is being read directly in function SipHash_Init() as per the below statements making a way for the garbage values :
uint64_t k0 = U8TO64_LE(k);
uint64_t k1 = U8TO64_LE(k + 8);

CLA: trivial
@@ -257,7 +257,7 @@ static int test_siphash(int idx)
static int test_siphash_basic(void)
{
SIPHASH siphash = { 0, };
unsigned char key[SIPHASH_KEY_SIZE];
unsigned char key[SIPHASH_KEY_SIZE] = {0};
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't needed, its initalized on line 191 before use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There , it is initialized in the function test_siphash() but not in test_siphash_basic(). In both the functions, it's a local variable . In test_siphash_basic(), it's being passed directly to the following function SipHash_Init().

TEST_true(SipHash_Init(&siphash, key, 0, 0));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, test_siphash_basic() is called at the earliest as suggested by the following code:

int setup_tests(void)
{
ADD_TEST(test_siphash_basic);
ADD_ALL_TESTS(test_siphash, OSSL_NELEM(tests));
return 1;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

in test_siphash_basic, it seems whatever garbage is on the stack is being used as a key, and SipHash_Init translates the unsigned char that we pass to two uint64 variables starting at indexes 0 and 8. Given that SIPHASH_KEY_SIZE is defined as 16, it won't overrun the array. It doesn't hurt to initalize it, but what you're doing means we're going to test with a key that is all zeros, which is fine, but probably not whats intended. If it needs to be initalized, it should likely be initalized with some concrete key that is something other than all zeros (though that might not hurt to test for either)

Copy link
Contributor

Choose a reason for hiding this comment

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

Uninitialised memory on the stack will either lead to unspecified values or trap representations being used. A trap representation would lead to undefined behaviour, but uint64_t on two's complement systems (in practice all that are likely to be seen) does not have a trap value, so on two's complement systems this won't lead to undefined behaviour.

On one's complement systems it's implementation-defined whether "all ones" is a trap representation, so this could potentially be an issue there.

I agree that "all zeroes" might not be the best value to use - it might be best to bring in the initialisation from test_siphash()

Copy link
Member

Choose a reason for hiding this comment

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

I think using all-zero key for this particular test is OK. Please just make the variable static const as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Please review.

@t8m t8m added branch: master Merge to master branch triaged: bug The issue/pr is/fixes a bug branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 tests: exempted The PR is exempt from requirements for testing branch: 3.2 Merge to openssl-3.2 labels Jan 15, 2024
Making the array variable static const as well.
static const unsigned char key[SIPHASH_KEY_SIZE] = {0};

CLA: trivial
@t8m t8m added the approval: review pending This pull request needs review by a committer label Jan 15, 2024
@t8m
Copy link
Member

t8m commented Jan 15, 2024

OK with CLA: trivial

@t8m t8m added the cla: trivial One of the commits is marked as 'CLA: trivial' label Jan 15, 2024
Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-arm left a comment

Choose a reason for hiding this comment

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

LGTM; okay with trivial

@tom-cosgrove-arm tom-cosgrove-arm added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Jan 15, 2024
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Jan 16, 2024
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@t8m
Copy link
Member

t8m commented Jan 19, 2024

Merged to the master, 3.2, 3.1 and 3.0 branches. Thank you for your contribution.

@t8m t8m closed this Jan 19, 2024
openssl-machine pushed a commit that referenced this pull request Jan 19, 2024
array"key" is uninitialized and it is being read directly in function SipHash_Init() as per the below statements making a way for the garbage values :
uint64_t k0 = U8TO64_LE(k);
uint64_t k1 = U8TO64_LE(k + 8);

CLA: trivial

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #23298)

(cherry picked from commit a0826b1)
openssl-machine pushed a commit that referenced this pull request Jan 19, 2024
array"key" is uninitialized and it is being read directly in function SipHash_Init() as per the below statements making a way for the garbage values :
uint64_t k0 = U8TO64_LE(k);
uint64_t k1 = U8TO64_LE(k + 8);

CLA: trivial

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #23298)
openssl-machine pushed a commit that referenced this pull request Jan 19, 2024
array"key" is uninitialized and it is being read directly in function SipHash_Init() as per the below statements making a way for the garbage values :
uint64_t k0 = U8TO64_LE(k);
uint64_t k1 = U8TO64_LE(k + 8);

CLA: trivial

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #23298)

(cherry picked from commit a0826b1)
openssl-machine pushed a commit that referenced this pull request Jan 19, 2024
array"key" is uninitialized and it is being read directly in function SipHash_Init() as per the below statements making a way for the garbage values :
uint64_t k0 = U8TO64_LE(k);
uint64_t k1 = U8TO64_LE(k + 8);

CLA: trivial

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #23298)

(cherry picked from commit a0826b1)
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 Merge to master branch branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 branch: 3.2 Merge to openssl-3.2 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.

None yet

5 participants