Skip to content

Commit

Permalink
c18n: Remove libsys's reference to a libc function
Browse files Browse the repository at this point in the history
Previously, lib/c18n/libsys's sigaction calls a libc function which in
turn calls the RTLD hook. This is broken but was undetected because c18n
was accidentally always disabled in the c18n-version of libsys.
  • Loading branch information
dpgao committed Sep 9, 2024
1 parent 0535b4c commit de814f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/libc/include/libc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ int __strerror_rl(int errnum, char *strerrbuf, size_t buflen,

#ifdef CHERI_LIB_C18N
__pid_t __sys_rfork(int);
int sigaction_c18n(int, const struct sigaction *, struct sigaction *);
int _rtld_sigaction(int, const struct sigaction *, struct sigaction *);
#endif

#endif /* _LIBC_PRIVATE_H_ */
13 changes: 0 additions & 13 deletions lib/libc/sys/sigaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@

__weak_reference(__sys_sigaction, __sigaction);
__weak_reference(sigaction, __libc_sigaction);
#ifdef CHERI_LIB_C18N
/*
* This weak symbol will always be resolved at runtime.
*/
#pragma weak _rtld_sigaction
int _rtld_sigaction(int, const struct sigaction *, struct sigaction *);

int
sigaction_c18n(int sig, const struct sigaction *act, struct sigaction *oact)
{
return (_rtld_sigaction(sig, act, oact));
}
#endif

#pragma weak sigaction
int
Expand Down
15 changes: 14 additions & 1 deletion lib/libsys/interposing_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@
#include <sys/types.h>
#include "libc_private.h"

#ifdef CHERI_LIB_C18N
/*
* XXX: A wrapper is needed to redirect the call because directly referencing
* _rtld_sigaction as a function pointer causes it to not be wrapped in a
* trampoline at the moment.
*/
int
_rtld_sigaction_wrapper(int sig, const struct sigaction *oact,
struct sigaction *act) {
return (_rtld_sigaction(sig, oact, act));
}
#endif

#define SLOT(a, b) \
[INTERPOS_##a] = (interpos_func_t)b
static interpos_func_t __libsys_interposing[INTERPOS_MAX] = {
Expand All @@ -57,7 +70,7 @@ static interpos_func_t __libsys_interposing[INTERPOS_MAX] = {
SLOT(sendto, __sys_sendto),
SLOT(setcontext, __sys_setcontext),
#ifdef CHERI_LIB_C18N
SLOT(sigaction, sigaction_c18n),
SLOT(sigaction, _rtld_sigaction_wrapper),
#else
SLOT(sigaction, __sys_sigaction),
#endif
Expand Down

0 comments on commit de814f8

Please sign in to comment.