Skip to content

Conversation

@Jakuje
Copy link
Collaborator

@Jakuje Jakuje commented Nov 20, 2025

As returned by SoftHSM: softhsm/SoftHSMv2#825

Fixes: #323

@Jakuje Jakuje force-pushed the allowed-mechanism-attribute branch from a2ac816 to 32243e0 Compare November 20, 2025 11:19
@Jakuje
Copy link
Collaborator Author

Jakuje commented Nov 20, 2025

OTOH this could be considered a softhsm bug (or at least oddness) and as a rust-cryptoki, we might want to shield a users from such pkcs11-module-specific issues. But then we would have to filter this out early in get_attributes, which does not sound great either.

@Jakuje Jakuje requested review from hug-dev and wiktor-k November 20, 2025 11:23
@nwalfield
Copy link
Contributor

nwalfield commented Nov 20, 2025

You already pointed out that at least two attributes can definitely be zero length. It thus seems like a bug in rust-cryptoki that it tries to allocate 0 bytes and expects to get a pointer that can be cast to a raw pointer and passed to std::slice::from_raw_parts:

Behavior is undefined if any of the following conditions are violated:

    data must be non-null, valid for reads for len * size_of::<T>() many bytes, and it must be properly aligned

@wiktor-k
Copy link
Collaborator

You already pointed out that at least two attributes can definitely be zero length. It thus seems like a bug in rust-cryptoki that it tries to allocate 0 bytes and expects to get a pointer that can be cast to a raw pointer and passed to std::slice::from_raw_parts:

Behavior is undefined if any of the following conditions are violated:

    data must be non-null, valid for reads for len * size_of::<T>() many bytes, and it must be properly aligned

Validity rules for reads explicitly point out that:

For memory accesses of size zero, every pointer is valid, including the null pointer.

I'm okay with the change here, with a bit of docs around it, since at first sight it looks like a premature optimization 🤔

@nwalfield
Copy link
Contributor

You already pointed out that at least two attributes can definitely be zero length. It thus seems like a bug in rust-cryptoki that it tries to allocate 0 bytes and expects to get a pointer that can be cast to a raw pointer and passed to std::slice::from_raw_parts:

Behavior is undefined if any of the following conditions are violated:

    data must be non-null, valid for reads for len * size_of::<T>() many bytes, and it must be properly aligned

Validity rules for reads explicitly point out that:

For memory accesses of size zero, every pointer is valid, including the null pointer.

I'm okay with the change here, with a bit of docs around it, since at first sight it looks like a premature optimization 🤔

That's not the only relevant thing. From slice::from_raw_parts:

data must be non-null and aligned even for zero-length slices or slices of ZSTs.

And that's the bug that we are seeing.

@Jakuje Jakuje force-pushed the allowed-mechanism-attribute branch from 32243e0 to 84339fb Compare November 20, 2025 14:13
Copy link

@neverpanic neverpanic left a comment

Choose a reason for hiding this comment

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

Typo, rest lg2m.

@Jakuje Jakuje force-pushed the allowed-mechanism-attribute branch from 84339fb to 0204b08 Compare November 20, 2025 14:28
hug-dev
hug-dev previously approved these changes Nov 24, 2025
Copy link
Member

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

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

Thanks for the fix and the comment ⭐

@Jakuje
Copy link
Collaborator Author

Jakuje commented Dec 3, 2025

@wiktor-k can you have a look and approve if this looks ok?

wiktor-k
wiktor-k previously approved these changes Dec 3, 2025
Copy link
Collaborator

@wiktor-k wiktor-k left a comment

Choose a reason for hiding this comment

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

I think this looks good 👌 a couple of small suggestions, if you don't mind.

Btw, thanks for the ping, quite a lot on the plate recently 😅

@Jakuje Jakuje dismissed stale reviews from wiktor-k and hug-dev via 780b7a2 December 3, 2025 11:21
@Jakuje Jakuje force-pushed the allowed-mechanism-attribute branch from 0204b08 to 780b7a2 Compare December 3, 2025 11:21
@Jakuje
Copy link
Collaborator Author

Jakuje commented Dec 3, 2025

oh, no. Something in the ubuntu broke the installation of the 32b arch softhsm ...

@hug-dev
Copy link
Member

hug-dev commented Dec 3, 2025

Is it this line failing? Might be ok to ignore for now...

sudo dpkg --add-architecture i386

@Jakuje
Copy link
Collaborator Author

Jakuje commented Dec 3, 2025

Is it this line failing? Might be ok to ignore for now...

sudo dpkg --add-architecture i386

Hard to say. Would have to try that locally or to get more information from the CI. I am also curious about the kryoptic failure that was not there in #328, in CI which ran last week.

@Jakuje
Copy link
Collaborator Author

Jakuje commented Dec 4, 2025

Is it this line failing? Might be ok to ignore for now...

sudo dpkg --add-architecture i386

Looks like it comes from the last line:

+ sudo apt-get install -y -qq gcc-multilib:i386 libsofthsm2:i386 gcc:i386
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

Removing the -qq gives more information, but they look related to the github build image (but I am really not sure):

+ sudo apt-get install -y gcc-multilib:i386 libsofthsm2:i386 gcc:i386
Reading package lists...
Building dependency tree...
Reading state information...
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 binutils : Conflicts: binutils:i386 but 2.42-4ubuntu2.7 is to be installed
 binutils:i386 : Conflicts: binutils but 2.42-4ubuntu2.6 is to be installed
 binutils-common : Breaks: binutils-common:i386 (!= 2.42-4ubuntu2.6) but 2.42-4ubuntu2.7 is to be installed
 binutils-common:i386 : Breaks: binutils-common (!= 2.42-4ubuntu2.7) but 2.42-4ubuntu2.6 is to be installed
 libbinutils : Breaks: libbinutils:i386 (!= 2.42-4ubuntu2.6) but 2.42-4ubuntu2.7 is to be installed
 libbinutils:i386 : Breaks: libbinutils (!= 2.42-4ubuntu2.7) but 2.42-4ubuntu2.6 is to be installed
 libctf0 : Breaks: libctf0:i386 (!= 2.42-4ubuntu2.6) but 2.42-4ubuntu2.7 is to be installed
 libctf0:i386 : Breaks: libctf0 (!= 2.42-4ubuntu2.7) but 2.42-4ubuntu2.6 is to be installed
 libgprofng0 : Breaks: libgprofng0:i386 (!= 2.42-4ubuntu2.6) but 2.42-4ubuntu2.7 is to be installed
 libgprofng0:i386 : Breaks: libgprofng0 (!= 2.42-4ubuntu2.7) but 2.42-4ubuntu2.6 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

@hug-dev
Copy link
Member

hug-dev commented Dec 5, 2025

I think it should be ok to remove those two failing 32 bits and open an issue to see how we can fix it until then. What about the failing kryoptic test though, do you have any idea of what could be wrong there?

@Jakuje
Copy link
Collaborator Author

Jakuje commented Dec 5, 2025

I think it should be ok to remove those two failing 32 bits and open an issue to see how we can fix it until then.

Looking at the CI configuration, these are not required to pass before merging. So we can probably keep them aronud

What about the failing kryoptic test though, do you have any idea of what could be wrong there?

I tried to reproduce it locally, but I was not successful (but I have likely slightly different openssl version). Its the ed25519 key. We consider these approved under FIPS so it should not be an issue. I will try to dig into that later today.

@Jakuje Jakuje force-pushed the allowed-mechanism-attribute branch 3 times, most recently from cd3b0b5 to 0dbac8f Compare December 8, 2025 14:25
@Jakuje
Copy link
Collaborator Author

Jakuje commented Dec 8, 2025

The softhsm issue is solved, but the kryoptic issue looks like failing inside of the openssl with debug logging turned on:

Error: 0 [ERROR] Openssl Error(50856204): "FIPS internal library context, Algorithm (ED25519CTX : 0), Properties (<null>)"
Error: 0 [ERROR] ossl/src/signature.rs:37: EVP_SIGNATURE_fetch() failed: []
Error: 0 [ERROR] Generic CK error, CKR_DEVICE_ERROR(48)
test sign_verify_eddsa_with_ed25519_schemes ... FAILED

Note, that this is already the second iteration in the test. The EddsaSignatureScheme::Ed25519 worked ok, but the ddsaSignatureScheme::Ed25519ctx(b"context") does not look like working now.

I guess this is some change inside of OpenSSL: And looks like its this one, which landed in openssl 3.5 branch during last two weeks:

openssl/openssl@1b67b76

That said, we will have to skip this signature scheme with fips kryoptic. Let me do that in separate PR so we can merge it irrespective of this PR.

@Jakuje Jakuje force-pushed the allowed-mechanism-attribute branch from 0dbac8f to 15d7cd8 Compare December 8, 2025 16:20
@Jakuje
Copy link
Collaborator Author

Jakuje commented Dec 8, 2025

filled #331. And rebased this one on top of #331.

As returned by SoftHSM: softhsm/SoftHSMv2#825

Fixes: parallaxsecond#323

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
@Jakuje Jakuje force-pushed the allowed-mechanism-attribute branch from 15d7cd8 to ad0810a Compare December 9, 2025 14:15
@Jakuje Jakuje requested review from hug-dev and wiktor-k December 9, 2025 14:15
@Jakuje
Copy link
Collaborator Author

Jakuje commented Dec 9, 2025

Rebased. Should be also ready

@wiktor-k wiktor-k enabled auto-merge December 9, 2025 16:04
@wiktor-k wiktor-k merged commit 979e631 into parallaxsecond:main Dec 9, 2025
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undefined behavior in CK_ATTRIBUTE::try_from or Session::get_attributes

5 participants