|
Lines 15-29
Link Here
|
| 15 |
*/ |
15 |
*/ |
| 16 |
|
16 |
|
| 17 |
/* |
17 |
/* |
| 18 |
* Uncomment the SANDBOX_SECCOMP_FILTER_DEBUG macro below to help diagnose |
18 |
* Uncomment the SANDBOX_SECCOMP_FILTER_DEBUG macro below and run sshd with |
| 19 |
* filter breakage during development. *Do not* use this in production, |
19 |
* stderr attached (sshd -De ... or sshd -d ...) to receive notifications of |
| 20 |
* as it relies on making library calls that are unsafe in signal context. |
20 |
* sandbox violations to stderr. E.g. |
| 21 |
* |
21 |
* |
| 22 |
* Instead, live systems the auditctl(8) may be used to monitor failures. |
22 |
* Alternately, live systems the auditctl(8) may be used to monitor |
| 23 |
* E.g. |
23 |
* failures. E.g. |
| 24 |
* auditctl -a task,always -F uid=<privsep uid> |
24 |
* auditctl -a task,always -F uid=<privsep uid> |
| 25 |
*/ |
25 |
*/ |
| 26 |
/* #define SANDBOX_SECCOMP_FILTER_DEBUG 1 */ |
26 |
#define SANDBOX_SECCOMP_FILTER_DEBUG 1 |
| 27 |
|
27 |
|
| 28 |
#if 0 |
28 |
#if 0 |
| 29 |
/* |
29 |
/* |
|
Lines 79-84
Link Here
|
| 79 |
#ifdef SANDBOX_SECCOMP_FILTER_DEBUG |
79 |
#ifdef SANDBOX_SECCOMP_FILTER_DEBUG |
| 80 |
# undef SECCOMP_FILTER_FAIL |
80 |
# undef SECCOMP_FILTER_FAIL |
| 81 |
# define SECCOMP_FILTER_FAIL SECCOMP_RET_TRAP |
81 |
# define SECCOMP_FILTER_FAIL SECCOMP_RET_TRAP |
|
|
82 |
# ifdef WITH_OPENSSL |
| 83 |
# include <openssl/dh.h> |
| 84 |
# endif /* WITH_OPENSSL */ |
| 85 |
# ifdef GSSAPI |
| 86 |
# include "ssh-gss.h" |
| 87 |
# endif /* GSSAPI */ |
| 88 |
# include "monitor_wrap.h" |
| 82 |
#endif /* SANDBOX_SECCOMP_FILTER_DEBUG */ |
89 |
#endif /* SANDBOX_SECCOMP_FILTER_DEBUG */ |
| 83 |
|
90 |
|
| 84 |
#if __BYTE_ORDER == __LITTLE_ENDIAN |
91 |
#if __BYTE_ORDER == __LITTLE_ENDIAN |
|
Lines 364-380
ssh_sandbox_init(struct monitor *monitor)
Link Here
|
| 364 |
} |
371 |
} |
| 365 |
|
372 |
|
| 366 |
#ifdef SANDBOX_SECCOMP_FILTER_DEBUG |
373 |
#ifdef SANDBOX_SECCOMP_FILTER_DEBUG |
| 367 |
extern struct monitor *pmonitor; |
374 |
/* convert an integer to a hex string; for use in signal handler */ |
| 368 |
void mm_log_handler(LogLevel level, int forced, const char *msg, void *ctx); |
375 |
static const char * |
|
|
376 |
ntoh(long unsigned int n) |
| 377 |
{ |
| 378 |
static char ret[sizeof(long unsigned int) * 2 + 2 + 1]; |
| 379 |
int i = sizeof(ret) - 2; |
| 380 |
|
| 381 |
if (n == 0) |
| 382 |
return "0"; |
| 383 |
while (n > 0) { |
| 384 |
ret[i--] = "0123456789abcdef"[n & 0xf]; |
| 385 |
n >>= 4; |
| 386 |
} |
| 387 |
ret[i--] = 'x'; |
| 388 |
ret[i--] = '0'; |
| 389 |
ret[sizeof(ret) - 1] = '\0'; |
| 390 |
return &(ret[i + 1]); |
| 391 |
} |
| 369 |
|
392 |
|
| 370 |
static void |
393 |
static void |
| 371 |
ssh_sandbox_violation(int signum, siginfo_t *info, void *void_context) |
394 |
ssh_sandbox_violation(int signum, siginfo_t *info, void *void_context) |
| 372 |
{ |
395 |
{ |
| 373 |
char msg[256]; |
396 |
char msg[256]; |
|
|
397 |
extern struct monitor *pmonitor; |
| 398 |
|
| 399 |
if (pmonitor == NULL) |
| 400 |
_exit(1); |
| 401 |
|
| 402 |
strlcpy(msg, __func__, sizeof(msg)); |
| 403 |
strlcat(msg, ": unexpected system call: arch:", sizeof(msg)); |
| 404 |
strlcat(msg, ntoh(info->si_arch), sizeof(msg)); |
| 405 |
strlcat(msg, " syscall:", sizeof(msg)); |
| 406 |
strlcat(msg, ntoh(info->si_syscall), sizeof(msg)); |
| 407 |
strlcat(msg, " addr:", sizeof(msg)); |
| 408 |
strlcat(msg, ntoh((unsigned long)info->si_call_addr), sizeof(msg)); |
| 374 |
|
409 |
|
| 375 |
snprintf(msg, sizeof(msg), |
|
|
| 376 |
"%s: unexpected system call (arch:0x%x,syscall:%d @ %p)", |
| 377 |
__func__, info->si_arch, info->si_syscall, info->si_call_addr); |
| 378 |
mm_log_handler(SYSLOG_LEVEL_FATAL, 0, msg, pmonitor); |
410 |
mm_log_handler(SYSLOG_LEVEL_FATAL, 0, msg, pmonitor); |
| 379 |
_exit(1); |
411 |
_exit(1); |
| 380 |
} |
412 |
} |
|
Lines 391-397
ssh_sandbox_child_debugging(void)
Link Here
|
| 391 |
sigaddset(&mask, SIGSYS); |
423 |
sigaddset(&mask, SIGSYS); |
| 392 |
|
424 |
|
| 393 |
act.sa_sigaction = &ssh_sandbox_violation; |
425 |
act.sa_sigaction = &ssh_sandbox_violation; |
| 394 |
act.sa_flags = SA_SIGINFO; |
426 |
act.sa_flags = SA_SIGINFO | SA_RESETHAND; |
| 395 |
if (sigaction(SIGSYS, &act, NULL) == -1) |
427 |
if (sigaction(SIGSYS, &act, NULL) == -1) |
| 396 |
fatal("%s: sigaction(SIGSYS): %s", __func__, strerror(errno)); |
428 |
fatal("%s: sigaction(SIGSYS): %s", __func__, strerror(errno)); |
| 397 |
if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1) |
429 |
if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1) |