From c2fa27c3b8bfd99240bda23fff1b09bb78c5e7fa Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 2 Oct 2020 10:46:57 +0200 Subject: [PATCH] Check maximum amount of arguments to SYS_futex. --- src/shims/posix/linux/sync.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shims/posix/linux/sync.rs b/src/shims/posix/linux/sync.rs index 0892eab4673..a891a7dd994 100644 --- a/src/shims/posix/linux/sync.rs +++ b/src/shims/posix/linux/sync.rs @@ -7,8 +7,11 @@ pub fn futex<'tcx>( args: &[OpTy<'tcx, Tag>], dest: PlaceTy<'tcx, Tag>, ) -> InterpResult<'tcx> { - if args.len() < 4 { - throw_ub_format!("incorrect number of arguments for futex syscall: got {}, expected at least 4", args.len()); + // The amount of arguments used depends on the type of futex operation. + // Some users always pass all arguments, even the unused ones, due to how they wrap this syscall in their code base. + // Some other users pass only the arguments the operation actually needs. So we don't use `check_arg_count` here. + if !(4..=7).contains(&args.len()) { + throw_ub_format!("incorrect number of arguments for futex syscall: got {}, expected between 4 and 7 (inclusive)", args.len()); } let addr = args[1]; let addr_scalar = this.read_scalar(addr)?.check_init()?;