Skip to content
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

job-list: limit constraint comparisons to avoid DoS #5681

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cmd/job/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int cmd_list (optparse_t *p, int argc, char **argv)
"constraint", c)))
log_err_exit ("flux_rpc_pack");
if (flux_rpc_get_unpack (f, "{s:o}", "jobs", &jobs) < 0)
log_err_exit ("flux job-list.list");
log_msg_exit ("flux job-list.list: %s", future_strerror (f, errno));
json_array_foreach (jobs, index, value) {
char *str;
str = json_dumps (value, 0);
Expand Down Expand Up @@ -173,7 +173,7 @@ int cmd_list_inactive (optparse_t *p, int argc, char **argv)
"constraint", c)))
log_err_exit ("flux_rpc_pack");
if (flux_rpc_get_unpack (f, "{s:o}", "jobs", &jobs) < 0)
log_err_exit ("flux job-list.list");
log_msg_exit ("flux job-list.list: %s", future_strerror (f, errno));
json_array_foreach (jobs, index, value) {
char *str;
str = json_dumps (value, 0);
Expand All @@ -193,7 +193,7 @@ void list_id_continuation (flux_future_t *f, void *arg)
json_t *job;
char *str;
if (flux_rpc_get_unpack (f, "{s:o}", "job", &job) < 0)
log_err_exit ("flux_job_list_id");
log_msg_exit ("flux job-list.list-d: %s", future_strerror (f, errno));
str = json_dumps (job, 0);
if (!str)
log_msg_exit ("error parsing list-id response");
Expand Down
8 changes: 8 additions & 0 deletions src/modules/job-list/job-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ static void config_reload_cb (flux_t *h,
errstr = error.text;
goto error;
}
if (job_match_config_reload (ctx->mctx, conf, &error) < 0) {
errstr = error.text;
goto error;
}
if (flux_respond (h, msg, NULL) < 0)
flux_log_error (h, "error responding to config-reload request");
return;
Expand Down Expand Up @@ -206,6 +210,8 @@ static void list_ctx_destroy (struct list_ctx *ctx)
job_state_destroy (ctx->jsctx);
if (ctx->isctx)
idsync_ctx_destroy (ctx->isctx);
if (ctx->mctx)
match_ctx_destroy (ctx->mctx);
free (ctx);
errno = saved_errno;
}
Expand All @@ -227,6 +233,8 @@ static struct list_ctx *list_ctx_create (flux_t *h)
goto error;
if (!(ctx->deferred_requests = flux_msglist_create ()))
goto error;
if (!(ctx->mctx = match_ctx_create (ctx->h)))
goto error;
return ctx;
error:
list_ctx_destroy (ctx);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/job-list/job-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

#include "job_state.h"
#include "idsync.h"
#include "match.h"

struct list_ctx {
flux_t *h;
flux_msg_handler_t **handlers;
struct job_state_ctx *jsctx;
struct idsync_ctx *isctx;
struct flux_msglist *deferred_requests;
struct match_ctx *mctx;
};

const char **job_attrs (void);
Expand Down
7 changes: 5 additions & 2 deletions src/modules/job-list/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ int get_jobs_from_list (json_t *jobs,

job = zlistx_first (list);
while (job) {
int ret;

/* If job->t_inactive > 0. we're on the inactive jobs list and jobs are
* sorted on the inactive list, larger t_inactive first.
Expand All @@ -68,7 +69,9 @@ int get_jobs_from_list (json_t *jobs,
if (job->t_inactive > 0. && job->t_inactive <= since)
break;

if (job_match (job, c)) {
if ((ret = job_match (job, c, errp)) < 0)
return -1;
if (ret) {
json_t *o;
if (!(o = job_to_json (job, attrs, errp)))
return -1;
Expand Down Expand Up @@ -311,7 +314,7 @@ void list_cb (flux_t *h, flux_msg_handler_t *mh,
errno = EPROTO;
goto error;
}
if (!(c = list_constraint_create (constraint, &error))) {
if (!(c = list_constraint_create (ctx->mctx, constraint, &error))) {
errprintf (&err,
"invalid payload: constraint object invalid: %s",
error.text);
Expand Down
Loading
Loading