]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
check for setsockopt IP_TOS in OpenBSD pledge
authorDamien Miller <djm@mindrot.org>
Mon, 18 Aug 2025 06:45:15 +0000 (16:45 +1000)
committerDamien Miller <djm@mindrot.org>
Mon, 18 Aug 2025 06:45:15 +0000 (16:45 +1000)
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.

clientloop.c
configure.ac

index b9a010414ff33f5e64f2f431ff02f0bba8082d18..577771f06963cc7f19cbb42e4648541b48d5c89c 100644 (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:
index 460ebd3b476cce14ebb6e0430ad8821fa182e319..bc1900af7ad6acda8e5cbd8da3038adffd0c6276 100644 (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