[libos] Fix gvisor setsockopt/getsockopt bugs

This commit is contained in:
ClawSeven 2024-05-06 16:12:30 +08:00 committed by volcano
parent 5dfa017a76
commit b80450ef96
3 changed files with 10 additions and 10 deletions

@ -35,7 +35,8 @@ impl GetSockOptRawCmd {
}
pub fn output(&self) -> Option<&[u8]> {
self.optlen.map(|_| self.optval.as_ref())
self.optlen
.map(|opt_len| &self.optval[..(opt_len as usize)])
}
}

@ -5,12 +5,11 @@ use libc::ocall::setsockopt as do_setsockopt;
pub struct SetSockOptRawCmd {
level: i32,
optname: i32,
optval: Box<[u8]>,
optval: &'static [u8],
}
impl SetSockOptRawCmd {
pub fn new(level: i32, optname: i32, optval: &[u8]) -> Self {
let optval = Box::from(optval);
pub fn new(level: i32, optname: i32, optval: &'static [u8]) -> Self {
Self {
level,
optname,

@ -274,10 +274,6 @@ pub fn do_setsockopt(
);
let file_ref = current!().file(fd as FileDesc)?;
if optval as usize != 0 && optlen == 0 && ENABLE_URING.load(Ordering::Relaxed) {
return_errno!(EINVAL, "the optlen size is 0");
}
let optval = from_user::make_slice(optval as *const u8, optlen as usize)?;
if let Ok(host_socket) = file_ref.as_host_socket() {
@ -1132,7 +1128,11 @@ fn new_uring_getsockopt_cmd(
}
/// Create a new ioctl command for host socket setsockopt syscall
fn new_host_setsockopt_cmd(level: i32, optname: i32, optval: &[u8]) -> Result<Box<dyn IoctlCmd>> {
fn new_host_setsockopt_cmd(
level: i32,
optname: i32,
optval: &'static [u8],
) -> Result<Box<dyn IoctlCmd>> {
if level != libc::SOL_SOCKET {
return Ok(Box::new(SetSockOptRawCmd::new(level, optname, optval)));
}
@ -1162,7 +1162,7 @@ fn new_host_setsockopt_cmd(level: i32, optname: i32, optval: &[u8]) -> Result<Bo
fn new_uring_setsockopt_cmd(
level: i32,
optname: i32,
optval: &[u8],
optval: &'static [u8],
socket_type: Type,
) -> Result<Box<dyn IoctlCmd>> {
if level != libc::SOL_SOCKET {