Skip to content

Commit 01353de

Browse files
committed
Remove need for buffer validation by slightly modifying function signatures
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent bdfd20b commit 01353de

File tree

3 files changed

+14
-41
lines changed

3 files changed

+14
-41
lines changed

src/hyperlight_common/src/flatbuffer_wrappers/function_call.rs

-24
Original file line numberDiff line numberDiff line change
@@ -227,30 +227,6 @@ impl FunctionCall {
227227
}
228228
}
229229

230-
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
231-
pub fn validate_guest_function_call_buffer(function_call_buffer: &[u8]) -> Result<()> {
232-
let guest_function_call_fb = size_prefixed_root::<FbFunctionCall>(function_call_buffer)
233-
.map_err(|e| anyhow::anyhow!("Error reading function call buffer: {:?}", e))?;
234-
match guest_function_call_fb.function_call_type() {
235-
FbFunctionCallType::guest => Ok(()),
236-
other => {
237-
bail!("Invalid function call type: {:?}", other);
238-
}
239-
}
240-
}
241-
242-
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
243-
pub fn validate_host_function_call_buffer(function_call_buffer: &[u8]) -> Result<()> {
244-
let host_function_call_fb = size_prefixed_root::<FbFunctionCall>(function_call_buffer)
245-
.map_err(|e| anyhow::anyhow!("Error reading function call buffer: {:?}", e))?;
246-
match host_function_call_fb.function_call_type() {
247-
FbFunctionCallType::host => Ok(()),
248-
other => {
249-
bail!("Invalid function call type: {:?}", other);
250-
}
251-
}
252-
}
253-
254230
impl TryFrom<&[u8]> for FunctionCall {
255231
type Error = Error;
256232
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]

src/hyperlight_host/src/func/guest_dispatch.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
use flatbuffers::FlatBufferBuilder;
1817
use hyperlight_common::flatbuffer_wrappers::function_call::{FunctionCall, FunctionCallType};
1918
use hyperlight_common::flatbuffer_wrappers::function_types::{
2019
ParameterValue, ReturnType, ReturnValue,
@@ -50,11 +49,8 @@ pub(crate) fn call_function_on_guest<WrapperGetterT: WrapperGetter>(
5049
);
5150

5251
{
53-
let mut builder = FlatBufferBuilder::new();
5452
let mem_mgr = wrapper_getter.get_mgr_wrapper_mut();
55-
mem_mgr
56-
.as_mut()
57-
.write_guest_function_call(fc.encode(&mut builder))?;
53+
mem_mgr.as_mut().write_guest_function_call(&fc)?;
5854
}
5955

6056
let mut hv_handler = wrapper_getter.get_hv_handler().clone();

src/hyperlight_host/src/mem/mgr.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ use std::cmp::Ordering;
1919
use std::str::from_utf8;
2020
use std::sync::{Arc, Mutex};
2121

22-
use hyperlight_common::flatbuffer_wrappers::function_call::{
23-
validate_guest_function_call_buffer, FunctionCall,
24-
};
22+
use flatbuffers::FlatBufferBuilder;
23+
use hyperlight_common::flatbuffer_wrappers::function_call::{FunctionCall, FunctionCallType};
2524
use hyperlight_common::flatbuffer_wrappers::function_types::ReturnValue;
2625
use hyperlight_common::flatbuffer_wrappers::guest_error::{ErrorCode, GuestError};
2726
use hyperlight_common::flatbuffer_wrappers::guest_log_data::GuestLogData;
@@ -617,18 +616,20 @@ impl SandboxMemoryManager<HostSharedMemory> {
617616

618617
/// Writes a guest function call to memory
619618
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
620-
pub(crate) fn write_guest_function_call(&mut self, buffer: &[u8]) -> Result<()> {
621-
validate_guest_function_call_buffer(buffer).map_err(|e| {
622-
new_error!(
623-
"Guest function call buffer validation failed: {}",
624-
e.to_string()
625-
)
626-
})?;
627-
619+
pub(crate) fn write_guest_function_call(&mut self, function_call: &FunctionCall) -> Result<()> {
620+
match function_call.function_call_type() {
621+
FunctionCallType::Host => {
622+
log_then_return!(
623+
"Tried to serialize a host function call as a guest function call"
624+
);
625+
}
626+
FunctionCallType::Guest => {}
627+
};
628+
let mut builder = FlatBufferBuilder::new();
628629
self.shared_mem.push_buffer(
629630
self.layout.input_data_buffer_offset,
630631
self.layout.sandbox_memory_config.get_input_data_size(),
631-
buffer,
632+
function_call.encode(&mut builder),
632633
)
633634
}
634635

0 commit comments

Comments
 (0)