From 8072dba146b213a3f12a394596537e73f1b9339c Mon Sep 17 00:00:00 2001 From: Harry Ciao Date: Mon, 25 Jul 2011 09:23:55 +0800 Subject: [PATCH] Add role attribute support when generating pp files. Add support to read/write the flavor flag and roles ebitmap in the role_datum_t structure from/to policy module, if its version is no less than MOD_POLICYDB_VERSION_ROLEATTRIB. Since the role ebitmap would be expanded and won't be written into policy.X, neither is the flavor flag, kernel SELinux security server needs no change, the maximum version number for policy.X needs no bump. Signed-off-by: Harry Ciao Signed-off-by: Steve Lawrence --- libsepol/include/sepol/policydb/policydb.h | 3 ++- libsepol/src/policydb.c | 26 ++++++++++++++++++++++ libsepol/src/write.c | 11 +++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/libsepol/include/sepol/policydb/policydb.h b/libsepol/include/sepol/policydb/policydb.h index b59ab2e3..5320bc8a 100644 --- a/libsepol/include/sepol/policydb/policydb.h +++ b/libsepol/include/sepol/policydb/policydb.h @@ -682,9 +682,10 @@ extern int policydb_set_target_platform(policydb_t *p, int platform); #define MOD_POLICYDB_VERSION_BOUNDARY_ALIAS 10 #define MOD_POLICYDB_VERSION_FILENAME_TRANS 11 #define MOD_POLICYDB_VERSION_ROLETRANS 12 +#define MOD_POLICYDB_VERSION_ROLEATTRIB 13 #define MOD_POLICYDB_VERSION_MIN MOD_POLICYDB_VERSION_BASE -#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_ROLETRANS +#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_ROLEATTRIB #define POLICYDB_CONFIG_MLS 1 diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c index eb6d5903..9145f2ab 100644 --- a/libsepol/src/policydb.c +++ b/libsepol/src/policydb.c @@ -213,6 +213,13 @@ static struct policydb_compat_info policydb_compat[] = { .ocon_num = OCON_NODE6 + 1, .target_platform = SEPOL_TARGET_SELINUX, }, + { + .type = POLICY_BASE, + .version = MOD_POLICYDB_VERSION_ROLEATTRIB, + .sym_num = SYM_NUM, + .ocon_num = OCON_NODE6 + 1, + .target_platform = SEPOL_TARGET_SELINUX, + }, { .type = POLICY_MOD, .version = MOD_POLICYDB_VERSION_BASE, @@ -276,6 +283,13 @@ static struct policydb_compat_info policydb_compat[] = { .ocon_num = 0, .target_platform = SEPOL_TARGET_SELINUX, }, + { + .type = POLICY_MOD, + .version = MOD_POLICYDB_VERSION_ROLEATTRIB, + .sym_num = SYM_NUM, + .ocon_num = 0, + .target_platform = SEPOL_TARGET_SELINUX, + }, }; #if 0 @@ -2090,6 +2104,18 @@ static int role_read(policydb_t * p if (type_set_read(&role->types, fp)) goto bad; } + + if (p->policy_type != POLICY_KERN && + p->policyvers >= MOD_POLICYDB_VERSION_ROLEATTRIB) { + rc = next_entry(buf, fp, sizeof(uint32_t)); + if (rc < 0) + goto bad; + + role->flavor = le32_to_cpu(buf[0]); + + if (ebitmap_read(&role->roles, fp)) + goto bad; + } if (strcmp(key, OBJECT_R) == 0) { if (role->s.value != OBJECT_R_VAL) { diff --git a/libsepol/src/write.c b/libsepol/src/write.c index 9657e6c4..290e0365 100644 --- a/libsepol/src/write.c +++ b/libsepol/src/write.c @@ -996,6 +996,17 @@ static int role_write(hashtab_key_t key, hashtab_datum_t datum, void *ptr) return POLICYDB_ERROR; } + if (p->policy_type != POLICY_KERN && + p->policyvers >= MOD_POLICYDB_VERSION_ROLEATTRIB) { + buf[0] = cpu_to_le32(role->flavor); + items = put_entry(buf, sizeof(uint32_t), 1, fp); + if (items != 1) + return POLICYDB_ERROR; + + if (ebitmap_write(&role->roles, fp)) + return POLICYDB_ERROR; + } + return POLICYDB_SUCCESS; }