Disallow overlap of local port ranges
Hi, this patch disallows overlapping port ranges in the local store, in the form of a commit validate run, where the ports are sorted and tested for overlap. The patch will not allow any kind of overlap, not just complete shadow. This was a feature requested by Joshua, since relying on the add() order for precedence seemed non-intuitive. Also, I'm not sure how useful overlapping ranges are to the local store - they seem more useful in the base policy where you want to set a default range of ports.
Overlap is still allowed in base policy, and local ranges are allowed to overlap (and shadow) base as well - they always take precedence.
=========
There is another problem related to ports, which is harder to solve - we want to remove the ordering significance of list() and iterate() - they should not show overlapping ranges (those still exist, because of the overlaps with policy). An example of why this is a problem is Dan's latest version of the semanage tool - it's in rawhide, but not upstreamed yet. He alphabetizes the ports by context, which does not provide any clue about order and precedence to the user (and I'm not sure the user should care about those things anyway - it seems reasonable to hide overlaps ). The tool shows 1-1023 as reserved, and ports displayed both below and above that are in the same (reserved) range, which seems confusing to me. Not sure how to resolve this problem...
libsemanage/src/direct_api.c +10 -2
@@ -382,7 +382,8 @@ static int semanage_direct_commit(semanasepol_policydb_t * out =NULL ;/* Declare some variables */ -int modified, fcontexts_modified, seusers_modified, users_extra_modified; +int modified, fcontexts_modified, ports_modified, + seusers_modified, users_extra_modified;dbase_config_t * users =semanage_user_dbase_local (sh);dbase_config_t * users_base =semanage_user_base_dbase_local (sh);dbase_config_t * users_extra =semanage_user_extra_dbase_local (sh);
@@ -403,10 +404,11 @@ static int semanage_direct_commit(semana fcontexts_modified = fcontexts->dtable->is_modified (fcontexts->dbase); seusers_modified = seusers->dtable->is_modified (seusers->dbase); users_extra_modified = users_extra->dtable->is_modified (users_extra->dbase); + ports_modified = ports->dtable->is_modified (ports->dbase); modified = sh->modules_modified; + modified |= ports_modified; modified |= users->dtable->is_modified (users_base->dbase); - modified |= ports->dtable->is_modified (ports->dbase); modified |= bools->dtable->is_modified (bools->dbase); modified |= ifaces->dtable->is_modified (ifaces->dbase);
@@ -479,6 +481,12 @@ static int semanage_direct_commit(semana goto cleanup; } +/* Validate local ports for overlap */ +if (sh->do_rebuild || ports_modified) { +if (semanage_port_validate_local (sh) <0 ) + goto cleanup; + } +/* Commit changes to components */ if (semanage_commit_components (sh) <0 ) goto cleanup;
libsemanage/src/port_internal.h +9 -0
@@ -42,4 +42,13 @@ extern int port_policydb_dbase_init(extern void port_policydb_dbase_release (dbase_config_t * dconfig); +extern int hidden semanage_port_validate_local( +semanage_handle_t * handle); + +/* ==== Internal (to ports) API === */ + +hidden int semanage_port_compare2_qsort( +const semanage_port_t ** port, +const semanage_port_t ** port2); +#endif
libsemanage/src/port_record.c +1 -1
@@ -40,7 +40,7 @@ int semanage_port_compare2( }hidden_def (semanage_port_compare2) -static int semanage_port_compare2_qsort( +hidden int semanage_port_compare2_qsort(const semanage_port_t ** port,const semanage_port_t ** port2) {
libsemanage/src/ports_local.c +72 -2
88 lines not on this page · raw message
Quoted 8 lines · Ivan Gyurdiev
Hi, this patch disallows overlapping port ranges in the local store, in the form of a commit validate run, where the ports are sorted and tested for overlap. The patch will not allow any kind of overlap, not just complete shadow. This was a feature requested by Joshua, since relying on the
add()order for precedence seemed non-intuitive. Also, I'm not sure how useful overlapping ranges are to the local store - they seem more useful in the base policy where you want to set a default range of ports.
Merged as of libsemanage 1.5.14.
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.