Skip to content

Commit

Permalink
ext_config: Fixes config only operations.
Browse files Browse the repository at this point in the history
Previously we were passing the u64 value of the
pointer to the vector of bytes the extended
report certificates were being loaded from.
However, when handling the case of an extended
configuration only, because the pointer value
of an empty vector is not 0, this was causing
an error in the kernel when attempting to access
the "pointer" being provided. By modifying the
underlying type of `bytes` to `Option<Vec<u8>>`,
it allows the default value to be set to `None`,
and conditionally update the extended config
`certs_address` field when certificate bytes are
present.

Signed-off-by: Larry Dewey <[email protected]>
  • Loading branch information
larrydewey committed Dec 1, 2023
1 parent d16e8f2 commit 04b3425
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/firmware/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,17 @@ impl Firmware {
/// ```
#[cfg(feature = "snp")]
pub fn snp_set_ext_config(&mut self, mut new_config: ExtConfig) -> Result<(), UserApiError> {
let mut bytes: Vec<u8> = vec![];
let mut opt_bytes: Option<Vec<u8>> = None;

if let Some(ref mut certificates) = new_config.certs {
bytes = FFI::types::CertTableEntry::uapi_to_vec_bytes(certificates)?;
opt_bytes = Some(FFI::types::CertTableEntry::uapi_to_vec_bytes(certificates)?);
}

let mut new_ext_config: FFI::types::SnpSetExtConfig = new_config.try_into()?;
new_ext_config.certs_address = bytes.as_mut_ptr() as u64;

if let Some(ref mut bytes) = opt_bytes {
new_ext_config.certs_address = bytes.as_mut_ptr() as u64;
}

SNP_SET_EXT_CONFIG.ioctl(&mut self.0, &mut Command::from_mut(&mut new_ext_config))?;

Expand Down

0 comments on commit 04b3425

Please sign in to comment.