From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: Joe Simmons-Talbott <josimmon@redhat.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH v4 2/2] aarch64: Set the syscall register right before doing the syscall.
Date: Tue, 18 Apr 2023 13:57:28 +0100 [thread overview]
Message-ID: <ZD6TuBVByhiUFAWG@arm.com> (raw)
In-Reply-To: <20230417212034.3890596-3-josimmon@redhat.com>
The 04/17/2023 17:20, Joe Simmons-Talbott via Libc-alpha wrote:
> To make identifying syscalls easier during call tree analysis load the
> syscall number just before performing the syscall.
>
> Compiler optimizations can place quite a few instructions between the
> setting of the syscall number and the syscall instruction. During call
> tree analysis the number of instructions between the two can lead to
> more difficulty for both tools and humans in properly identifying the
> syscall number. Having the syscall number set in the prior instruction
> to the syscall instruction makes this task easier and less error prone.
> Being able to reliably identify syscalls made by a given API will make
> it easier to understand and verify the safety and security of glibc.
since the code has !__builtin_constant_p(name) case
how would that be handled by these tools?
> ---
> sysdeps/unix/sysv/linux/aarch64/sysdep.h | 20 +++++++++++++++++---
> 1 file changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
> index e94d1703ad..b91656fdff 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
> @@ -167,14 +167,28 @@
>
> # define HAVE_CLONE3_WRAPPER 1
>
> +# define MSTR_HELPER(x) # x
> +# define MSTR(x) MSTR_HELPER(x)
> +
i dont see this used.
> # undef INTERNAL_SYSCALL_RAW
> # define INTERNAL_SYSCALL_RAW(name, nr, args...) \
> ({ long _sys_result; \
> { \
> LOAD_ARGS_##nr (args) \
> - register long _x8 asm ("x8") = (name); \
> - asm volatile ("svc 0 // syscall " # name \
> - : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr : "memory"); \
> + if (__builtin_constant_p(name)) \
> + asm volatile ("mov x8, %1\n" \
> + "svc 0 // syscall " # name \
> + : "=r" (_x0) \
> + : "i" (name) ASM_ARGS_##nr \
> + : "x8", "memory"); \
> + else \
> + { \
> + register long _x8 asm ("x8") = (name); \
> + asm volatile ("svc 0 // syscall " # name \
> + : "=r" (_x0) \
> + : "r"(_x8) ASM_ARGS_##nr \
> + : "memory"); \
> + } \
> _sys_result = _x0; \
> } \
> _sys_result; })
i guess this is ok.
i would probably move the generated comment to the
mov x8,%1 line and remove it in the non-const case.
but i rarely look at compiler output..
it seems the only cases when the name is non-const are
nptl/nptl_setxid.c: result = INTERNAL_SYSCALL_NCS (xidcmd->syscall_no, 3, xidcmd->id[0],
nptl/nptl_setxid.c: result = INTERNAL_SYSCALL_NCS (cmdp->syscall_no, 3,
which in turn only happens for syscalls
sysdeps/unix/sysv/linux/setuid.c: return INLINE_SETXID_SYSCALL (setuid32, 1, uid);
sysdeps/unix/sysv/linux/setuid.c: return INLINE_SETXID_SYSCALL (setuid, 1, uid);
sysdeps/unix/sysv/linux/setreuid.c: return INLINE_SETXID_SYSCALL (setreuid32, 2, ruid, euid);
sysdeps/unix/sysv/linux/setreuid.c: return INLINE_SETXID_SYSCALL (setreuid, 2, ruid, euid);
sysdeps/unix/sysv/linux/setegid.c: result = INLINE_SETXID_SYSCALL (setresgid32, 3, -1, gid, -1);
sysdeps/unix/sysv/linux/setegid.c: result = INLINE_SETXID_SYSCALL (setresgid, 3, -1, gid, -1);
sysdeps/unix/sysv/linux/setregid.c: return INLINE_SETXID_SYSCALL (setregid32, 2, rgid, egid);
sysdeps/unix/sysv/linux/setregid.c: return INLINE_SETXID_SYSCALL (setregid, 2, rgid, egid);
sysdeps/unix/sysv/linux/setgid.c: return INLINE_SETXID_SYSCALL (setgid32, 1, gid);
sysdeps/unix/sysv/linux/setgid.c: return INLINE_SETXID_SYSCALL (setgid, 1, gid);
sysdeps/unix/sysv/linux/setgroups.c: return INLINE_SETXID_SYSCALL (setgroups32, 2, n, groups);
sysdeps/unix/sysv/linux/setgroups.c: return INLINE_SETXID_SYSCALL (setgroups, 2, n, groups);
sysdeps/unix/sysv/linux/setresgid.c: return INLINE_SETXID_SYSCALL (setresgid32, 3, rgid, egid, sgid);
sysdeps/unix/sysv/linux/setresgid.c: return INLINE_SETXID_SYSCALL (setresgid, 3, rgid, egid, sgid);
sysdeps/unix/sysv/linux/setresuid.c: return INLINE_SETXID_SYSCALL (setresuid32, 3, ruid, euid, suid);
sysdeps/unix/sysv/linux/setresuid.c: return INLINE_SETXID_SYSCALL (setresuid, 3, ruid, euid, suid);
sysdeps/unix/sysv/linux/seteuid.c: result = INLINE_SETXID_SYSCALL (setresuid32, 3, -1, uid, -1);
sysdeps/unix/sysv/linux/seteuid.c: result = INLINE_SETXID_SYSCALL (setresuid, 3, -1, uid, -1);
so if we wanted we could have a switch statement in setxid
and make all syscalls compile time const (other than
explicit external calls to syscall())
next prev parent reply other threads:[~2023-04-18 12:57 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-11 13:30 [PATCH 0/2] x86_64: aarch64: Set call number just before syscall Joe Simmons-Talbott
2023-04-11 13:30 ` [PATCH 1/2] x86_64: Set the syscall register right before doing the syscall Joe Simmons-Talbott
2023-04-17 22:35 ` Noah Goldstein
2023-04-17 22:36 ` Noah Goldstein
2023-04-11 13:30 ` [PATCH 2/2] aarch64: " Joe Simmons-Talbott
2023-04-11 13:50 ` Florian Weimer
2023-04-11 14:15 ` Adhemerval Zanella Netto
2023-04-11 15:43 ` Szabolcs Nagy
2023-04-11 16:03 ` Florian Weimer
2023-04-11 16:39 ` Adhemerval Zanella Netto
2023-04-12 15:27 ` Joe Simmons-Talbott
2023-04-12 21:11 ` [PATCH v2 0/2] x86_64: aarch64: Set call number just before syscall Joe Simmons-Talbott
2023-04-12 21:11 ` [PATCH v2 1/2] x86_64: Set the syscall register right before doing the syscall Joe Simmons-Talbott
2023-04-12 21:11 ` [PATCH v2 2/2] aarch64: " Joe Simmons-Talbott
2023-04-17 15:34 ` [PATCH v3 0/2] x86_64: aarch64: Set call number just before syscall Joe Simmons-Talbott
2023-04-17 15:34 ` [PATCH v3 1/2] x86_64: Set the syscall register right before doing the syscall Joe Simmons-Talbott
2023-04-17 15:54 ` H.J. Lu
2023-04-17 16:00 ` Joe Simmons-Talbott
2023-04-17 18:38 ` H.J. Lu
2023-04-17 15:34 ` [PATCH v3 2/2] aarch64: " Joe Simmons-Talbott
2023-04-17 21:20 ` [PATCH v4 0/2] x86_64: aarch64: Set call number just before syscall Joe Simmons-Talbott
2023-04-17 21:20 ` [PATCH v4 1/2] x86_64: Set the syscall register right before doing the syscall Joe Simmons-Talbott
2023-04-17 21:20 ` [PATCH v4 2/2] aarch64: " Joe Simmons-Talbott
2023-04-18 12:57 ` Szabolcs Nagy [this message]
2023-04-18 19:33 ` Joe Simmons-Talbott
2023-04-19 13:58 ` [PATCH v5 0/3] x86_64: aarch64: Set call number just before syscall Joe Simmons-Talbott
2023-04-19 13:58 ` [PATCH v5 1/3] x86_64: Set the syscall register right before doing the syscall Joe Simmons-Talbott
2023-04-19 15:35 ` H.J. Lu
2023-04-19 15:48 ` Joe Simmons-Talbott
2023-04-19 13:58 ` [PATCH v5 2/3] aarch64: " Joe Simmons-Talbott
2023-04-19 14:56 ` Szabolcs Nagy
2023-04-19 15:21 ` Joe Simmons-Talbott
2023-04-19 13:58 ` [PATCH v5 3/3] nptl: Use direct syscall numbers in setxid Joe Simmons-Talbott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZD6TuBVByhiUFAWG@arm.com \
--to=szabolcs.nagy@arm.com \
--cc=josimmon@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).