Skip to content

Commit

Permalink
ofp-actions: Set an action depth limit to prevent stackoverflow by of…
Browse files Browse the repository at this point in the history
…pacts_parse

Reported-at: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12557
Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
yifsun authored and blp committed Feb 4, 2019
1 parent 561ac83 commit 1f886f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/openvswitch/ofp-actions.h
Expand Up @@ -1175,7 +1175,11 @@ struct ofpact_parse_params {
/* Output. */
struct ofpbuf *ofpacts;
enum ofputil_protocol *usable_protocols;

/* Parse context. */
unsigned int depth;
};
#define MAX_OFPACT_PARSE_DEPTH 100
char *ofpacts_parse_actions(const char *, const struct ofpact_parse_params *)
OVS_WARN_UNUSED_RESULT;
char *ofpacts_parse_instructions(const char *,
Expand Down
5 changes: 5 additions & 0 deletions lib/ofp-actions.c
Expand Up @@ -9062,11 +9062,16 @@ static char * OVS_WARN_UNUSED_RESULT
ofpacts_parse(char *str, const struct ofpact_parse_params *pp,
bool allow_instructions, enum ofpact_type outer_action)
{
if (pp->depth >= MAX_OFPACT_PARSE_DEPTH) {
return xstrdup("Action nested too deeply");
}
CONST_CAST(struct ofpact_parse_params *, pp)->depth++;
uint32_t orig_size = pp->ofpacts->size;
char *error = ofpacts_parse__(str, pp, allow_instructions, outer_action);
if (error) {
pp->ofpacts->size = orig_size;
}
CONST_CAST(struct ofpact_parse_params *, pp)->depth--;
return error;
}

Expand Down

0 comments on commit 1f886f0

Please sign in to comment.