Skip to content

Commit 9521eb3

Browse files
WOnder93pcmoore
authored andcommitted
selinux: don't produce incorrect filename_trans_count
I thought I fixed the counting in filename_trans_read_helper() to count the compat rule count correctly in the final version, but it's still wrong. To really count the same thing as in the compat path, we'd need to add up the cardinalities of stype bitmaps of all datums. Since the kernel currently doesn't implement an ebitmap_cardinality() function (and computing the proper count would just waste CPU cycles anyway), just document that we use the field only in case of the old format and stop updating it in filename_trans_read_helper(). Fixes: 4300590 ("selinux: implement new format of filename transitions") Signed-off-by: Ondrej Mosnacek <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 4300590 commit 9521eb3

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

security/selinux/ss/policydb.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,12 +2016,7 @@ static int filename_trans_read_helper(struct policydb *p, void *fp)
20162016
if (rc)
20172017
goto out;
20182018

2019-
rc = ebitmap_set_bit(&p->filename_trans_ttypes, ttype, 1);
2020-
if (rc)
2021-
return rc;
2022-
2023-
p->filename_trans_count += ndatum;
2024-
return 0;
2019+
return ebitmap_set_bit(&p->filename_trans_ttypes, ttype, 1);
20252020

20262021
out:
20272022
kfree(ft);
@@ -2051,7 +2046,7 @@ static int filename_trans_read(struct policydb *p, void *fp)
20512046
nel = le32_to_cpu(buf[0]);
20522047

20532048
if (p->policyvers < POLICYDB_VERSION_COMP_FTRANS) {
2054-
p->filename_trans_count = nel;
2049+
p->compat_filename_trans_count = nel;
20552050
p->filename_trans = hashtab_create(filenametr_hash,
20562051
filenametr_cmp, (1 << 11));
20572052
if (!p->filename_trans)
@@ -3568,7 +3563,7 @@ static int filename_trans_write(struct policydb *p, void *fp)
35683563
return 0;
35693564

35703565
if (p->policyvers < POLICYDB_VERSION_COMP_FTRANS) {
3571-
buf[0] = cpu_to_le32(p->filename_trans_count);
3566+
buf[0] = cpu_to_le32(p->compat_filename_trans_count);
35723567
rc = put_entry(buf, sizeof(u32), 1, fp);
35733568
if (rc)
35743569
return rc;

security/selinux/ss/policydb.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ struct policydb {
270270
struct ebitmap filename_trans_ttypes;
271271
/* actual set of filename_trans rules */
272272
struct hashtab *filename_trans;
273-
u32 filename_trans_count;
273+
/* only used if policyvers < POLICYDB_VERSION_COMP_FTRANS */
274+
u32 compat_filename_trans_count;
274275

275276
/* bools indexed by (value - 1) */
276277
struct cond_bool_datum **bool_val_to_struct;

0 commit comments

Comments
 (0)