Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251126223140.GL3520958@port70.net>
Date: Wed, 26 Nov 2025 23:31:40 +0100
From: Szabolcs Nagy <nsz@...t70.net>
To: Arjun Ramesh <arjunr2@...rew.cmu.edu>
Cc: Rich Felker <dalias@...c.org>, musl@...ts.openwall.com
Subject: Re: [Patch Request] Name-bound syscalls within musl

* Arjun Ramesh <arjunr2@...rew.cmu.edu> [2025-11-25 22:17:12 -0500]:
> On Tue, Nov 25, 2025 at 8:44 PM Rich Felker <dalias@...c.org> wrote:
> This makes sense, and macro magic within syscall_arch.h can certainly work.
> Looking through the codebase, luckily most call-sites use exclusively SYS_*
> macros, allowing this sort of magic to work. However, there are still a
> couple of spots that might need some patching where a variable is used for
> syscall numbers. These will likely have to expand out to a different macro
> expansion -- one which has a giant switch case over all possible syscalls
> to name-bind them. At the moment, I identify very few places where this
> happens, which is a good thing (seems like both are just for generic
> syscall-by-number invocations):
> * src/misc/syscall.c
> * src/thread/__syscall_cp.c

and
src/thread/pthread_cancel.c
src/unistd/setxid.c

> 
> Given this, would you then be open to minimal patches that would route
> these "variable" numbered to a different macro? Perhaps something of the
> nature of this in those spots:
> ```
> diff --git a/src/misc/syscall.c b/src/misc/syscall.c
> index 6f3ef656..72356346 100644
> --- a/src/misc/syscall.c
> +++ b/src/misc/syscall.c
> @@ -17,5 +17,5 @@ long syscall(long n, ...)
>         e=va_arg(ap, syscall_arg_t);
>         f=va_arg(ap, syscall_arg_t);
>         va_end(ap);
> -       return __syscall_ret(__syscall(n,a,b,c,d,e,f));
> +       return __syscall_ret(__syscall_var(n,a,b,c,d,e,f));
>  }
> ```
> 
> The `__syscall_var` can be defaulted to `__syscall` on all existing
> platforms, but will provide the flexibility for allowing a hook for
> name-binding these calls.

note that with

#define __syscall1(n,a) __my_##n(a)
#define __syscall_cp1(n,a) __my_cp_##n(a)
...

the call above would expand to

__my_n(a,b,c,d,e,f)

which your target can override. the only issue
is setxid:

int ret = __syscall(c->nr, c->id, c->eid, c->sid);

you can work this around e.g. by 'int n = c->nr;'
but for better typesafety you can just do the
switch(c->nr) dispatch there.

likely you need to add ifdefs in the internal
syscall.h to be able to override __syscall*
macros, so maintaining a minimal setxid patch
should be acceptable as well.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.