-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restrict systems operations on OpenBSD #2934
Conversation
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
b82c231 "Remove -i option (jqlang#704)" removed its last usage in 2015. Spotted while looking for code could potentially write/create/modify files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@nicowilliams i think we discussed merging openbsd patches some months ago?
FWIW, there is just one other years-old patch for the configure script to "fix" thread-local storage detection (when using clang/LLVM), but at least on amd64 using clang 13.0.0 this no longer seems to be needed. I'll have yet to check other architectures/compiler combinations, but it seems this patch can go, i.e. this PR about pledge would be the only patch relevant to upstream/you. |
Otherwise `AGRS` and `program_arguments` remain allocated/unfreed in the early (extremely unlikely) pledge(2) failure case. Move their allocation before jq_init(), the first case of jumping to `out` where they are cleaned up, where it also seems to logically fit better than above between function entry, locale setup and OpenBSD specific pledge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If jq_init() fails, goto out would try to free input_state which is uninitialised. I initialised input_state to NULL to fix the problem. I also fixed input_jq_util_input_init() not handling OOM errors by returning NULL, and added code to make jq exit cleanly if it returns NULL. The code base is filled with these kinds of problems, but this one was easy to fix, so might as well fix it now... Ref: jqlang#2934 (comment) Reported-By: Klemens Nanni <kn@openbsd.org>
If jq_init() fails, goto out would try to free input_state which is uninitialised. I initialised input_state to NULL to fix the problem. I also fixed input_jq_util_input_init() not handling OOM errors by returning NULL, and added code to make jq exit cleanly if it returns NULL. The code base is filled with these kinds of problems, but this one was easy to fix, so might as well fix it now... Ref: jqlang#2934 (comment) Reported-By: Klemens Nanni <kn@openbsd.org>
If jq_init() fails, goto out would try to free input_state which is uninitialised. I initialised input_state to NULL to fix the problem. I also fixed jq_util_input_init() not handling OOM errors by returning NULL, and added code to make jq exit cleanly if it returns NULL. The code base is filled with these kinds of problems, but this one was easy to fix, so might as well fix it now... Ref: jqlang#2934 (comment) Reported-By: Klemens Nanni <kn@openbsd.org>
Just FYI the |
I see over three year old, barely documented code to My impression is that this won't land any time soon. Not sure what you mean with "explicit authz jq program", but either way, yes, that would have to pry open the currently nicely small and secure set of promises. I personally don't care about this until it is considered to land in jq proper. |
If jq_init() fails, goto out would try to free input_state which is uninitialised. I initialised input_state to NULL to fix the problem. I also fixed jq_util_input_init() not handling OOM errors by returning NULL, and added code to make jq exit cleanly if it returns NULL. The code base is filled with these kinds of problems, but this one was easy to fix, so might as well fix it now... Ref: jqlang#2934 (comment) Reported-By: Klemens Nanni <kn@openbsd.org>
Thanks! |
If jq_init() fails, goto out would try to free input_state which is uninitialised. I initialised input_state to NULL to fix the problem. Ref: jqlang#2934 (comment) Reported-By: Klemens Nanni <kn@openbsd.org>
If jq_init() fails, goto out would try to free input_state which is uninitialised. I initialised input_state to NULL to fix the problem. Ref: #2934 (comment) Reported-By: Klemens Nanni <kn@openbsd.org>
If we express sandbox constraints as JSON then we could use those to drive pledges. If we express sandbox constraints as jq programs whose inputs are descriptions of actions the user's jq program wants to do and whose outputs are booleans (allowed and disallowed) then that won't work with pledges at all. The thought occurs that it would be nice if one could use a command-line utility -let's call it |
This is not how pledge(2) was designed, I don't expect there to be this kind of wrapper. |
For what it is worth, SerenityOS has a Though you might think impleminting it is as simple as doing If |
Indeed, that's the sort of problem I was referring to by "bootstrap". If there was a |
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:
f1c4947 "Avoid getpwuid for static linking" removed getpwuid(3) usage
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