Skip to content
Myr

Restrict systems operations on OpenBSD

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Use pledge(2)[0] to limit jq(1) to reading files. It does not change files and only writes to standard output/error. It never deals with TTY, network, process management or other subsystems. This is to reduce jq's attack surface and potential damage. OpenBSD is carrying a local patch[1] in its official jq port/package since 2016. An improved version: - drop no longer needed "getpw" promise f1c4947 "Avoid getpwuid for static linking" removed getpwuid(3) usage - pledge before jq_init() to simplify the error path - use perror(3) to print errno(2) No behaviour change in tests or real world usage observed on OpenBSD/amd64 7.4. 0: https://man.openbsd.org/pledge.2 1: https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/textproc/jq/patches/patch-main_c

authored by Klemens Nanni · committed by Nico Williams · parent 9de0e26 · Browse files · 1 file+7 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • 0: https://man.openbsd.org/pledge.2
  • 1: https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/textproc/jq/patches/patch-main_c

Diff stats

1 file+7 added−0 removed

  • other:+7 added−0 removed

1 file+7 added−0 removed

modified:src/main.c+7 added
322 unmodified lines
323#ifdef HAVE_SETLOCALE324 (void) setlocale(LC_ALL, "");325#endif326327#ifdef __OpenBSD__328 if (pledge("stdio rpath", NULL) == -1) {329 perror("pledge");330 exit(JQ_ERROR_SYSTEM);331 }332#endif333334#ifdef WIN32335 jv_tsd_dtoa_ctx_init();336 fflush(stdout);337 fflush(stderr);
448 unmodified lines