libsepol: validate conditional type rules have a simple default type
PATCH 1/7 libsepol: validate conditional type rules have a simple default type
Similar to unconditional avtab keys check the default type of type av rules are a simple type, not an attribute.
Since extended permission rules are not allowed in conditional policies this check does not need to be performed.
--- libsepol/src/policydb_validate.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
libsepol/src/policydb_validate.c +11 -4
@@ -885,14 +885,21 @@ static int validate_cond_av_list(sepol_handle_t *handle, const cond_av_list_t *cfor (; cond_av; cond_av = cond_av->next) {for (avtab_ptr = cond_av->node; avtab_ptr; avtab_ptr = avtab_ptr->next) { -if (validate_avtab_key (&avtab_ptr->key,1 , p, flavors)) { -ERR (handle,"Invalid cond av list" ); -return -1 ; - } +const avtab_key_t *key = &avtab_ptr->key; +const avtab_datum_t *datum = &avtab_ptr->datum; + +if (validate_avtab_key (key,1 , p, flavors)) + goto bad; +if ((key->specified &AVTAB_TYPE ) &&validate_simpletype (datum->data, p, flavors)) + goto bad; } }return 0 ; + +bad: +ERR (handle,"Invalid cond av list" ); +return -1 ; }static int validate_avrules (sepol_handle_t *handle,const avrule_t *avrule,int conditional,const policydb_t *p,validate_t flavors[])
Signature · 1 line
2.43.0
PATCH 2/7 libsepol: use correct type to avoid truncations
Avoid truncations of the read 32 bit unsigned integer:
conditional.c:764:8: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 3758096384 (32-bit, unsigned) to type 'int' changed the value to -536870912 (32-bit, signed)
conditional.c:831:8: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4280295456 (32-bit, unsigned) to type 'int' changed the value to -14671840 (32-bit, signed)--- libsepol/src/conditional.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
libsepol/src/conditional.c +4 -4
@@ -746,8 +746,8 @@ static int expr_isvalid(policydb_t * p, cond_expr_t * expr)static int cond_read_node (policydb_t * p,cond_node_t * node,void *fp) { -uint32_t buf[2 ]; -int len, i, rc; +uint32_t buf[2 ], i, len; +int rc;cond_expr_t *expr =NULL , *last =NULL ; rc =next_entry (buf, fp,sizeof (uint32_t ));
@@ -821,8 +821,8 @@ static int cond_read_node(policydb_t * p, cond_node_t * node, void *fp)int cond_read_list (policydb_t * p,cond_list_t ** list,void *fp) {cond_node_t *node, *last =NULL ; -uint32_t buf[1 ]; -int i, len, rc; +uint32_t buf[1 ], i, len; +int rc; rc =next_entry (buf, fp,sizeof (uint32_t ));if (rc <0 )
Signature · 1 line
2.43.0
PATCH 3/7 checkpolicy/dismod: avoid duplicate initialization and fix module linking
In reply to Christian GöttscheAvoid duplicate policydb initialization when reading a kernel policy. One caller, main(), already performs the initialization. The other one, link_module(), needs to do it also for the module policy case.
Also set the target platform to enable module linking.
--- checkpolicy/test/dismod.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
checkpolicy/test/dismod.c +6 -4
@@ -824,10 +824,6 @@ static int read_policy(char *filename, policydb_t * policy, int verbose) package->policy =NULL ;sepol_module_package_free (package); }else { -if (policydb_init (policy)) { -fprintf (stderr,"%s: Out of memory!\n" , __FUNCTION__); -exit (1 ); - } retval =policydb_read (policy, &f, verbose); }fclose (in_fp);
@@ -856,9 +852,15 @@ static void link_module(policydb_t * base, FILE * out_fp, int verbose)return ; } +if (policydb_init (mods)) { +fprintf (stderr,"Out of memory!\n" ); +exit (1 ); + } +/* read the binary policy */ if (verbose)fprintf (out_fp,"Reading module...\n" ); +policydb_set_target_platform (mods, base->target_platform);if (read_policy (module_name, mods, verbose)) { fprintf(stderr, "%s: error(s) encountered while loading policy\n",
Signature · 1 line
2.43.0
PATCH 4/7 checkpolicy/dispol: misc updates
In reply to Christian Göttsche* add option to display users
* drop duplicate option to display booleans
* show number of entries before listing them
* drop global variable
--- checkpolicy/test/dispol.c | 53 +++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 25 deletions(-)
checkpolicy/test/dispol.c +28 -25
@@ -33,9 +33,7 @@#include <stdio.h> #include <fcntl.h> -static policydb_t policydb; - -static struct command { +static const struct command { enum { EOL = 0, HEADER = 1,
@@ -50,7 +48,6 @@ static struct command { {CMD, '2', "display conditional AVTAB (entirely)"}, {CMD, '3', "display conditional AVTAB (only ENABLED rules)"}, {CMD, '4', "display conditional AVTAB (only DISABLED rules)"}, - {CMD, '5', "display conditional bools"}, {CMD, '6', "display conditional expressions"}, {CMD|NOOPT, '7', "change a boolean value"}, {CMD, '8', "display role transitions"},
@@ -58,11 +55,12 @@ static struct command { {CMD, 'c', "display policy capabilities"}, {CMD, 'b', "display booleans"}, {CMD, 'C', "display classes"}, + {CMD, 'u', "display users"}, {CMD, 'r', "display roles"}, {CMD, 't', "display types"}, {CMD, 'a', "display type attributes"}, {CMD, 'p', "display the list of permissive types"}, - {CMD, 'u', "display unknown handling setting"}, + {CMD, 'U', "display unknown handling setting"}, {CMD, 'F', "display filename_trans rules"}, {HEADER, 0, ""}, {CMD|NOOPT, 'f', "set output file"},
@@ -234,17 +232,6 @@ static int display_avtab(avtab_t * a, uint32_t what, policydb_t * p, FILE * fp)return 0 ; } -static int display_bools (policydb_t * p,FILE * fp) -{ -unsigned int i; - -for (i =0 ; i < p->p_bools.nprim; i++) { -fprintf (fp,"%s : %d\n" , p->p_bool_val_to_name[i], - p->bool_val_to_struct[i]->state); - } -return 0 ; -} -static void display_expr (policydb_t * p,cond_expr_t * exp,FILE * fp) {
@@ -313,6 +300,8 @@ static int display_handle_unknown(policydb_t * p, FILE * out_fp)fprintf (out_fp,"Deny unknown classes and permissions\n" ); else if (p->handle_unknown == REJECT_UNKNOWN) fprintf(out_fp, "Reject unknown classes and permissions\n"); + else + fprintf(out_fp, "<INVALID SETTING!>\n");return 0 ; }
@@ -334,7 +323,7 @@ static int display_booleans(policydb_t * p, FILE *fp) {uint32_t i; -fprintf (fp,"booleans:\n" ); +fprintf (fp,"booleans (#%u):\n" , p->p_bools.table->nel);for (i =0 ; i < p->p_bools.nprim; i++) {fprintf (fp,"\t%s : %d\n" , p->p_bool_val_to_name[i], p->bool_val_to_struct[i]->state);
@@ -364,7 +353,7 @@ static int display_classes(policydb_t * p, FILE *fp) {uint32_t i; -fprintf (fp,"classes:\n" ); +fprintf (fp,"classes (#%u):\n" , p->p_classes.table->nel);for (i =0 ; i < p->p_classes.nprim; i++) {if (!p->p_class_val_to_name[i])continue ;
@@ -386,7 +375,7 @@ static void display_permissive(policydb_t *p, FILE *fp)ebitmap_node_t *node;unsigned int i; -fprintf (fp,"permissive sids:\n" ); +fprintf (fp,"permissive sids (#%u):\n" ,ebitmap_cardinality (&p->permissive_map));ebitmap_for_each_positive_bit (&p->permissive_map, node, i) {fprintf (fp,"\t" );display_id (p, fp,SYM_TYPES , i -1 ,"" );
@@ -394,11 +383,25 @@ static void display_permissive(policydb_t *p, FILE *fp) } } +static int display_users (policydb_t * p,FILE *fp) +{ +uint32_t i; + +fprintf (fp,"users (#%u):\n" , p->p_users.table->nel); +for (i =0 ; i < p->p_users.nprim; i++) { +if (!p->p_user_val_to_name[i]) +continue ; + +fprintf (fp,"\t%s\n" , p->p_user_val_to_name[i]); + } +return 0 ; +} +static int display_roles (policydb_t * p,FILE *fp) {uint32_t i; -fprintf (fp,"roles:\n" ); +fprintf (fp,"roles (#%u):\n" , p->p_roles.table->nel);for (i =0 ; i < p->p_roles.nprim; i++) {if (!p->p_role_val_to_name[i])continue ;
@@ -412,7 +415,7 @@ static int display_types(policydb_t * p, FILE *fp) {uint32_t i; -fprintf (fp,"types:\n" ); +fprintf (fp,"types (out of #%u):\n" , p->p_types.table->nel);for (i =0 ; i < p->p_types.nprim; i++) {if (!p->p_type_val_to_name[i])continue ;
@@ -429,7 +432,7 @@ static int display_attributes(policydb_t * p, FILE *fp) {uint32_t i; -fprintf (fp,"attributes:\n" ); +fprintf (fp,"attributes (out of #%u):\n" , p->p_types.table->nel);for (i =0 ; i < p->p_types.nprim; i++) {if (!p->p_type_val_to_name[i])continue ;
@@ -522,6 +525,7 @@ int main(int argc, char **argv)char *name;int state;struct policy_file pf; +policydb_t policydb;if (argc <2 ||strcmp (argv[1 ],"-h" ) ==0 ||strcmp (argv[1 ],"--help" ) ==0 )usage (argv[0 ]);
@@ -616,9 +620,6 @@ int main(int argc, char **argv)display_avtab (&policydb.te_cond_avtab,RENDER_DISABLED , &policydb, out_fp);break ; -case '5' : -display_bools (&policydb, out_fp); -break ;case '6' :display_cond_expressions (&policydb, out_fp);break ;
@@ -678,6 +679,8 @@ int main(int argc, char **argv)display_types (&policydb, out_fp);break ;case 'u' : +display_users (&policydb, out_fp); +break ;case 'U' :display_handle_unknown (&policydb, out_fp);break ;
Signature · 1 line
2.43.0
PATCH 5/7 libsepol: reject invalid class datums
In reply to Christian GöttscheInternally class values are stored in multiple placed in a 16-bit wide integer. Reject class values exceeding the maximum representable value. This avoids truncations in the helper policydb_string_to_security_class(), which gets called before validation of the policy:
policydb.c:4082:9: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 2113929220 (32-bit, unsigned) to type 'sepol_security_class_t' (aka 'unsigned short') changed the value to 4 (16-bit, unsigned)
--- libsepol/src/policydb.c | 2 ++ libsepol/src/policydb_validate.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
libsepol/src/policydb.c +2 -0
@@ -2255,6 +2255,8 @@ static int class_read(policydb_t * p, hashtab_t h, struct policy_file *fp) len2 =le32_to_cpu (buf[1 ]); cladatum->s.value =le32_to_cpu (buf[2 ]); +if (cladatum->s.value >UINT16_MAX ) + goto bad;if (symtab_init (&cladatum->permissions,PERM_SYMTAB_SIZE )) goto bad;
libsepol/src/policydb_validate.c +1 -1
@@ -389,7 +389,7 @@ static int validate_common_datum_wrapper(__attribute__((unused)) hashtab_key_t kstatic int validate_class_datum (sepol_handle_t *handle,const class_datum_t *class,validate_t flavors[]) { -if (validate_value (class->s.value, &flavors[SYM_CLASSES ])) +if (class->s.value >UINT16_MAX ||validate_value (class->s.value, &flavors[SYM_CLASSES ])) goto bad;if (class->comdatum &&validate_common_datum (handle, class->comdatum, flavors)) goto bad;
Signature · 1 line
2.43.0
PATCH 6/7 libsepol/fuzz: handle empty and non kernel policies
In reply to Christian GöttscheDo not check assertions for policies without any av rules.
Only output kernel policies in traditional and CIL format.
Perform hierarchy constraint checks.
Try to link, expand and output base module policies.
Also rework argument passing of verbose flags to improve debugging usability.
--- libsepol/fuzz/binpolicy-fuzzer.c | 53 +++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 8 deletions(-)
libsepol/fuzz/binpolicy-fuzzer.c +45 -8
@@ -1,12 +1,20 @@#include <sepol/debug.h> #include <sepol/kernel_to_cil.h> #include <sepol/kernel_to_conf.h> +#include <sepol/policydb/expand.h> +#include <sepol/policydb/hierarchy.h> +#include <sepol/policydb/link.h> #include <sepol/policydb/policydb.h> extern int policydb_validate (sepol_handle_t *handle,const policydb_t *p);extern int LLVMFuzzerTestOneInput (const uint8_t *data,size_t size); + +// set to 1 to enable more verbose libsepol logging +#define VERBOSE 0 + +static int write_binary_policy (policydb_t *p,FILE *outfp) {struct policy_file pf;
@@ -19,12 +27,12 @@ static int write_binary_policy(policydb_t *p, FILE *outfp)int LLVMFuzzerTestOneInput (const uint8_t *data,size_t size) { -policydb_t policydb = {}; +policydb_t policydb = {}, out = {};sidtab_t sidtab = {};struct policy_file pf;FILE *devnull =NULL ; -sepol_debug (0 ); +sepol_debug (VERBOSE );policy_file_init (&pf); pf.type =PF_USE_MEMORY ;
@@ -34,7 +42,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)if (policydb_init (&policydb)) goto exit; -if (policydb_read (&policydb, &pf,/*verbose=*/ 0 )) +if (policydb_read (&policydb, &pf,VERBOSE )) goto exit;if (policydb_load_isids (&policydb, &sidtab))
@@ -47,7 +55,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)abort (); } - (void )check_assertions (NULL , &policydb, policydb.global->branch_list->avrules); +if (policydb.global->branch_list) + (void )check_assertions (NULL , &policydb, policydb.global->branch_list->avrules); + + (void )hierarchy_check_constraints (NULL , &policydb); devnull =fopen ("/dev/null" ,"we" );if (!devnull)
@@ -56,16 +67,42 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)if (write_binary_policy (&policydb, devnull))abort (); -if (sepol_kernel_policydb_to_conf (devnull, &policydb)) -abort (); +if (policydb.policy_type ==POLICY_KERN ) { +if (sepol_kernel_policydb_to_conf (devnull, &policydb)) +abort (); -if (sepol_kernel_policydb_to_cil (devnull, &policydb)) -abort (); +if (sepol_kernel_policydb_to_cil (devnull, &policydb)) +abort (); + + }else if (policydb.policy_type ==POLICY_BASE ) { +if (link_modules (NULL , &policydb,NULL ,0 ,VERBOSE )) + goto exit; + +if (policydb_init (&out)) + goto exit; + +if (expand_module (NULL , &policydb, &out,VERBOSE ,/*check_assertions=*/ 0 )) + goto exit; + + (void )check_assertions (NULL , &out, out.global->branch_list->avrules); + (void )hierarchy_check_constraints (NULL , &out); + +if (write_binary_policy (&out, devnull)) +abort (); + +if (sepol_kernel_policydb_to_conf (devnull, &out)) +abort (); + +if (sepol_kernel_policydb_to_cil (devnull, &out)) +abort (); + + } exit:if (devnull !=NULL )fclose (devnull); +policydb_destroy (&out);policydb_destroy (&policydb);sepol_sidtab_destroy (&sidtab);
Signature · 1 line
2.43.0
PATCH 7/7 libsepol: reject linking modules with no avrules
In reply to Christian GöttscheStandard policy modules generated by compilers have at least one global av rule. Reject modules otherwise, e.g. generated by a fuzzer.
--- libsepol/src/link.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
libsepol/src/link.c +6 -1
@@ -2019,7 +2019,7 @@ static int debug_requirements(link_state_t * state, policydb_t * p)memset (&req,0 ,sizeof (req));for (cur = p->global; cur !=NULL ; cur = cur->next) { -if (cur->enabled !=NULL ) +if (cur->enabled !=NULL || cur->branch_list ==NULL )continue ; ret =is_decl_requires_met (state, cur->branch_list, &req);
@@ -2142,6 +2142,11 @@ static int enable_avrules(link_state_t * state, policydb_t * pol)/* 1) enable all of the non-else blocks */ for (block = pol->global; block !=NULL ; block = block->next) { block->enabled = block->branch_list; +if (!block->enabled) { +ERR (state->handle,"Global block has no avrules!" ); + ret =SEPOL_ERR ; + goto out; + } block->enabled->enabled =1 ;for (decl = block->branch_list->next; decl !=NULL ; decl = decl->next)
Signature · 1 line
2.43.0
Re: [PATCH 4/7] checkpolicy/dispol: misc updates
In reply to Christian GöttscheQuoted 27 lines · Christian Göttsche
* add option to display users
* drop duplicate option to display booleans
* show number of entries before listing them
* drop global variableSigned-off-by Christian Göttsche <[email protected]>--- checkpolicy/test/dispol.c | 53 +++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 25 deletions(-)checkpolicy/test/dispol.c +1
-3@@ -33,9 +33,7 @@#include <stdio.h> #include <fcntl.h> -static policydb_t policydb; - -static struct command { +static const struct command { enum { EOL = 0, HEADER = 1,
checkpolicy/test/dispol.c static struct command { · line 53
Quoted 4 lines
checkpolicy/test/dispol.c +0
-1@@ -50,7 +48,6 @@ static struct command { {CMD, '2', "display conditional AVTAB (entirely)"}, {CMD, '3', "display conditional AVTAB (only ENABLED rules)"}, {CMD, '4', "display conditional AVTAB (only DISABLED rules)"}, - {CMD, '5', "display conditional bools"},
This command is older than 'b'.
I would like to keep it, but with it saying "display booleans" like below and calling the display_booleans() function like below. If there is something else that would use '5', that would be fine. It just seems weird to skip a number.
Thanks,
Jim
Quoted 147 lines
checkpolicy/test/dispol.c +27
-22{CMD, '6', "display conditional expressions"}, {CMD|NOOPT, '7', "change a boolean value"}, {CMD, '8', "display role transitions"},@@ -58,11 +55,12 @@ static struct command { {CMD, 'c', "display policy capabilities"}, {CMD, 'b', "display booleans"}, {CMD, 'C', "display classes"}, + {CMD, 'u', "display users"}, {CMD, 'r', "display roles"}, {CMD, 't', "display types"}, {CMD, 'a', "display type attributes"}, {CMD, 'p', "display the list of permissive types"}, - {CMD, 'u', "display unknown handling setting"}, + {CMD, 'U', "display unknown handling setting"}, {CMD, 'F', "display filename_trans rules"}, {HEADER, 0, ""}, {CMD|NOOPT, 'f', "set output file"},@@ -234,17 +232,6 @@ static int display_avtab(avtab_t * a, uint32_t what, policydb_t * p, FILE * fp)return 0 ; } -static int display_bools (policydb_t * p,FILE * fp) -{ -unsigned int i; - -for (i =0 ; i < p->p_bools.nprim; i++) { -fprintf (fp,"%s : %d\n" , p->p_bool_val_to_name[i], - p->bool_val_to_struct[i]->state); - } -return 0 ; -} -static void display_expr (policydb_t * p,cond_expr_t * exp,FILE * fp) {@@ -313,6 +300,8 @@ static int display_handle_unknown(policydb_t * p, FILE * out_fp)fprintf (out_fp,"Deny unknown classes and permissions\n" ); else if (p->handle_unknown == REJECT_UNKNOWN) fprintf(out_fp, "Reject unknown classes and permissions\n"); + else + fprintf(out_fp, "<INVALID SETTING!>\n");return 0 ; }@@ -334,7 +323,7 @@ static int display_booleans(policydb_t * p, FILE *fp) {uint32_t i; -fprintf (fp,"booleans:\n" ); +fprintf (fp,"booleans (#%u):\n" , p->p_bools.table->nel);for (i =0 ; i < p->p_bools.nprim; i++) {fprintf (fp,"\t%s : %d\n" , p->p_bool_val_to_name[i], p->bool_val_to_struct[i]->state);@@ -364,7 +353,7 @@ static int display_classes(policydb_t * p, FILE *fp) {uint32_t i; -fprintf (fp,"classes:\n" ); +fprintf (fp,"classes (#%u):\n" , p->p_classes.table->nel);for (i =0 ; i < p->p_classes.nprim; i++) {if (!p->p_class_val_to_name[i])continue ;@@ -386,7 +375,7 @@ static void display_permissive(policydb_t *p, FILE *fp)ebitmap_node_t *node;unsigned int i; -fprintf (fp,"permissive sids:\n" ); +fprintf (fp,"permissive sids (#%u):\n" ,ebitmap_cardinality (&p->permissive_map));ebitmap_for_each_positive_bit (&p->permissive_map, node, i) {fprintf (fp,"\t" );display_id (p, fp,SYM_TYPES , i -1 ,"" );@@ -394,11 +383,25 @@ static void display_permissive(policydb_t *p, FILE *fp) } } +static int display_users (policydb_t * p,FILE *fp) +{ +uint32_t i; + +fprintf (fp,"users (#%u):\n" , p->p_users.table->nel); +for (i =0 ; i < p->p_users.nprim; i++) { +if (!p->p_user_val_to_name[i]) +continue ; + +fprintf (fp,"\t%s\n" , p->p_user_val_to_name[i]); + } +return 0 ; +} +static int display_roles (policydb_t * p,FILE *fp) {uint32_t i; -fprintf (fp,"roles:\n" ); +fprintf (fp,"roles (#%u):\n" , p->p_roles.table->nel);for (i =0 ; i < p->p_roles.nprim; i++) {if (!p->p_role_val_to_name[i])continue ;@@ -412,7 +415,7 @@ static int display_types(policydb_t * p, FILE *fp) {uint32_t i; -fprintf (fp,"types:\n" ); +fprintf (fp,"types (out of #%u):\n" , p->p_types.table->nel);for (i =0 ; i < p->p_types.nprim; i++) {if (!p->p_type_val_to_name[i])continue ;@@ -429,7 +432,7 @@ static int display_attributes(policydb_t * p, FILE *fp) {uint32_t i; -fprintf (fp,"attributes:\n" ); +fprintf (fp,"attributes (out of #%u):\n" , p->p_types.table->nel);for (i =0 ; i < p->p_types.nprim; i++) {if (!p->p_type_val_to_name[i])continue ;@@ -522,6 +525,7 @@ int main(int argc, char **argv)char *name;int state;struct policy_file pf; +policydb_t policydb;if (argc <2 ||strcmp (argv[1 ],"-h" ) ==0 ||strcmp (argv[1 ],"--help" ) ==0 )usage (argv[0 ]);@@ -616,9 +620,6 @@ int main(int argc, char **argv)display_avtab (&policydb.te_cond_avtab,RENDER_DISABLED , &policydb, out_fp);break ; -case '5' : -display_bools (&policydb, out_fp); -break ;case '6' :display_cond_expressions (&policydb, out_fp);break ;@@ -678,6 +679,8 @@ int main(int argc, char **argv)display_types (&policydb, out_fp);break ;case 'u' : +display_users (&policydb, out_fp); +break ;case 'U' :display_handle_unknown (&policydb, out_fp);break ; --2.43.0
Quoted 7 lines · Christian Göttsche
Similar to unconditional avtab keys check the default type of type av rules are a simple type, not an attribute.
Since extended permission rules are not allowed in conditional policies this check does not need to be performed.Signed-off-by Christian Göttsche <[email protected]>
For every patch except for patch 4.
Quoted 38 lines
--- libsepol/src/policydb_validate.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)libsepol/src/policydb_validate.c +11
-5@@ -885,14 +885,21 @@ static int validate_cond_av_list(sepol_handle_t *handle, const cond_av_list_t *cfor (; cond_av; cond_av = cond_av->next) {for (avtab_ptr = cond_av->node; avtab_ptr; avtab_ptr = avtab_ptr->next) { -if (validate_avtab_key (&avtab_ptr->key,1 , p, flavors)) { -ERR (handle,"Invalid cond av list" ); -return -1 ; - } +const avtab_key_t *key = &avtab_ptr->key; +const avtab_datum_t *datum = &avtab_ptr->datum; + +if (validate_avtab_key (key,1 , p, flavors)) + goto bad; +if ((key->specified &AVTAB_TYPE ) &&validate_simpletype (datum->data, p, flavors)) + goto bad; } }return 0 ; + +bad: +ERR (handle,"Invalid cond av list" ); +return -1 ; }static int validate_avrules (sepol_handle_t *handle,const avrule_t *avrule,int conditional,const policydb_t *p,validate_t flavors[]) --2.43.0
Quoted 9 lines · James Carter
Quoted 6 lines · Christian Göttsche
Similar to unconditional avtab keys check the default type of type av rules are a simple type, not an attribute.
Since extended permission rules are not allowed in conditional policies this check does not need to be performed.
Quoted 5 lines
Quoted 1 line
Signed-off-by Christian Göttsche <[email protected]>For every patch except for patch 4.
Acked-by James Carter <[email protected]>
Patches 1-3 and 5-7 have been merged.
Thanks,
Jim
Quoted 38 lines
Quoted 38 lines
--- libsepol/src/policydb_validate.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)libsepol/src/policydb_validate.c +11
-5@@ -885,14 +885,21 @@ static int validate_cond_av_list(sepol_handle_t *handle, const cond_av_list_t *cfor (; cond_av; cond_av = cond_av->next) {for (avtab_ptr = cond_av->node; avtab_ptr; avtab_ptr = avtab_ptr->next) { -if (validate_avtab_key (&avtab_ptr->key,1 , p, flavors)) { -ERR (handle,"Invalid cond av list" ); -return -1 ; - } +const avtab_key_t *key = &avtab_ptr->key; +const avtab_datum_t *datum = &avtab_ptr->datum; + +if (validate_avtab_key (key,1 , p, flavors)) + goto bad; +if ((key->specified &AVTAB_TYPE ) &&validate_simpletype (datum->data, p, flavors)) + goto bad; } }return 0 ; + +bad: +ERR (handle,"Invalid cond av list" ); +return -1 ; }static int validate_avrules (sepol_handle_t *handle,const avrule_t *avrule,int conditional,const policydb_t *p,validate_t flavors[]) --2.43.0