put neverallows in avtab, propagate errors in policydb
PATCH 1/2 put neverallows in avtab, propagate errors in policydb
This is a rebase of the patch sent recently to allow neverallow rules to be put in the avtab. The suggestions including using policydb->unsupported_format and adding defined error codes to policydb read and write have been added.
libsepol/include/sepol/policydb/avtab.h +1 -0
@@ -45,6 +45,7 @@ typedef struct avtab_key {#define AVTAB_ALLOWED 1#define AVTAB_AUDITALLOW 2#define AVTAB_AUDITDENY 4 +#define AVTAB_NEVERALLOW 128#define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY)#define AVTAB_TRANSITION 16#define AVTAB_MEMBER 32
libsepol/include/sepol/policydb/policydb.h +9 -2
@@ -65,6 +65,10 @@#define ERRMSG_LEN 1024 +#define POLICYDB_SUCCESS 0 +#define POLICYDB_ERROR -1; +#define POLICYDB_UNSUPPORTED -2; +/* * A datum type is defined for each kind of symbol * in the configuration data: individual permissions,
@@ -194,12 +198,12 @@ typedef struct avrule {#define AVRULE_AUDITALLOW 2#define AVRULE_AUDITDENY 4#define AVRULE_DONTAUDIT 8 -#define AVRULE_AV (AVRULE_ALLOWED | AVRULE_AUDITALLOW | AVRULE_AUDITDENY | AVRULE_DONTAUDIT) +#define AVRULE_NEVERALLOW 128 +#define AVRULE_AV (AVRULE_ALLOWED | AVRULE_AUDITALLOW | AVRULE_AUDITDENY | AVRULE_DONTAUDIT | AVRULE_NEVERALLOW)#define AVRULE_TRANSITION 16#define AVRULE_MEMBER 32#define AVRULE_CHANGE 64#define AVRULE_TYPE (AVRULE_TRANSITION | AVRULE_MEMBER | AVRULE_CHANGE) -#define AVRULE_NEVERALLOW 128uint32_t specified;#define RULE_SELF 1uint32_t flags;
@@ -371,6 +375,9 @@ typedef struct policydb {char *name;char *version; +/* Set when the policydb is modified such that writing is unsupported */ +int unsupported_format; +/* Whether this policydb is mls, should always be set */ int mls;
libsepol/src/link.c +1 -2
@@ -964,8 +964,7 @@ static int copy_avrule_list(avrule_t * l module->map[SYM_CLASSES ][cur_perm->class -1 ];assert (new_perm->class); -if (new_rule-> - specified & (AVRULE_AV |AVRULE_NEVERALLOW )) { +if (new_rule->specified & (AVRULE_AV )) { for (i = 0; i < module->perm_map_len[cur_perm->class - 1];
libsepol/src/policydb.c +12 -12
@@ -2618,7 +2618,7 @@ int policydb_read(policydb_t * p, struct/* Read the magic number and string length. */ buf =next_entry (fp,sizeof (uint32_t ) *2 );if (!buf) -return -1 ; +return POLICYDB_ERROR ;for (i =0 ; i <2 ; i++) buf[i] =le32_to_cpu (buf[i]);
@@ -2632,26 +2632,26 @@ int policydb_read(policydb_t * p, structERR (fp->handle,"policydb magic number %#08x does not " "match expected magic number %#08x or %#08x" , buf[0 ],POLICYDB_MAGIC ,POLICYDB_MOD_MAGIC ); -return -1 ; +return POLICYDB_ERROR ; } len = buf[1 ];if (len !=strlen (target_str)) {ERR (fp->handle,"policydb string length %zu does not match " "expected length %zu" , len,strlen (target_str)); -return -1 ; +return POLICYDB_ERROR ; } buf =next_entry (fp, len);if (!buf) {ERR (fp->handle,"truncated policydb string identifier" ); -return -1 ; +return POLICYDB_ERROR ; } policydb_str =malloc (len +1 );if (!policydb_str) {ERR (fp->handle,"unable to allocate memory for policydb " "string of length %zu" , len); -return -1 ; +return POLICYDB_ERROR ; }memcpy (policydb_str, buf, len); policydb_str[len] =0 ;
@@ -2659,7 +2659,7 @@ int policydb_read(policydb_t * p, structERR (fp->handle,"policydb string %s does not match " "my string %s" , policydb_str, target_str);free (policydb_str); -return -1 ; +return POLICYDB_ERROR ; }/* Done with policydb_str. */ free (policydb_str);
@@ -2673,7 +2673,7 @@ int policydb_read(policydb_t * p, struct buf =next_entry (fp,sizeof (uint32_t ) * nel);if (!buf) -return -1 ; +return POLICYDB_ERROR ;for (i =0 ; i < nel; i++) buf[i] =le32_to_cpu (buf[i]);
@@ -2687,7 +2687,7 @@ int policydb_read(policydb_t * p, structif (policy_type !=POLICY_MOD && policy_type !=POLICY_BASE ) {ERR (fp->handle,"unknown module type: %#08x" , policy_type); -return -1 ; +return POLICYDB_ERROR ; } bufindex++; }
@@ -2699,7 +2699,7 @@ int policydb_read(policydb_t * p, structERR (fp->handle,"policydb version %d does not match " "my version range %d-%d" , buf[bufindex],POLICYDB_VERSION_MIN ,POLICYDB_VERSION_MAX ); -return -1 ; +return POLICYDB_ERROR ; } }else if (policy_type ==POLICY_BASE || policy_type ==POLICY_MOD ) { if (r_policyvers < MOD_POLICYDB_VERSION_MIN ||
@@ -2708,7 +2708,7 @@ int policydb_read(policydb_t * p, struct"not match my version range %d-%d" , buf[bufindex],MOD_POLICYDB_VERSION_MIN , MOD_POLICYDB_VERSION_MAX); -return -1 ; +return POLICYDB_ERROR ; } }else {assert (0 );
@@ -2870,9 +2870,9 @@ int policydb_read(policydb_t * p, struct } } -return 0 ; +return POLICYDB_SUCCESS ; bad: -return -1 ; +return POLICYDB_ERROR ; }int policydb_reindex_users (policydb_t * p)
libsepol/src/write.c +189 -186
1,065 lines not on this page · raw message
libsepol/src/expand.c +36 -19
164 lines not on this page · raw message
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 9 lines · Joshua Brindle
This is a rebase of the patch sent recently to allow neverallow rules to be put in the avtab. The suggestions including using
policydb->unsupported_formatand adding defined error codes to policydb read and write have been added.diff -urpN -x 'Change*' -x entries -x '*.orig' -x '*.rej' -x '*.svn*' -x '*.swp'
trunk/libsepol/include/sepol/policydb/policydb.hbranch/setools_public-policydb-components/libsepol/include/sepol/policydb/policydb.h
libsepol/include/sepol/policydb/policydb.h line 70
Quoted 6 lines
libsepol/include/sepol/policydb/policydb.h +3
-0@@ -65,6 +65,10 @@#define ERRMSG_LEN 1024 +#define POLICYDB_SUCCESS 0 +#define POLICYDB_ERROR -1; +#define POLICYDB_UNSUPPORTED -2;
Spurious semicolons.
libsepol/src/link.c static int copy_avrule_list(avrule_t * l · line 967
Quoted 10 lines
diff -urpN -x 'Change*' -x entries -x '*.orig' -x '*.rej' -x '*.svn*' -x '*.swp'
trunk/libsepol/src/link.cbranch/setools_public-policydb-components/libsepol/src/link.clibsepol/src/link.c +1
-2@@ -964,8 +964,7 @@ static int copy_avrule_list(avrule_t * l module->map[SYM_CLASSES ][cur_perm->class -1 ];assert (new_perm->class); -if (new_rule-> - specified & (AVRULE_AV |AVRULE_NEVERALLOW )) { +if (new_rule->specified & (AVRULE_AV )) {
Spurious parens.
libsepol/src/expand.c static avtab_ptr_t find_avtab_node(sepol · line 1013
Quoted 10 lines
diff -urpN -x 'Change*' -x entries -x '*.orig' -x '*.rej' -x '*.svn*' -x '*.swp'
trunk/libsepol/src/expand.cbranch/setools_public-policydb-components/libsepol/src/expand.clibsepol/src/expand.c +3
-0@@ -1007,6 +1008,10 @@ static avtab_ptr_t find_avtab_node(sepolreturn node; } +#define EXPAND_RULE_SUCCESS 0 +#define EXPAND_RULE_CONFLICT 1 +#define EXPAND_RULE_ERROR -1
You are switching the current return values, but not all return statements and caller tests appear to have been updated, e.g. expand_rule still returns 1 on a "success" path, and expand_rule_helper still tests for != 1 as an indication of error.
libsepol/src/expand.c int expand_module(sepol_handle_t * handl · line 2049
Quoted 6 lines
libsepol/src/expand.c +1
-1@@ -2033,13 +2046,17 @@ int expand_module(sepol_handle_t * handl/* copy rules */ cur_avrule = decl->avrules;while (cur_avrule !=NULL ) { -if (cur_avrule->specified &AVRULE_NEVERALLOW ) { + if (!(state->expand_neverallow)
This doesn't compile (next patch happens to eliminate it as part of the refactoring, but one would like each patch to leave things in a working state).
libsepol/src/expand.c int expand_module(sepol_handle_t * handl · line 2058
Quoted 9 lines
libsepol/src/expand.c +3
-0+ && cur_avrule->specified & AVRULE_NEVERALLOW) { /* copy this over directly so that assertions are checked later */ if (copy_neverallow (out, state.typemap, cur_avrule)) ERR(handle, "Error while copying neverallow."); } else { +if (cur_avrule->specified &AVRULE_NEVERALLOW ) { + state->out->unsupported_format =1 ;
Ditto.
libsepol/src/expand.c int expand_module(sepol_handle_t * handl · line 2062
Quoted 4 lines
libsepol/src/expand.c +1
-0+ } if (convert_and_expand_rule (state.handle, out, state.typemap, cur_avrule, &out->te_avtab, NULL, NULL,
Ditto.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 5 lines · Joshua Brindle
This is a rebase of the patch sent recently to allow neverallow rules to be put in the avtab. The suggestions including using
policydb->unsupported_formatand adding defined error codes to policydb read and write have been added.
Almost everything looks good to me except:
Quoted 8 lines
libsepol/src/expand.c +2
-1@@ -2033,13 +2046,17 @@ int expand_module(sepol_handle_t * handl/* copy rules */ cur_avrule = decl->avrules;while (cur_avrule !=NULL ) { -if (cur_avrule->specified &AVRULE_NEVERALLOW ) { +if (!(state->expand_neverallow) + && cur_avrule->specified &AVRULE_NEVERALLOW ) {/* copy this over directly so that assertions are checked later */
libsepol/src/expand.c int expand_module(sepol_handle_t * handl · line 2061
Quoted 10 lines
libsepol/src/expand.c +3
-0if (copy_neverallow (out, state.typemap, cur_avrule))ERR (handle,"Error while copying neverallow." ); }else { +if (cur_avrule->specified &AVRULE_NEVERALLOW ) { + state->out->unsupported_format =1 ; + } if (convert_and_expand_rule (state.handle, out, state.typemap,
As I mentioned before, isn't it possible that you would want the expanded and unexpanded neverallow rules? This is a surprising side effect - it at least needs documentation.
libsepol/src/expand.c int expand_module(sepol_handle_t * handl · line 2121
Quoted 11 lines
libsepol/src/expand.c +1
-1cur_avrule, &out->te_avtab, NULL, NULL,@@ -2098,7 +2115,7 @@ int expand_module(sepol_handle_t * handl goto cleanup;hashtab_map_remove_on_error (state.out->p_types.table, type_attr_remove, type_destroy, state.out); -if (check) { +if (check && !(out->unsupported_format)) {if (hierarchy_check_constraints (handle, state.out)) goto cleanup;
I thought that this was going to be removed so that the check would
Quoted 6 lines · happen if requested. You
I guess I can see this, I doubt that someone who requests an
unsupported_formatwould also request checking so the explicit check is
not necessary.
Did I parse this incorrectly?
Karl
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.