Skip to content

Commit

Permalink
libsepol/cil: Fix syntax checking of defaultrange rule
Browse files Browse the repository at this point in the history
When "glblub" was added as a default for the defaultrange rule, the
syntax array was updated because the "glblub" default does not need
to specify a range of "low", "high", or "low-high". Unfortunately,
additional checking was not added for the "source" and "target"
defaults to make sure they specified a range. This means that using
the "source" or "target" defaults without specifying the range will
result in a segfault.

When the "source" or "target" defaults are used, check that the rule
specifies a range as well.

This bug was found by the secilc-fuzzer.

Signed-off-by: James Carter <jwcart2@gmail.com>
Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>
  • Loading branch information
jwcart2 committed Jun 24, 2021
1 parent c28525a commit ac8b35d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libsepol/cil/src/cil_build_ast.c
Expand Up @@ -5886,6 +5886,11 @@ int cil_gen_defaultrange(struct cil_tree_node *parse_current, struct cil_tree_no

object = parse_current->next->next->data;
if (object == CIL_KEY_SOURCE) {
if (!parse_current->next->next->next) {
cil_log(CIL_ERR, "Missing 'low', 'high', or 'low-high'\n");
rc = SEPOL_ERR;
goto exit;
}
range = parse_current->next->next->next->data;
if (range == CIL_KEY_LOW) {
def->object_range = CIL_DEFAULT_SOURCE_LOW;
Expand All @@ -5899,6 +5904,11 @@ int cil_gen_defaultrange(struct cil_tree_node *parse_current, struct cil_tree_no
goto exit;
}
} else if (object == CIL_KEY_TARGET) {
if (!parse_current->next->next->next) {
cil_log(CIL_ERR, "Missing 'low', 'high', or 'low-high'\n");
rc = SEPOL_ERR;
goto exit;
}
range = parse_current->next->next->next->data;
if (range == CIL_KEY_LOW) {
def->object_range = CIL_DEFAULT_TARGET_LOW;
Expand Down

0 comments on commit ac8b35d

Please sign in to comment.