From 18607c33ea4c35813de3324d2df5e83dc774a008 Mon Sep 17 00:00:00 2001 From: Marsman1996 Date: Fri, 16 Aug 2024 16:38:38 +0800 Subject: [PATCH] Fix panic in `madv_free()` --- kernel/aster-nix/src/syscall/madvise.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/aster-nix/src/syscall/madvise.rs b/kernel/aster-nix/src/syscall/madvise.rs index 5b12bb7dc..47db5ec1d 100644 --- a/kernel/aster-nix/src/syscall/madvise.rs +++ b/kernel/aster-nix/src/syscall/madvise.rs @@ -33,8 +33,17 @@ pub fn sys_madvise( } fn madv_free(start: Vaddr, len: usize, ctx: &Context) -> Result<()> { - debug_assert!(start % PAGE_SIZE == 0); - debug_assert!(len % PAGE_SIZE == 0); + if start % PAGE_SIZE != 0 { + return_errno_with_message!(Errno::EINVAL, "the start address should be page aligned"); + } + + if len % PAGE_SIZE != 0 { + return_errno_with_message!(Errno::EINVAL, "the length should be page aligned"); + } + + if len == 0 { + return_errno_with_message!(Errno::EINVAL, "madv_free len cannot be zero"); + } let root_vmar = ctx.process.root_vmar(); let advised_range = start..start + len;