| 1 | // On Linux we can use a seccomp() filter to disable exec. |
| 2 | #![allow(non_upper_case_globals)] |
| 3 | #![cfg_attr(not(target_arch = "x86_64"), allow(unused))] |
| 4 | |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::allocrust-analyzer cargo std https://github.com/rust-lang/rust/library/std alloc/::{GlobalAllocrust-analyzer cargo core https://github.com/rust-lang/rust/library/core alloc/global/GlobalAlloc#, Layoutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core alloc/layout/Layout#, handle_alloc_errorrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc alloc/handle_alloc_error().}; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#, c_uintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_uint#, c_ulongrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_ulong#, c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#}; |
| 7 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::{align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of()., offset_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/offset_of!, size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of()., zeroedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/zeroed().}; |
| 8 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::{AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#, AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#, BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#, FromRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/FromRawFd#, OwnedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/OwnedFd#}; |
| 9 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::netrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/::UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#; |
| 10 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/process/::CommandExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/process/CommandExt#; |
| 11 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#; |
| 12 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/, addr_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/addr_of!}; |
| 13 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/}; |
| 14 | |
| 15 | use libcrust-analyzer cargo libc 0.2.186 crate/::{ |
| 16 | __errno_locationrust-analyzer cargo libc 0.2.186 __errno_location()., BPF_ABSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_ABS., BPF_ALUrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_ALU., BPF_ANDrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_AND., BPF_JEQrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JEQ., BPF_JMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JMP., BPF_JUMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JUMP()., BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K., BPF_LDrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_LD., |
| 17 | BPF_RETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_RET., BPF_STMTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_STMT()., BPF_Wrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_W., CMSG_DATArust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_DATA()., CMSG_FIRSTHDRrust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_FIRSTHDR()., CMSG_LENrust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_LEN()., CMSG_SPACErust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_SPACE()., EACCESrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EACCES., ENOENTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/ENOENT., |
| 18 | MSG_TRUNCrust-analyzer cargo libc 0.2.186 unix/linux_like/MSG_TRUNC., PR_SET_NO_NEW_PRIVSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/PR_SET_NO_NEW_PRIVS., SCM_RIGHTSrust-analyzer cargo libc 0.2.186 unix/linux_like/SCM_RIGHTS., SECCOMP_FILTER_FLAG_NEW_LISTENERrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_FILTER_FLAG_NEW_LISTENER., |
| 19 | SECCOMP_GET_NOTIF_SIZESrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_GET_NOTIF_SIZES., SECCOMP_RET_ALLOWrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_RET_ALLOW., SECCOMP_RET_KILL_PROCESSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_RET_KILL_PROCESS., SECCOMP_SET_MODE_FILTERrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_SET_MODE_FILTER., |
| 20 | SECCOMP_USER_NOTIF_FLAG_CONTINUErust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_USER_NOTIF_FLAG_CONTINUE., SOL_SOCKETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/SOL_SOCKET., SYS_execverust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/not_x32/SYS_execve., SYS_execveatrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/not_x32/SYS_execveat., SYS_seccomprust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/not_x32/SYS_seccomp., cmsghdrrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/cmsghdr#, |
| 21 | iovecrust-analyzer cargo libc 0.2.186 unix/iovec#, msghdrrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#, prctlrust-analyzer cargo libc 0.2.186 prctl()., recvmsgrust-analyzer cargo libc 0.2.186 recvmsg()., seccomp_datarust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_data#, seccomp_notifrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif#, seccomp_notif_resprust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_resp#, |
| 22 | seccomp_notif_sizesrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_sizes#, sendmsgrust-analyzer cargo libc 0.2.186 sendmsg()., sock_filterrust-analyzer cargo libc 0.2.186 unix/linux_like/sock_filter#, sock_fprogrust-analyzer cargo libc 0.2.186 unix/linux_like/sock_fprog#, syscallrust-analyzer cargo libc 0.2.186 syscall()., |
| 23 | }; |
| 24 | |
| 25 | const SECCOMP_RET_USER_NOTIFrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SECCOMP_RET_USER_NOTIF.: c_uintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_uint# = 0x7fc00000; |
| 26 | const SECCOMP_IOCTL_NOTIF_RECVrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SECCOMP_IOCTL_NOTIF_RECV.: c_ulongrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_ulong# = 0xc0502100; |
| 27 | const SECCOMP_IOCTL_NOTIF_SENDrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SECCOMP_IOCTL_NOTIF_SEND.: c_ulongrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_ulong# = 0xc0182101; |
| 28 | |
| 29 | // from /usr/include/linux/audit.h, converted using bindgen |
| 30 | const __AUDIT_ARCH_64BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_64BIT.: u32 = 0x80000000; |
| 31 | const __AUDIT_ARCH_LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_LE.: u32 = 0x40000000; |
| 32 | |
| 33 | const AUDIT_ARCH_AARCH64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_AARCH64.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_AARCH64rust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_AARCH64. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_64BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_64BIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_LE.; |
| 34 | const AUDIT_ARCH_ARMrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_ARM.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_ARMrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_ARM. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_LE.; |
| 35 | const AUDIT_ARCH_I386rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_I386.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_386rust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_386. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_LE.; |
| 36 | const AUDIT_ARCH_MIPSrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_MIPS.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_MIPSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_MIPS. as u32; |
| 37 | const AUDIT_ARCH_MIPSELrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_MIPSEL.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_MIPSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_MIPS. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_LE.; |
| 38 | const AUDIT_ARCH_MIPS64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_MIPS64.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_MIPSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_MIPS. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_64BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_64BIT.; |
| 39 | const AUDIT_ARCH_MIPSEL64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_MIPSEL64.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_MIPSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_MIPS. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_64BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_64BIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_LE.; |
| 40 | const AUDIT_ARCH_PPCrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_PPC.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_PPCrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_PPC. as u32; |
| 41 | const AUDIT_ARCH_PPC64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_PPC64.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_PPC64rust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_PPC64. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_64BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_64BIT.; |
| 42 | const AUDIT_ARCH_PPC64LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_PPC64LE.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_PPC64rust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_PPC64. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_64BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_64BIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_LE.; |
| 43 | const AUDIT_ARCH_RISCV32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_RISCV32.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_RISCVrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_RISCV. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_LE.; |
| 44 | const AUDIT_ARCH_RISCV64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_RISCV64.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_RISCVrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_RISCV. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_64BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_64BIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_LE.; |
| 45 | const AUDIT_ARCH_S390Xrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_S390X.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_S390rust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_S390. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_64BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_64BIT.; |
| 46 | const AUDIT_ARCH_X86_64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_X86_64.: u32 = libcrust-analyzer cargo libc 0.2.186 crate/::EM_X86_64rust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EM_X86_64. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_64BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_64BIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().__AUDIT_ARCH_LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__AUDIT_ARCH_LE.; |
| 47 | |
| 48 | /// # Safety |
| 49 | /// |
| 50 | /// You must follow the rules the Linux man page specifies for the chosen |
| 51 | /// seccomp operation. |
| 52 | unsafe fn seccomprust-analyzer cargo sudo-rs 0.2.14 exec/noexec/seccomp().<T>(operation: c_uintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_uint#, flags: c_uintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_uint#, args: *mut T) -> c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int# { |
| 53 | // SAFETY: By function invariant. |
| 54 | unsafe { syscallrust-analyzer cargo libc 0.2.186 syscall().(SYS_seccomprust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/not_x32/SYS_seccomp., operation, flags, args) as c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int# } |
| 55 | } |
| 56 | |
| 57 | struct NotifyAllocsrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs# { |
| 58 | reqrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs#req.: *mut seccomp_notifrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif#, |
| 59 | req_sizerust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs#req_size.: usize, |
| 60 | resprust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs#resp.: *mut seccomp_notif_resprust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_resp#, |
| 61 | } |
| 62 | |
| 63 | /// Linux reserves the right to demand the memory for an object of type T |
| 64 | /// to be over-allocated; this function ensures that happens. |
| 65 | fn alloc_dynamicrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/alloc_dynamic().<T>(runtime_size: u16) -> (*mut T, usize) { |
| 66 | const { |
| 67 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>() >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 68 | } |
| 69 | |
| 70 | let layout = Layoutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core alloc/layout/Layout#::from_size_alignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core alloc/layout/impl#[Layout]from_size_align().( |
| 71 | cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(runtime_size.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>()), |
| 72 | align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<seccomp_notifrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif#>(), |
| 73 | ) |
| 74 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 75 | |
| 76 | // SAFETY: We assert that T is bigger than 0 bytes and as such the computed layout is also |
| 77 | // bigger. |
| 78 | let ptr = unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::allocrust-analyzer cargo std https://github.com/rust-lang/rust/library/std alloc/::Systemrust-analyzer cargo std https://github.com/rust-lang/rust/library/std alloc/System#.alloc_zeroedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sys/alloc/unix/impl#[System][GlobalAlloc]alloc_zeroed().(layout).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<T>() }; |
| 79 | if ptr.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() { |
| 80 | handle_alloc_errorrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc alloc/handle_alloc_error().(layout); |
| 81 | } |
| 82 | |
| 83 | (ptr, layout.sizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core alloc/layout/impl#[Layout]size().()) |
| 84 | } |
| 85 | |
| 86 | fn alloc_notify_allocsrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/alloc_notify_allocs().() -> NotifyAllocsrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs# { |
| 87 | let mut sizes = seccomp_notif_sizesrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_sizes# { |
| 88 | seccomp_notifrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_sizes#seccomp_notif.: 0, |
| 89 | seccomp_notif_resprust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_sizes#seccomp_notif_resp.: 0, |
| 90 | seccomp_datarust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_sizes#seccomp_data.: 0, |
| 91 | }; |
| 92 | // SAFETY: A valid seccomp_notif_sizes pointer is passed in |
| 93 | if unsafe { seccomprust-analyzer cargo sudo-rs 0.2.14 exec/noexec/seccomp().(SECCOMP_GET_NOTIF_SIZESrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_GET_NOTIF_SIZES., 0, &mut sizes) } rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1 { |
| 94 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!( |
| 95 | "failed to get sizes for seccomp unotify data structures: {}", |
| 96 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().(), |
| 97 | ); |
| 98 | } |
| 99 | |
| 100 | let (req, req_size) = alloc_dynamicrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/alloc_dynamic().::<seccomp_notifrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif#>(sizes.seccomp_notifrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_sizes#seccomp_notif.); |
| 101 | let (resp, _) = alloc_dynamicrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/alloc_dynamic().::<seccomp_notif_resprust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_resp#>(sizes.seccomp_notif_resprust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_sizes#seccomp_notif_resp.); |
| 102 | |
| 103 | NotifyAllocsrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs# { |
| 104 | reqrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs#req., |
| 105 | req_sizerust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs#req_size., |
| 106 | resprust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs#resp., |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /// Returns 'None' if the ioctl failed with E_NOENT, 'Some(())' if it succeeded. |
| 111 | /// This aborts the program in any other situation. |
| 112 | /// |
| 113 | /// # Safety |
| 114 | /// |
| 115 | /// `ioctl(fd, request, ptr)` must be safe to call |
| 116 | unsafe fn ioctlrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/ioctl().<T>(fd: BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#, request: c_ulongrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_ulong#, ptr: *mut T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<()> { |
| 117 | // SAFETY: By function contract |
| 118 | if unsafe { libcrust-analyzer cargo libc 0.2.186 crate/::ioctlrust-analyzer cargo libc 0.2.186 ioctl().(fd.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), request as _, ptr) } rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1 { |
| 119 | // SAFETY: Trivial |
| 120 | if unsafe { *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().__errno_locationrust-analyzer cargo libc 0.2.186 __errno_location().() } rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().ENOENTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/ENOENT. { |
| 121 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 122 | } else { |
| 123 | // SAFETY: Not actually unsafe |
| 124 | unsafe { |
| 125 | libcrust-analyzer cargo libc 0.2.186 crate/::abortrust-analyzer cargo libc 0.2.186 abort().(); |
| 126 | } |
| 127 | } |
| 128 | } else { |
| 129 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(()) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /// # Safety |
| 134 | /// |
| 135 | /// The argument must be a valid seccomp_unotify fd. |
| 136 | unsafe fn handle_notificationsrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/handle_notifications().(notify_fd: OwnedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/OwnedFd#) -> ! { |
| 137 | let NotifyAllocsrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs# { |
| 138 | reqrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs#req., |
| 139 | req_sizerust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs#req_size., |
| 140 | resprust-analyzer cargo sudo-rs 0.2.14 exec/noexec/NotifyAllocs#resp., |
| 141 | } = alloc_notify_allocsrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/alloc_notify_allocs().(); |
| 142 | |
| 143 | // SAFETY: See individual SAFETY comments |
| 144 | let handle_syscall = |create_response: fn(&mut _)| unsafe { |
| 145 | // SECCOMP_IOCTL_NOTIF_RECV expects the target struct to be zeroed |
| 146 | // SAFETY: req is at least req_size bytes big. |
| 147 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::write_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write_bytes().(req.castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<u8>(), 0, req_size); |
| 148 | |
| 149 | // SAFETY: A valid pointer to a seccomp_notify is passed in; notify_fd is valid. |
| 150 | ioctlrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/ioctl().(notify_fd.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][AsFd]as_fd().(), SECCOMP_IOCTL_NOTIF_RECVrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SECCOMP_IOCTL_NOTIF_RECV., req)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 151 | |
| 152 | // Allow the first execve call as this is sudo itself starting the target executable. |
| 153 | // SAFETY: resp is a valid pointer to a seccomp_notify_resp. |
| 154 | (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().resp).idrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_resp#id. = (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().req).idrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif#id.; |
| 155 | create_response(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().resp); |
| 156 | |
| 157 | // SAFETY: A valid pointer to a seccomp_notify_resp is passed in; notify_fd is valid. |
| 158 | ioctlrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/ioctl().(notify_fd.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][AsFd]as_fd().(), SECCOMP_IOCTL_NOTIF_SENDrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SECCOMP_IOCTL_NOTIF_SEND., resp) |
| 159 | }; |
| 160 | |
| 161 | loop { |
| 162 | if handle_syscall(|resp| { |
| 163 | resp.valrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_resp#val. = 0; |
| 164 | resp.errorrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_resp#error. = 0; |
| 165 | resp.flagsrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_resp#flags. = SECCOMP_USER_NOTIF_FLAG_CONTINUErust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_USER_NOTIF_FLAG_CONTINUE. as _ |
| 166 | }) |
| 167 | .is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() |
| 168 | { |
| 169 | break; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | loop { |
| 174 | handle_syscall(|resp| { |
| 175 | resp.valrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_resp#val. = 0; |
| 176 | resp.errorrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_resp#error. = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().EACCESrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/EACCES.; |
| 177 | resp.flagsrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_notif_resp#flags. = 0; |
| 178 | }); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | //We must use vectored reads with ancillary data. |
| 183 | // |
| 184 | //NOTE: some day we can witch to using send/recv_vectored_with_ancillary; see: |
| 185 | // - https://doc.rust-lang.org/std/os/unix/net/struct.UnixDatagram.html#method.recv_vectored_with_ancillary |
| 186 | // - https://doc.rust-lang.org/std/os/unix/net/struct.UnixDatagram.html#method.send_vectored_with_ancillary |
| 187 | // but this is (at the time of writing) unstable. |
| 188 | |
| 189 | #[repr(C)] |
| 190 | union SingleRightAnciliaryDatarust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SingleRightAnciliaryData# { |
| 191 | // SAFETY: Not actually unsafe |
| 192 | bufrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SingleRightAnciliaryData#buf.: [u8; unsafe { CMSG_SPACErust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_SPACE().(size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#>() as u32) as usize }], |
| 193 | _alignrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SingleRightAnciliaryData#_align.: cmsghdrrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/cmsghdr#, |
| 194 | } |
| 195 | |
| 196 | /// Receives a raw file descriptor from the provided UnixStream |
| 197 | fn receive_fdrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/receive_fd().(rx_fd: UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#) -> OwnedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/OwnedFd# { |
| 198 | let mut data = [0u8; 1]; |
| 199 | let mut iov = iovecrust-analyzer cargo libc 0.2.186 unix/iovec# { |
| 200 | iov_baserust-analyzer cargo libc 0.2.186 unix/iovec#iov_base.: &mut data as *mut [u8; 1] as *mut c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#, |
| 201 | iov_lenrust-analyzer cargo libc 0.2.186 unix/iovec#iov_len.: 1, |
| 202 | }; |
| 203 | |
| 204 | // SAFETY: msghdr can be zero-initialized |
| 205 | let mut msg: msghdrrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr# = unsafe { zeroedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/zeroed().() }; |
| 206 | msg.msg_namerust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_name. = ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().(); |
| 207 | msg.msg_namelenrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_namelen. = 0; |
| 208 | msg.msg_iovrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_iov. = &mut iov; |
| 209 | msg.msg_iovlenrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_iovlen. = 1; |
| 210 | |
| 211 | // SAFETY: SingleRightAnciliaryData can be zero-initialized. |
| 212 | let mut control: SingleRightAnciliaryDatarust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SingleRightAnciliaryData# = unsafe { zeroedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/zeroed().() }; |
| 213 | // SAFETY: The buf field is valid when zero-initialized. |
| 214 | msg.msg_controllenrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_controllen. = unsafe { control.bufrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SingleRightAnciliaryData#buf..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as _ }; |
| 215 | msg.msg_controlrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_control. = &mut control as *mut _ as *mut c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#; |
| 216 | |
| 217 | // SAFETY: A valid socket fd and a valid initialized msghdr are passed in. |
| 218 | if unsafe { recvmsgrust-analyzer cargo libc 0.2.186 recvmsg().(rx_fd.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream][AsRawFd]as_raw_fd().(), &mut msg, 0) } rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1 { |
| 219 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("failed to recvmsg: {}", iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().()); |
| 220 | } |
| 221 | |
| 222 | if msg.msg_flagsrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_flags. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().MSG_TRUNCrust-analyzer cargo libc 0.2.186 unix/linux_like/MSG_TRUNC. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().MSG_TRUNCrust-analyzer cargo libc 0.2.186 unix/linux_like/MSG_TRUNC. { |
| 223 | unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("unexpected internal error in seccomp filter"); |
| 224 | } |
| 225 | |
| 226 | // SAFETY: The kernel correctly initializes everything on recvmsg for this to be safe. |
| 227 | unsafe { |
| 228 | let cmsgp = CMSG_FIRSTHDRrust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_FIRSTHDR().(&msg); |
| 229 | if cmsgp.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() |
| 230 | || (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().cmsgp).cmsg_lenrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/cmsghdr#cmsg_len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().CMSG_LENrust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_LEN().(size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#>() as u32) as _ |
| 231 | || (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().cmsgp).cmsg_levelrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/cmsghdr#cmsg_level. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().SOL_SOCKETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/SOL_SOCKET. |
| 232 | || (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().cmsgp).cmsg_typerust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/cmsghdr#cmsg_type. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().SCM_RIGHTSrust-analyzer cargo libc 0.2.186 unix/linux_like/SCM_RIGHTS. |
| 233 | { |
| 234 | unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("unexpected response from Linux kernel"); |
| 235 | } |
| 236 | OwnedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/OwnedFd#::from_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][FromRawFd]from_raw_fd().(CMSG_DATArust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_DATA().(cmsgp).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#>().readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]read().()) |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | fn send_fdrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/send_fd().(tx_fd: UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#, notify_fd: OwnedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/OwnedFd#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 241 | let mut data = [0u8; 1]; |
| 242 | let mut iov = iovecrust-analyzer cargo libc 0.2.186 unix/iovec# { |
| 243 | iov_baserust-analyzer cargo libc 0.2.186 unix/iovec#iov_base.: &mut data as *mut [u8; 1] as *mut c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#, |
| 244 | iov_lenrust-analyzer cargo libc 0.2.186 unix/iovec#iov_len.: 1, |
| 245 | }; |
| 246 | |
| 247 | // SAFETY: msghdr can be zero-initialized |
| 248 | let mut msg: msghdrrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr# = unsafe { zeroedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/zeroed().() }; |
| 249 | msg.msg_namerust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_name. = ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().(); |
| 250 | msg.msg_namelenrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_namelen. = 0; |
| 251 | msg.msg_iovrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_iov. = &mut iov; |
| 252 | msg.msg_iovlenrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_iovlen. = 1; |
| 253 | |
| 254 | // SAFETY: SingleRightAnciliaryData can be zero-initialized. |
| 255 | let mut control: SingleRightAnciliaryDatarust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SingleRightAnciliaryData# = unsafe { zeroedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/zeroed().() }; |
| 256 | // SAFETY: The buf field is valid when zero-initialized. |
| 257 | msg.msg_controllenrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_controllen. = unsafe { control.bufrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SingleRightAnciliaryData#buf..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as _ }; |
| 258 | msg.msg_controlrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/msghdr#msg_control. = &mut control as *mut _ as *mut _; |
| 259 | // SAFETY: msg.msg_control is correctly initialized and this follows |
| 260 | // the contract of the various CMSG_* macros. |
| 261 | unsafe { |
| 262 | let cmsgp = CMSG_FIRSTHDRrust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_FIRSTHDR().(&msg); |
| 263 | (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().cmsgp).cmsg_levelrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/cmsghdr#cmsg_level. = SOL_SOCKETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/SOL_SOCKET.; |
| 264 | (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().cmsgp).cmsg_typerust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/cmsghdr#cmsg_type. = SCM_RIGHTSrust-analyzer cargo libc 0.2.186 unix/linux_like/SCM_RIGHTS.; |
| 265 | (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().cmsgp).cmsg_lenrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/cmsghdr#cmsg_len. = CMSG_LENrust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_LEN().(size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#>() as u32) as _; |
| 266 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(CMSG_DATArust-analyzer cargo libc 0.2.186 unix/linux_like/CMSG_DATA().(cmsgp).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#>(), notify_fd.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][AsRawFd]as_raw_fd().()); |
| 267 | } |
| 268 | |
| 269 | // SAFETY: A valid socket fd and a valid initialized msghdr are passed in. |
| 270 | if unsafe { sendmsgrust-analyzer cargo libc 0.2.186 sendmsg().(tx_fd.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream][AsRawFd]as_raw_fd().(), &msg, 0) } rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1 { |
| 271 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().()) |
| 272 | } else { |
| 273 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) struct SpawnNoexecHandlerrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SpawnNoexecHandler#(UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#); |
| 278 | |
| 279 | impl SpawnNoexecHandlerrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SpawnNoexecHandler# { |
| 280 | pub(superrust-analyzer cargo sudo-rs 0.2.14 exec/) fn spawnrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/impl#[SpawnNoexecHandler]spawn().(self) { |
| 281 | threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/spawn().(move || { |
| 282 | let notify_fd = receive_fdrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/receive_fd().(self.0rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SpawnNoexecHandler#0.); |
| 283 | // SAFETY: notify_fd is a valid seccomp_unotify fd. |
| 284 | unsafe { handle_notificationsrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/handle_notifications().(notify_fd) }; |
| 285 | }); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | // BPF filtering is only supported (according to man seccomp) on the following architectures |
| 290 | // that are realistic on Linux. |
| 291 | const HOST_ARCHrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/HOST_ARCH.: u32 = if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "aarch64") { |
| 292 | AUDIT_ARCH_AARCH64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_AARCH64. |
| 293 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "arm") { |
| 294 | AUDIT_ARCH_ARMrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_ARM. |
| 295 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "mips") { |
| 296 | if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_endian = "little") { |
| 297 | AUDIT_ARCH_MIPSELrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_MIPSEL. |
| 298 | } else { |
| 299 | AUDIT_ARCH_MIPSrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_MIPS. |
| 300 | } |
| 301 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "mips64") { |
| 302 | if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_endian = "little") { |
| 303 | AUDIT_ARCH_MIPSEL64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_MIPSEL64. |
| 304 | } else { |
| 305 | AUDIT_ARCH_MIPS64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_MIPS64. |
| 306 | } |
| 307 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "powerpc") { |
| 308 | AUDIT_ARCH_PPCrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_PPC. |
| 309 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "powerpc64") { |
| 310 | if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_endian = "little") { |
| 311 | AUDIT_ARCH_PPC64LErust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_PPC64LE. |
| 312 | } else { |
| 313 | AUDIT_ARCH_PPC64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_PPC64. |
| 314 | } |
| 315 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "riscv32") { |
| 316 | AUDIT_ARCH_RISCV32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_RISCV32. |
| 317 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "riscv64") { |
| 318 | AUDIT_ARCH_RISCV64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_RISCV64. |
| 319 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "s390x") { |
| 320 | AUDIT_ARCH_S390Xrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_S390X. |
| 321 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "x86") { |
| 322 | AUDIT_ARCH_I386rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_I386. |
| 323 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "x86_64") { |
| 324 | AUDIT_ARCH_X86_64rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_X86_64. |
| 325 | } else { |
| 326 | 0 // this will filter out all syscalls |
| 327 | }; |
| 328 | |
| 329 | // For x86-64 and aarch64 systems, it's possible to encounter them |
| 330 | // running in multi-arch mode. |
| 331 | const GUEST_ARCHrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/GUEST_ARCH.: u32 = if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "aarch64") { |
| 332 | AUDIT_ARCH_ARMrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_ARM. |
| 333 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "riscv64") { |
| 334 | AUDIT_ARCH_RISCV32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_RISCV32. |
| 335 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "x86_64") { |
| 336 | AUDIT_ARCH_I386rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/AUDIT_ARCH_I386. |
| 337 | } else { |
| 338 | HOST_ARCHrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/HOST_ARCH. |
| 339 | }; |
| 340 | |
| 341 | /// syscall numbers for the guest architecture according to the Linux syscall table |
| 342 | const SYS_execve_x86rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execve_x86.: i64 = 11; |
| 343 | const SYS_execve_armrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execve_arm.: i64 = 11; |
| 344 | const SYS_execve_x32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execve_x32.: i64 = 520; |
| 345 | const SYS_execve_rv32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execve_rv32.: i64 = 221; |
| 346 | const SYS_execveat_x86rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execveat_x86.: i64 = 358; |
| 347 | const SYS_execveat_armrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execveat_arm.: i64 = 387; |
| 348 | const SYS_execveat_x32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execveat_x32.: i64 = 545; |
| 349 | const SYS_execveat_rv32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execveat_rv32.: i64 = 281; |
| 350 | |
| 351 | const GUEST_SYSCALLrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/GUEST_SYSCALL.: (i64, i64) = if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "aarch64") { |
| 352 | (SYS_execve_armrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execve_arm., SYS_execveat_armrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execveat_arm.) |
| 353 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "riscv64") { |
| 354 | (SYS_execve_rv32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execve_rv32., SYS_execveat_rv32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execveat_rv32.) |
| 355 | } else if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_arch = "x86_64") { |
| 356 | (SYS_execve_x86rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execve_x86., SYS_execveat_x86rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execveat_x86.) |
| 357 | } else { |
| 358 | (SYS_execverust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/not_x32/SYS_execve. as _, SYS_execveatrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/not_x32/SYS_execveat. as _) // fallback |
| 359 | }; |
| 360 | |
| 361 | // Bit that is set on syscalls when using the X32 ABI; see man seccomp. |
| 362 | const __X32_SYSCALL_BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__X32_SYSCALL_BIT.: u32 = 0x40000000; |
| 363 | |
| 364 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn add_noexec_filterrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/add_noexec_filter().(command: &mut Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<SpawnNoexecHandlerrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SpawnNoexecHandler#> { |
| 365 | let (tx_fd, rx_fd) = UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#::pairrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream]pair().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 366 | |
| 367 | // wrap tx_fd so it can be moved into the closure |
| 368 | let mut tx_fd = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tx_fd); |
| 369 | |
| 370 | // SAFETY: See individual SAFETY comments |
| 371 | unsafe { |
| 372 | // SAFETY: The closure only calls async-signal-safe functions. |
| 373 | command.pre_execrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/process/impl#[`process::Command`][CommandExt]pre_exec().(move || { |
| 374 | let tx_fd = tx_fd.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 375 | |
| 376 | let nr_offset = offset_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/offset_of!!(seccomp_datarust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_data#, nrrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_data#nr.); |
| 377 | let arch_offset = offset_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/offset_of!!(seccomp_datarust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_data#, archrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/seccomp_data#arch.); |
| 378 | |
| 379 | // SAFETY: libc unnecessarily marks these functions as unsafe |
| 380 | #[rustfmt::skip] |
| 381 | let exec_filter = [ |
| 382 | // Load architecture number into the accumulator |
| 383 | BPF_STMTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_STMT().((BPF_LDrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_LD. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_ABSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_ABS.) as _, arch_offset as _), |
| 384 | // Check if we are any of the recognized architectures |
| 385 | BPF_JUMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JUMP().((BPF_JMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JMP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_JEQrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JEQ. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, HOST_ARCHrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/HOST_ARCH. as _, 7, 0), |
| 386 | BPF_JUMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JUMP().((BPF_JMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JMP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_JEQrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JEQ. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, GUEST_ARCHrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/GUEST_ARCH. as _, 1, 0), |
| 387 | // Not a recognized architecture, forbid all syscalls |
| 388 | BPF_STMTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_STMT().((BPF_RETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_RET. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, SECCOMP_RET_KILL_PROCESSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_RET_KILL_PROCESS. as _), |
| 389 | |
| 390 | // Guest architecture section |
| 391 | // Load syscall number into the accumulator |
| 392 | BPF_STMTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_STMT().((BPF_LDrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_LD. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Wrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_W. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_ABSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_ABS.) as _, nr_offset as _), |
| 393 | // Jump to user notify for execve/execveat |
| 394 | BPF_JUMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JUMP().((BPF_JMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JMP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_JEQrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JEQ. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, GUEST_SYSCALLrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/GUEST_SYSCALL..0 as _, 2, 0), |
| 395 | BPF_JUMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JUMP().((BPF_JMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JMP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_JEQrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JEQ. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, GUEST_SYSCALLrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/GUEST_SYSCALL..1 as _, 1, 0), |
| 396 | // Allow non-matching syscalls |
| 397 | BPF_STMTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_STMT().((BPF_RETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_RET. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, SECCOMP_RET_ALLOWrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_RET_ALLOW.), |
| 398 | // Notify sudo about execve/execveat syscall |
| 399 | BPF_STMTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_STMT().((BPF_RETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_RET. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, SECCOMP_RET_USER_NOTIFrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SECCOMP_RET_USER_NOTIF. as _), |
| 400 | |
| 401 | // Host architecture section |
| 402 | // Load syscall number into the accumulator |
| 403 | BPF_STMTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_STMT().((BPF_LDrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_LD. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Wrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_W. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_ABSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_ABS.) as _, nr_offset as _), |
| 404 | // Unset the X32_SYSCALL bit (only necessary on x86_64) |
| 405 | #[cfg(target_arch = "x86_64")] |
| 406 | BPF_STMTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_STMT().((BPF_ALUrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_ALU. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_ANDrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_AND. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][Not]not().__X32_SYSCALL_BITrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/__X32_SYSCALL_BIT.), |
| 407 | // On x86-64 only: check the x32 "design error" syscall numbers |
| 408 | #[cfg(target_arch = "x86_64")] |
| 409 | BPF_JUMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JUMP().((BPF_JMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JMP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_JEQrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JEQ. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, SYS_execve_x32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execve_x32. as _, 4, 0), |
| 410 | #[cfg(target_arch = "x86_64")] |
| 411 | BPF_JUMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JUMP().((BPF_JMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JMP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_JEQrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JEQ. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, SYS_execveat_x32rust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SYS_execveat_x32. as _, 3, 0), |
| 412 | // Jump to user notify for execve/execveat |
| 413 | BPF_JUMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JUMP().((BPF_JMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JMP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_JEQrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JEQ. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, SYS_execverust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/not_x32/SYS_execve. as _, 2, 0), |
| 414 | BPF_JUMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JUMP().((BPF_JMPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JMP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_JEQrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_JEQ. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, SYS_execveatrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/not_x32/SYS_execveat. as _, 1, 0), |
| 415 | // Allow non-matching syscalls |
| 416 | BPF_STMTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_STMT().((BPF_RETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_RET. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, SECCOMP_RET_ALLOWrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_RET_ALLOW.), |
| 417 | // Notify sudo about execve/execveat syscall |
| 418 | BPF_STMTrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_STMT().((BPF_RETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_RET. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().BPF_Krust-analyzer cargo libc 0.2.186 unix/linux_like/linux/BPF_K.) as _, SECCOMP_RET_USER_NOTIFrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SECCOMP_RET_USER_NOTIF. as _), |
| 419 | ]; |
| 420 | |
| 421 | // this is used since we can't yet use "let exec_filter: [sock_filter; _] above" |
| 422 | const fn check_typerust-analyzer cargo sudo-rs 0.2.14 exec/noexec/check_type().<const N: usize>(_arr: &[sock_filterrust-analyzer cargo libc 0.2.186 unix/linux_like/sock_filter#; N]) {} |
| 423 | check_typerust-analyzer cargo sudo-rs 0.2.14 exec/noexec/check_type().(&exec_filter); |
| 424 | |
| 425 | let exec_fprog = sock_fprogrust-analyzer cargo libc 0.2.186 unix/linux_like/sock_fprog# { |
| 426 | lenrust-analyzer cargo libc 0.2.186 unix/linux_like/sock_fprog#len.: exec_filter.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u16, |
| 427 | filterrust-analyzer cargo libc 0.2.186 unix/linux_like/sock_fprog#filter.: addr_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/addr_of!!(exec_filter) as *mut sock_filterrust-analyzer cargo libc 0.2.186 unix/linux_like/sock_filter#, |
| 428 | }; |
| 429 | |
| 430 | // SAFETY: Trivially safe as it doesn't touch any memory. |
| 431 | // SECCOMP_SET_MODE_FILTER will fail unless the process has |
| 432 | // CAP_SYS_ADMIN or the no_new_privs bit is set. |
| 433 | if prctlrust-analyzer cargo libc 0.2.186 prctl().(PR_SET_NO_NEW_PRIVSrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/PR_SET_NO_NEW_PRIVS., 1, 0, 0, 0) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1 { |
| 434 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().()); |
| 435 | } |
| 436 | |
| 437 | // While the man page warns against using seccomp_unotify as security |
| 438 | // mechanism, the TOCTOU problem that is described there isn't |
| 439 | // relevant here. We only SECCOMP_USER_NOTIF_FLAG_CONTINUE the first |
| 440 | // execve which is done by ourself and thus trusted. |
| 441 | // SAFETY: Passes a valid sock_fprog as argument. |
| 442 | let notify_fd = seccomprust-analyzer cargo sudo-rs 0.2.14 exec/noexec/seccomp().( |
| 443 | SECCOMP_SET_MODE_FILTERrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_SET_MODE_FILTER., |
| 444 | SECCOMP_FILTER_FLAG_NEW_LISTENERrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/SECCOMP_FILTER_FLAG_NEW_LISTENER. as _, |
| 445 | addr_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/addr_of!!(exec_fprog).cast_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast_mut().(), |
| 446 | ); |
| 447 | if notify_fd rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0 { |
| 448 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().()); |
| 449 | } |
| 450 | |
| 451 | send_fdrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/send_fd().(tx_fd, OwnedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/OwnedFd#::from_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][FromRawFd]from_raw_fd().(notify_fd))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 452 | |
| 453 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 454 | }); |
| 455 | } |
| 456 | |
| 457 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(SpawnNoexecHandlerrust-analyzer cargo sudo-rs 0.2.14 exec/noexec/SpawnNoexecHandler#(rx_fd)) |
| 458 | } |