From: James Carter <jwcart2@gmail.com>
To: selinux@vger.kernel.org
Cc: James Carter <jwcart2@gmail.com>
Subject: [PATCH v3 1/2] libsepol: Fix type alias handling in kernel_to_cil
Date: Fri, 22 May 2020 10:50:37 -0400 [thread overview]
Message-ID: <20200522145038.194209-1-jwcart2@gmail.com> (raw)
Type alias rules are not written out when converting a binary kernel
policy to CIL. The problem is that type aliases are not in the
type_val_to_struct array and that is what is being used to find the
aliases.
Since type aliases are only in the types hashtable, walk that to
find the type aliases.
Fixes: 70a480bfcd46214a ("libsepol: Add ability to convert binary
policy to CIL")
Signed-off-by: James Carter <jwcart2@gmail.com>
---
v2: No changes
v3: Add "__attribute__((unused))" to unused parameters as suggested by
Nicolas Iooss
libsepol/src/kernel_to_cil.c | 44 +++++++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/libsepol/src/kernel_to_cil.c b/libsepol/src/kernel_to_cil.c
index ede78a20..9acf2ec2 100644
--- a/libsepol/src/kernel_to_cil.c
+++ b/libsepol/src/kernel_to_cil.c
@@ -1367,33 +1367,55 @@ exit:
return rc;
}
+static int map_count_type_aliases(__attribute__((unused)) char *key, void *data, void *args)
+{
+ type_datum_t *datum = data;
+ unsigned *count = args;
+
+ if (datum->primary == 0 && datum->flavor == TYPE_TYPE)
+ (*count)++;
+
+ return SEPOL_OK;
+}
+
+static int map_type_aliases_to_strs(char *key, void *data, void *args)
+{
+ type_datum_t *datum = data;
+ struct strs *strs = args;
+ int rc = 0;
+
+ if (datum->primary == 0 && datum->flavor == TYPE_TYPE)
+ rc = strs_add(strs, key);
+
+ return rc;
+}
+
static int write_type_alias_rules_to_cil(FILE *out, struct policydb *pdb)
{
type_datum_t *alias;
struct strs *strs;
char *name;
char *type;
- unsigned i, num;
+ unsigned i, num = 0;
int rc = 0;
- rc = strs_init(&strs, pdb->p_types.nprim);
+ rc = hashtab_map(pdb->p_types.table, map_count_type_aliases, &num);
if (rc != 0) {
goto exit;
}
- for (i=0; i < pdb->p_types.nprim; i++) {
- alias = pdb->type_val_to_struct[i];
- if (!alias->primary) {
- rc = strs_add(strs, pdb->p_type_val_to_name[i]);
- if (rc != 0) {
- goto exit;
- }
- }
+ rc = strs_init(&strs, num);
+ if (rc != 0) {
+ goto exit;
+ }
+
+ rc = hashtab_map(pdb->p_types.table, map_type_aliases_to_strs, strs);
+ if (rc != 0) {
+ goto exit;
}
strs_sort(strs);
- num = strs_num_items(strs);
for (i=0; i<num; i++) {
name = strs_read_at_index(strs, i);
if (!name) {
--
2.25.4
next reply other threads:[~2020-05-22 14:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-22 14:50 James Carter [this message]
2020-05-22 14:50 ` [PATCH v3 2/2] libsepol: Fix type alias handling in kernel_to_conf James Carter
2020-05-27 14:22 ` Stephen Smalley
2020-05-27 14:44 ` James Carter
2020-05-27 21:15 ` James Carter
2020-05-29 12:57 ` Stephen Smalley
2020-05-29 12:53 ` Stephen Smalley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200522145038.194209-1-jwcart2@gmail.com \
--to=jwcart2@gmail.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).