Skip to content

Conversation

swenson
Copy link
Contributor

@swenson swenson commented Aug 29, 2025

Splitting up #2405 into a few parts as suggest by @alex.

This adds the param-builder.

Original commit message:

Add internal module to simplify working with OSSL_PARAM structure We discussed that this API is not well suitable for the end users but still, it required for several operations in OpenSSL 3.* so instead of calling to FFI for every use of this API, this introduces simple wrappers that allow building of the params and their usage.

@alex
Copy link
Collaborator

alex commented Aug 29, 2025

If you can put the openssl-sys changes into their own PR, it makes it considerably easier to review. thanks.

@swenson
Copy link
Contributor Author

swenson commented Aug 29, 2025

No problem.

@swenson swenson force-pushed the pqc-param-builder branch from 8720778 to 935f6cf Compare August 29, 2025 04:14
@swenson
Copy link
Contributor Author

swenson commented Aug 29, 2025

@alex this is just the param builder and the related Argon changes now, I believe.

@alex
Copy link
Collaborator

alex commented Aug 29, 2025 via email

@alex
Copy link
Collaborator

alex commented Aug 29, 2025

Merge conflicts, sorry :-(

Splitting up sfackler#2405 into a few parts as suggest by @alex.

This adds the param-builder and other openssl-sys changes.

Original commit message:

Add internal module to simplify working with OSSL_PARAM structure
We discussed that this API is not well suitable for the end users
but still, it required for several operations in OpenSSL 3.* so
instead of calling to FFI for every use of this API, this
introduces simple wrappers that allow building of the params
and their usage.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Co-authored-by: Justus Winter <justus@sequoia-pgp.org>
@swenson swenson force-pushed the pqc-param-builder branch from 935f6cf to 69182d1 Compare August 29, 2025 18:15
@swenson
Copy link
Contributor Author

swenson commented Aug 29, 2025

@alex no worries, rebased

@swenson swenson force-pushed the pqc-param-builder branch from 643db6e to 131cddd Compare August 30, 2025 02:21
@swenson
Copy link
Contributor Author

swenson commented Sep 6, 2025

@alex anything else you wanted to address with this PR?

@alex
Copy link
Collaborator

alex commented Sep 7, 2025

Sigh, sorry there was a review comment that apparently never got submitted (and is caught in limbo). Unfortunately the lifetime changes aren't enough:

use std::ffi::CStr;


pub struct OsslParamBuilderRef;
impl OsslParamBuilderRef {
    pub(crate) fn add_octet_string<'a>(
        &'a mut self,
        _key: &'a CStr,
        _buf: &'a [u8],
    ) -> Result<(), ()> {
        Ok(())
    }
}

pub fn f(x: &mut OsslParamBuilderRef) -> Result<(), ()> {
    let key = std::ffi::CString::new(b"my str").unwrap();
    x.add_octet_string(&key, &[])
}

this compiles, and has a UAF.

@swenson
Copy link
Contributor Author

swenson commented Sep 7, 2025

@alex Absolutely right. For some reason I thought adding &'a to the mut self would be sufficient, but that only ties it to the lifetime of the borrow (?) and not of the actual builder struct.

I think this latest commit correctly adds the lifetime bound, e.g., I ran this test based on yours:

#[cfg(test)]
mod test {
    #[test]
    fn test_osssl_param_builder() {
        let mut p = crate::ossl_param::OsslParamBuilder::new().unwrap();
        {
            let key = std::ffi::CString::new(b"my str").unwrap();
            p.add_octet_string(&key, &[]).unwrap();
        }
        p.to_param().unwrap();
    }
}

Before, it compiled (incorrectly), but now it fails to compile as expected with:

error[E0597]: `key` does not live long enough
   --> openssl/src/ossl_param.rs:162:32
    |
161 |             let key = std::ffi::CString::new(b"my str").unwrap();
    |                 --- binding `key` declared here
162 |             p.add_octet_string(&key, &[]).unwrap();
    |                                ^^^^ borrowed value does not live long enough
163 |         }
    |         - `key` dropped here while still borrowed
164 |         p.to_param().unwrap();
    |         - borrow later used here

@alex
Copy link
Collaborator

alex commented Sep 7, 2025

Great, will review later this afternoon.

Copy link
Collaborator

@alex alex 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 your patience here

@alex alex merged commit 850c00f into sfackler:master Sep 8, 2025
170 of 172 checks passed
@swenson swenson deleted the pqc-param-builder branch September 8, 2025 02:49
@swenson
Copy link
Contributor Author

swenson commented Sep 8, 2025

Thanks!

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.

2 participants