AC_MSG_CHECKING([if sandboxing should be used])
AC_ARG_ENABLE([sandbox], [AS_HELP_STRING([--enable-sandbox=METHOD],
- [Sandboxing METHOD can be `auto', `no', or `capsicum'.
+ [Sandboxing METHOD can be
+ `auto', `no', `capsicum', or `pledge'.
The default is `auto' which enables sandboxing if
a supported sandboxing method is found.])],
[], [enable_sandbox=auto])
auto)
AC_MSG_RESULT([maybe (autodetect)])
;;
- no | capsicum)
+ no | capsicum | pledge)
AC_MSG_RESULT([$enable_sandbox])
;;
*)
AC_MSG_RESULT([])
- AC_MSG_ERROR([--enable-sandbox only accepts `auto', `no', or `capsicum'.])
+ AC_MSG_ERROR([--enable-sandbox only accepts `auto', `no', `capsicum', or `pledge'.])
;;
esac
AX_CHECK_CAPSICUM([enable_sandbox=found], [:])
;;
esac
+case $enable_sandbox in
+ auto | pledge)
+ AC_CHECK_FUNCS([pledge], [enable_sandbox=found ; break])
+ ;;
+esac
# If a specific sandboxing method was explicitly requested and it wasn't
# found, give an error.
if (cap_enter())
goto error;
+#elif defined(HAVE_PLEDGE)
+ // pledge() was introduced in OpenBSD 5.9.
+ //
+ // main() unconditionally calls pledge() with fairly relaxed
+ // promises which work in all situations. Here we make the
+ // sandbox more strict.
+ if (pledge("stdio", ""))
+ goto error;
+
+ (void)src_fd;
+
#else
# error ENABLE_SANDBOX is defined but no sandboxing method was found.
#endif
// on the command line, thus this must be done before args_parse().
hardware_init();
+#ifdef HAVE_PLEDGE
+ // OpenBSD's pledge() sandbox
+ //
+ // Unconditionally enable sandboxing with fairly relaxed promises.
+ // This is still way better than having no sandbox at all. :-)
+ // More strict promises will be made later in file_io.c if possible.
+ //
+ // This is done only after the above initializations
+ // as the error message needs locale support.
+ if (pledge("stdio rpath wpath cpath fattr", ""))
+ message_fatal(_("Failed to enable the sandbox"));
+#endif
+
// Parse the command line arguments and get an array of filenames.
// This doesn't return if something is wrong with the command line
// arguments. If there are no arguments, one filename ("-") is still
# define STDERR_FILENO (fileno(stderr))
#endif
-#ifdef HAVE_CAPSICUM
+#if defined(HAVE_CAPSICUM) || defined(HAVE_PLEDGE)
# define ENABLE_SANDBOX 1
#endif