* discovering native audit arch
@ 2022-02-14 21:40 Kees Cook
0 siblings, 0 replies; only message in thread
From: Kees Cook @ 2022-02-14 21:40 UTC (permalink / raw)
To: linux-api
Hi,
Is there a better way than this to find the native architecture value
needed for seccomp filters? Right now everyone basically hard-codes it
with other compile-time checks...
static unsigned int get_syscall_arch(void)
{
struct ptrace_syscall_info info = { };
siginfo_t siginfo = { };
unsigned int arch = -1;
pid_t pid = fork();
if (pid < 0)
return -1;
if (pid == 0) {
if (ptrace(PTRACE_TRACEME, 0, 0, 0) != 0) {
perror("PTRACE_TRACEME");
_exit(1);
}
if (raise(SIGSTOP) != 0) {
perror("raise");
_exit(1);
}
_exit(0);
}
if (ptrace(PTRACE_ATTACH, pid, 0, 0) != 0)
goto reap;
if (waitid(P_PID, pid, &siginfo, WEXITED | WSTOPPED | WCONTINUED) != 0)
goto reap;
if (siginfo.si_code != CLD_STOPPED &&
siginfo.si_code != CLD_TRAPPED)
goto reap;
if (ptrace(PTRACE_GET_SYSCALL_INFO, pid, sizeof(info), &info)
< offsetof(typeof(info), arch) + sizeof(info.arch))
goto reap;
arch = info.arch;
ptrace(PTRACE_DETACH, pid, 0, 0);
reap:
kill(pid, SIGKILL);
if (waitpid(pid, NULL, 0) != pid)
perror("waitpid");
return arch;
}
--
Kees Cook
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-02-14 21:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-14 21:40 discovering native audit arch Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).