libsepol/cil: Add function to get number of items in a stack
PATCH 1/2 libsepol/cil: Add function to get number of items in a stack
Add the function, cil_stack_number_of_items(), to return the number of items in the stack.
Signed-off-by James Carter <[email protected]>
--- libsepol/cil/src/cil_stack.c | 5 +++++ libsepol/cil/src/cil_stack.h | 1 + 2 files changed, 6 insertions(+)
libsepol/cil/src/cil_stack.c +5 -0
@@ -67,6 +67,11 @@ int cil_stack_is_empty(struct cil_stack *stack)return (stack->pos ==-1 ); } +int cil_stack_number_of_items (struct cil_stack *stack) +{ +return stack->pos +1 ; +} +void cil_stack_push (struct cil_stack *stack,enum cil_flavor flavor,void *data) { stack->pos++;
libsepol/cil/src/cil_stack.h +1 -0
@@ -52,6 +52,7 @@ void cil_stack_destroy(struct cil_stack **stack);void cil_stack_empty (struct cil_stack *stack);int cil_stack_is_empty (struct cil_stack *stack); +int cil_stack_number_of_items (struct cil_stack *stack);void cil_stack_push (struct cil_stack *stack,enum cil_flavor flavor,void *data);struct cil_stack_item *cil_stack_pop (struct cil_stack *stack);
Signature · 1 line
2.31.1
PATCH 2/2 libsepol/cil: Limit the number of active line marks
A line mark functions like an open parenthesis, so the number of active line marks should be limited like the number of open parenthesis.
This issue was found by the secilc-fuzzer.
Signed-off-by James Carter <[email protected]>
--- libsepol/cil/src/cil_parser.c | 4 ++++ 1 file changed, 4 insertions(+)
libsepol/cil/src/cil_parser.c +4 -0
@@ -131,6 +131,10 @@ static int add_hll_linemark(struct cil_tree_node **current, uint32_t *hll_offset *current = (*current)->parent; }else {push_hll_info (stack, *hll_offset, *hll_expand); +if (cil_stack_number_of_items (stack) >CIL_PARSER_MAX_EXPR_DEPTH ) { +cil_log (CIL_ERR ,"Number of active line marks exceeds limit of %d\n" ,CIL_PARSER_MAX_EXPR_DEPTH ); + goto exit; + }create_node (&node, *current, tok.line, *hll_offset,NULL );insert_node (node, *current);
Signature · 1 line
2.31.1
Re: [PATCH 2/2] libsepol/cil: Limit the number of active line marks
Quoted 8 lines · James Carter
A line mark functions like an open parenthesis, so the number of active line marks should be limited like the number of open parenthesis.
This issue was found by the secilc-fuzzer.
Signed-off-by James Carter <[email protected]>
For both patches:
Acked-by Nicolas Iooss <[email protected]>
Thanks,
Nicolas
Quoted 22 lines
--- libsepol/cil/src/cil_parser.c | 4 ++++ 1 file changed, 4 insertions(+)libsepol/cil/src/cil_parser.c +4
-1@@ -131,6 +131,10 @@ static int add_hll_linemark(struct cil_tree_node **current, uint32_t *hll_offset *current = (*current)->parent; }else {push_hll_info (stack, *hll_offset, *hll_expand); +if (cil_stack_number_of_items (stack) >CIL_PARSER_MAX_EXPR_DEPTH ) { +cil_log (CIL_ERR ,"Number of active line marks exceeds limit of %d\n" ,CIL_PARSER_MAX_EXPR_DEPTH ); + goto exit; + }create_node (&node, *current, tok.line, *hll_offset,NULL );insert_node (node, *current); --2.31.1