This is kinda important.
ps_freeprocess(psp);
return -1;
case 0:
- ps_entersandbox("stdio");
+ ps_entersandbox("stdio", NULL);
break;
default:
#ifdef PRIVSEP_DEBUG
ps_ctl_listen, ctx) == -1)
return -1;
- ps_entersandbox("stdio inet");
+ ps_entersandbox("stdio inet", NULL);
return 0;
}
PSF_DROPPRIVS);
if (pid == 0)
- ps_entersandbox("stdio");
+ ps_entersandbox("stdio", NULL);
return pid;
}
ps_freeprocess(psp);
return -1;
case 0:
- ps_entersandbox("stdio");
+ ps_entersandbox("stdio", NULL);
break;
default:
break;
ps_seccomp_enter(void)
{
- if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1)
- return errno == EINVAL ? 0 : -1;
- if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &ps_seccomp_prog) == -1)
- return errno == EINVAL ? 0 : -1;
+ if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1 ||
+ prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &ps_seccomp_prog) == -1)
+ {
+ if (errno == EINVAL)
+ errno = ENOSYS;
+ return -1;
+ }
return 0;
}
}
int
-ps_entersandbox(const char *_pledge)
+ps_entersandbox(const char *_pledge, const char **sandbox)
{
#ifdef HAVE_CAPSICUM
- if (cap_enter() == -1 && errno != ENOSYS) {
- logerr("%s: cap_enter", __func__);
- return -1;
- }
+ if (sandbox != NULL)
+ *sandbox = "capsicum";
+ return cap_enter();
#endif
#ifdef HAVE_PLEDGE
- if (pledge(_pledge, NULL) == -1) {
- logerr("%s: pledge", __func__);
- return -1;
- }
+ if (sandbox != NULL)
+ *sandbox = "pledge";
+ return pledge(_pledge, NULL);
#else
UNUSED(_pledge);
#endif
#ifdef HAVE_SECCOMP
- if (ps_seccomp_enter() == -1) {
- logerr("%s: ps_seccomp_enter", __func__);
- return -1;
- }
+ if (sandbox != NULL)
+ *sandbox = "seccomp";
+ return ps_seccomp_enter();
#endif
+ if (sandbox != NULL)
+ *sandbox = NULL;
return 0;
}
int
ps_mastersandbox(struct dhcpcd_ctx *ctx)
{
+ const char *sandbox = NULL;
if (ps_dropprivs(ctx) == -1) {
logerr("%s: ps_dropprivs", __func__);
}
#endif
- return ps_entersandbox("stdio route");
+ if (ps_entersandbox("stdio route", &sandbox) == -1) {
+ if (errno == ENOSYS) {
+ if (sandbox != NULL)
+ logwarnx("sandbox unavailable: %s", sandbox);
+ return 0;
+ }
+ logerr("%s: %s", __func__, sandbox);
+ return -1;
+ } else if (sandbox != NULL)
+ loginfox("sandbox: %s", sandbox);
+ return 0;
}
int
int ps_init(struct dhcpcd_ctx *);
int ps_start(struct dhcpcd_ctx *);
int ps_stop(struct dhcpcd_ctx *);
-int ps_entersandbox(const char *);
+int ps_entersandbox(const char *, const char **);
int ps_mastersandbox(struct dhcpcd_ctx *);
int ps_unrollmsg(struct msghdr *, struct ps_msghdr *, const void *, size_t);