Skip to content

Commit 817d914

Browse files
committed
Merge tag 'selinux-pr-20200621' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull SELinux fixes from Paul Moore: "Three small patches to fix problems in the SELinux code, all found via clang. Two patches fix potential double-free conditions and one fixes an undefined return value" * tag 'selinux-pr-20200621' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: fix undefined return of cond_evaluate_expr selinux: fix a double free in cond_read_node()/cond_read_list() selinux: fix double free
2 parents 16f4aa9 + 8231b0b commit 817d914

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

security/selinux/ss/conditional.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ static int cond_evaluate_expr(struct policydb *p, struct cond_expr *expr)
2727
int s[COND_EXPR_MAXDEPTH];
2828
int sp = -1;
2929

30+
if (expr->len == 0)
31+
return -1;
32+
3033
for (i = 0; i < expr->len; i++) {
3134
struct cond_expr_node *node = &expr->nodes[i];
3235

@@ -392,27 +395,19 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
392395

393396
rc = next_entry(buf, fp, sizeof(u32) * 2);
394397
if (rc)
395-
goto err;
398+
return rc;
396399

397400
expr->expr_type = le32_to_cpu(buf[0]);
398401
expr->bool = le32_to_cpu(buf[1]);
399402

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

406407
rc = cond_read_av_list(p, fp, &node->true_list, NULL);
407408
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;
409+
return rc;
410+
return cond_read_av_list(p, fp, &node->false_list, &node->true_list);
416411
}
417412

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

security/selinux/ss/services.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,8 +2888,12 @@ int security_get_bools(struct selinux_state *state,
28882888
if (*names) {
28892889
for (i = 0; i < *len; i++)
28902890
kfree((*names)[i]);
2891+
kfree(*names);
28912892
}
28922893
kfree(*values);
2894+
*len = 0;
2895+
*names = NULL;
2896+
*values = NULL;
28932897
goto out;
28942898
}
28952899

0 commit comments

Comments
 (0)