check for setsockopt IP_TOS in OpenBSD pledge

OpenBSD has recently relaxed the pledge(2) sandbox to allow some
setsockopt options to be changed without the "inet" promise.

This adds compatibility for OpenBSD that predates this relaxation.
This commit is contained in:
Damien Miller committed 2025-08-18 16:45:15 +10:00
1 parent ae44cd74f3
commit 9184fa3636
2 files changed
+31 -2

No files matched your search

+2 -2
View File
@@ -975,11 +975,11 @@ client_repledge(void)
} else if (options.forward_agent != 0) {
/* agent forwarding needs to open $SSH_AUTH_SOCK at will */
debug("pledge: agent");
if (pledge("stdio unix proc tty", NULL) == -1)
if (pledge(PLEDGE_EXTRA_INET "stdio unix proc tty", NULL) == -1)
fatal_f("pledge(): %s", strerror(errno));
} else {
debug("pledge: fork");
if (pledge("stdio proc tty", NULL) == -1)
if (pledge(PLEDGE_EXTRA_INET "stdio proc tty", NULL) == -1)
fatal_f("pledge(): %s", strerror(errno));
}
/* XXX further things to do:
+29
View File
@@ -1128,6 +1128,35 @@ mips-sony-bsd|mips-sony-newsos4)
AC_DEFINE([SYSLOG_R_SAFE_IN_SIGHAND], [1],
[syslog_r function is safe to use in in a signal handler])
TEST_MALLOC_OPTIONS="SJRU"
AC_MSG_CHECKING([whether pledge(2) allows IP_TOS])
need_pledge_inet=""
AC_RUN_IFELSE(
[AC_LANG_PROGRAM([[
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <stdlib.h>
#include <err.h>
]], [[
int s, one = 1;
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
err(1, "socket");
if (pledge("stdio", NULL) == -1)
err(1, "pledge");
if (setsockopt(s, IPPROTO_IP, IP_TOS, &one, sizeof(one)) == -1)
err(1, "setsockopt");
]])],
[ AC_MSG_RESULT([yes]) ], [
AC_MSG_RESULT([no])
need_pledge_inet=1
],
[ AC_MSG_WARN([cross compiling: cannot test]) ])
if test -z "$need_pledge_inet" ; then
AC_DEFINE_UNQUOTED([PLEDGE_EXTRA_INET], [])
else
AC_DEFINE_UNQUOTED([PLEDGE_EXTRA_INET], ["inet "],
[need inet in pledge for setsockopt IP_TOS])
fi
;;
*-*-solaris*)
if test "x$withval" != "xno" ; then