From ce379ec74e0348325b3a3149fa6207f398ea8da7 Mon Sep 17 00:00:00 2001 From: afify Date: Sat, 28 Nov 2020 18:44:57 +0300 Subject: [PATCH] [feat] OpenBSD pledge --- README.md | 1 + azan.s | 5 +++++ macros.s | 11 +++++++++++ syscalls.s | 1 + 4 files changed, 18 insertions(+) diff --git a/README.md b/README.md index a3b4d4f..d069f9c 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ azan - standalone nasm - unix portable syscalls - tested on Linux, OpenBSD, FreeBSD and NetBSD +- OpenBSD pledge. - binary size ≈ 7 kb - instructions ≈ 250-400 - branches ≈ 6-20 diff --git a/azan.s b/azan.s index 9751654..a6b1c15 100644 --- a/azan.s +++ b/azan.s @@ -39,6 +39,8 @@ section .rodata usage_len: equ $ - usage_msg version_msg: db "azan-", VERSION, 10, 0 version_len: equ $ - version_msg + pledge_msg: db "pledge", 10, 0 + promises: db "stdio", 0 section .data res_msg: db "X XX:XX", 10, 0 @@ -84,6 +86,7 @@ check_argv: DIE version_msg, version_len get_timestamp: + OPENBSD_PLEDGE mov rax, SYS_gettimeofday ;sys_gettimeofday( mov rdi, tmp0 ;struct timeval *tv, mov rsi, rsi ;struct timezone* tz @@ -456,6 +459,8 @@ print_all_12: PRINT_HM EEXIT EXIT_SUCCESS +die_pledge: + DIE pledge_msg, 8 ; result_hour ;r8 ; result_min ;r9 ; duhr_ts: ;xmm0 diff --git a/macros.s b/macros.s index eb381c4..814367c 100644 --- a/macros.s +++ b/macros.s @@ -25,6 +25,17 @@ section .note.openbsd.ident note %endif %endmacro +%macro OPENBSD_PLEDGE 0 +%ifdef OpenBSD + mov rax, SYS_pledge ;pledge( + mov rdi, promises ;const char *promises + xor rsi, rsi ;const char *execpromises + syscall + cmp rax, 0 + jl die_pledge +%endif +%endmacro + %macro EEXIT 1 mov rax, SYS_exit mov rdi, %1 diff --git a/syscalls.s b/syscalls.s index 102074b..0502a0a 100644 --- a/syscalls.s +++ b/syscalls.s @@ -11,6 +11,7 @@ %define SYS_exit 1 %define SYS_write 4 %define SYS_gettimeofday 67 + %define SYS_pledge 108 %elifdef FreeBSD %define SYS_exit 1 %define SYS_write 4