Skip to content

Commit aa449a7

Browse files
Tom Rixpcmoore
authored andcommitted
selinux: fix a double free in cond_read_node()/cond_read_list()
Clang static analysis reports this double free error security/selinux/ss/conditional.c:139:2: warning: Attempt to free released memory [unix.Malloc] kfree(node->expr.nodes); ^~~~~~~~~~~~~~~~~~~~~~~ When cond_read_node fails, it calls cond_node_destroy which frees the node but does not poison the entry in the node list. So when it returns to its caller cond_read_list, cond_read_list deletes the partial list. The latest entry in the list will be deleted twice. So instead of freeing the node in cond_read_node, let list freeing in code_read_list handle the freeing the problem node along with all of the earlier nodes. Because cond_read_node no longer does any error handling, the goto's the error case are redundant. Instead just return the error code. Cc: [email protected] Fixes: 60abd31 ("selinux: convert cond_list to array") Signed-off-by: Tom Rix <[email protected]> Reviewed-by: Ondrej Mosnacek <[email protected]> [PM: subject line tweaks] Signed-off-by: Paul Moore <[email protected]>
1 parent 65de509 commit aa449a7

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

security/selinux/ss/conditional.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -392,27 +392,19 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
392392

393393
rc = next_entry(buf, fp, sizeof(u32) * 2);
394394
if (rc)
395-
goto err;
395+
return rc;
396396

397397
expr->expr_type = le32_to_cpu(buf[0]);
398398
expr->bool = le32_to_cpu(buf[1]);
399399

400-
if (!expr_node_isvalid(p, expr)) {
401-
rc = -EINVAL;
402-
goto err;
403-
}
400+
if (!expr_node_isvalid(p, expr))
401+
return -EINVAL;
404402
}
405403

406404
rc = cond_read_av_list(p, fp, &node->true_list, NULL);
407405
if (rc)
408-
goto err;
409-
rc = cond_read_av_list(p, fp, &node->false_list, &node->true_list);
410-
if (rc)
411-
goto err;
412-
return 0;
413-
err:
414-
cond_node_destroy(node);
415-
return rc;
406+
return rc;
407+
return cond_read_av_list(p, fp, &node->false_list, &node->true_list);
416408
}
417409

418410
int cond_read_list(struct policydb *p, void *fp)

0 commit comments

Comments
 (0)