From 8c916a9913d8a5e49c8a41feec31eae212e04411 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 8 Feb 2022 02:21:24 +0000 Subject: ripple/minitrace: enforce openat flags Co-authored-by: V Change-Id: Id848249e6b4a3de612d298d434c59889ba93b300 --- ripple/minitrace/src/main.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'ripple/minitrace/src') diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs index 6b7c044..424c6f2 100644 --- a/ripple/minitrace/src/main.rs +++ b/ripple/minitrace/src/main.rs @@ -4,6 +4,7 @@ use { anyhow::{bail, Context, Result}, + bitflags::bitflags, nix::{ libc, sys::{ @@ -263,17 +264,19 @@ fn check_syscall(process: &Process, entry: SyscallEntry) -> bool { // openat 257 => { - let [dirfd, pathname, _flags, _mode, _, _] = entry.args; + let [dirfd, pathname, flags, _mode, _, _] = entry.args; const AT_FDCWD: i32 = -100; if dirfd.try_into() == Ok(AT_FDCWD) { return false; } - println!( - "openat(AT_FDCWD, {:?}, ..)", - process.read_mem_cstr(pathname).unwrap() - ); + let pathname = process.read_mem_cstr(pathname).unwrap(); + + let flags: i32 = flags.try_into().expect("openat(2) flags don't fit in i32"); + let flags = OpenFlags::from_bits(flags).expect("unknown openat flags"); + + println!("openat(AT_FDCWD, {:?}, {:?}, ..)", pathname, flags); } // newfstatat @@ -296,3 +299,13 @@ fn check_syscall(process: &Process, entry: SyscallEntry) -> bool { } true } + +bitflags! { + struct OpenFlags: i32 { + const WRONLY = 0o00000001; + const CREAT = 0o00000100; + const NOCTTY = 0o00000400; + const TRUNC = 0o00001000; + const CLOEXEC = 0o02000000; + } +} -- cgit 1.4.1