fix some more edge cases in PDDB key deletion

This commit is contained in:
bunnie 2023-01-20 18:07:24 +08:00
parent ea913a6fb4
commit 71a1dddf15
2 changed files with 17 additions and 1 deletions

View file

@ -572,7 +572,11 @@ impl BasisCache {
// this implementation is still in progress
dict_entry.key_erase(key);
}
// sync the key pools to disk
if !dict_entry.sync_small_pool(hw, &mut basis.v2p_map, &basis.cipher) {
return Err(Error::new(ErrorKind::OutOfMemory, "Ran out of memory syncing small pool"));
}
dict_entry.sync_large_pool();
// encrypt and write the dict entry to disk
basis.dict_sync(hw, dict)?;
@ -1697,6 +1701,13 @@ impl BasisCacheEntry {
}
}
for dict in dictnames {
if let Some(dict_entry) = self.dicts.get_mut(&dict) {
if !dict_entry.sync_small_pool(hw, &mut self.v2p_map, &self.cipher) {
return Err(Error::new(ErrorKind::OutOfMemory, "Ran out of memory syncing small pool"));
}
dict_entry.sync_large_pool();
}
match self.dict_sync(hw, &dict) {
Ok(_) => {},
Err(e) => {

View file

@ -307,6 +307,10 @@ impl DictCacheEntry {
fn try_fill_small_key(&mut self, hw: &mut PddbOs, v2p_map: &HashMap::<VirtAddr, PhysPage>, cipher: &Aes256GcmSiv,
data_cache: &mut PlaintextCache, key_name: &str) {
if let Some(kcache) = self.keys.get_mut(key_name) {
if !kcache.flags.valid() {
// nothing to fill, the key entry isn't valid
return;
}
if let Some(pool_index) = small_storage_index_from_key(&kcache, self.index) {
// if the key is within the small pool space, create a bookkeeping record for it, and pre-cache its data.
// generate the index within the small pool based on the address
@ -1014,7 +1018,8 @@ impl DictCacheEntry {
log::error!("Double-free error in free_keys()");
log::info!("free_key_vec[i].0: {:?}", free_key_vec[i].0);
log::info!("index: {}", index);
panic!("Double-free error in free_keys()");
panic!("Double-free error in free_keys(). free_key_vec[i].0: {:?}, index: {}, free_key_vec.len(): {}",
free_key_vec[i].0, index, free_key_vec.len());
}
FreeKeyCases::RightAdjacent => {
// see if we should merge to the right