summary refs log tree commit diff
path: root/ripple/minitrace/src
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-07-29 17:29:40 +0000
committeredef <edef@unfathomable.blue>2022-07-29 17:29:40 +0000
commit2dedda00b4ab174af853da0d13ea0d74d40645d4 (patch)
tree0a312d036c53fb383e3989532224e4167771c8b9 /ripple/minitrace/src
parent26aeaad5ea9013bbd8ae104ab2edaf800228113e (diff)
downloadunf-legacy-2dedda00b4ab174af853da0d13ea0d74d40645d4.tar.zst
ripple/minitrace: verify newfstatat flags strictly
Change-Id: Ia85d147d493e1d6fb5a67ff5240dc64b17afb1af
Diffstat (limited to 'ripple/minitrace/src')
-rw-r--r--ripple/minitrace/src/main.rs28
1 files changed, 20 insertions, 8 deletions
diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs
index 0f1d278..7d6a41c 100644
--- a/ripple/minitrace/src/main.rs
+++ b/ripple/minitrace/src/main.rs
@@ -287,7 +287,7 @@ define_syscalls! {
 		fn set_tid_address(tidptr: *mut i32) -> i64 = 218;
 		fn exit_group(error_code: i32) -> i64 = 231;
 		fn openat(dfd: FileDesc, filename: CString, flags: OpenFlags, mode: u16) -> i64 = 257;
-		fn newfstatat(dfd: FileDesc, filename: CString, statbuf: *mut Stat, flags: i32) -> i64 = 262;
+		fn newfstatat(dfd: FileDesc, filename: CString, statbuf: *mut Stat, flags: AtFlags) -> i64 = 262;
 		fn set_robust_list(head: *mut RobustListHead, len: usize) -> i64 = 273;
 		fn prlimit64(pid: i32, resource: u32, new_rlim: *const RLimit64, old_rlim: *mut RLimit64) -> i64 = 302;
 		fn getrandom(ubuf: *mut u8, len: usize, flags: GrndFlags) -> i64 = 318;
@@ -450,14 +450,22 @@ fn check_syscall(process: &Process, entry: &SyscallEntry) -> bool {
 			dfd,
 			ref filename,
 			statbuf: _,
-			flags: _,
+			flags,
 		} => {
-			if dfd == AT_FDCWD {
-				println!("newfstatat(AT_FDCWD, {filename:?}, ..)");
-			} else if filename.as_bytes() == b"" {
-				println!("newfstatat({dfd}, {filename:?})");
-			} else {
-				return false;
+			match (dfd, filename.as_bytes()) {
+				(_, b"") if !flags.contains(AtFlags::EMPTY_PATH) => {
+					// empty path without AT_EMPTY_PATH
+					return false;
+				}
+				(AT_FDCWD, _) => {
+					println!("newfstatat(AT_FDCWD, {filename:?}, .., {flags:?})");
+				}
+				(_, b"") if dfd >= 0 => {
+					println!("newfstatat({dfd}, {filename:?}, .., {flags:?})");
+				}
+				_ => {
+					return false;
+				}
 			}
 		}
 		SyscallEntry::set_robust_list { head: _, len } => {
@@ -519,4 +527,8 @@ syscall_bitflags! {
 		const WRITE = 1 << 1 => PROT_WRITE;
 		const EXEC  = 1 << 2 => PROT_EXEC;
 	}
+
+	struct AtFlags: i32 {
+		const EMPTY_PATH = 1 << 12 => AT_EMPTY_PATH;
+	}
 }