libsepol: validate some object contexts
PATCH 1/5 libsepol: validate some object contexts
Ensure various object context entries have a name, since they are duplicated via strdup(3), and the order for ports and memory regions is valid.
--- libsepol/src/policydb_validate.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
libsepol/src/policydb_validate.c +30 -0
@@ -1149,6 +1149,8 @@ static int validate_ocontexts(sepol_handle_t *handle, const policydb_t *p, validcase OCON_NETIF :if (validate_context (&octx->context[1 ], flavors, p->mls)) goto bad; +if (!octx->u.name) + goto bad;break ;case OCON_PORT :if (octx->u.port.low_port > octx->u.port.high_port)
@@ -1163,6 +1165,34 @@ static int validate_ocontexts(sepol_handle_t *handle, const policydb_t *p, validdefault : goto bad; } +if (!octx->u.name) + goto bad; +break ; +case OCON_IBPKEY : +if (octx->u.ibpkey.low_pkey > octx->u.ibpkey.high_pkey) + goto bad; +break ; +case OCON_IBENDPORT : +if (!octx->u.ibendport.dev_name) + goto bad; +break ; + } + }else if (p->target_platform ==SEPOL_TARGET_XEN ) { +switch (i) { +case OCON_XEN_IOPORT : +if (octx->u.ioport.low_ioport > octx->u.ioport.high_ioport) + goto bad; +break ; +case OCON_XEN_IOMEM : +if (octx->u.iomem.low_iomem > octx->u.iomem.high_iomem) + goto bad; +if (p->policyvers <POLICYDB_VERSION_XEN_DEVICETREE && octx->u.iomem.high_iomem >0xFFFFFFFFULL ) + goto bad; +break ; +case OCON_XEN_DEVICETREE : +if (!octx->u.name) + goto bad; +break ; } } }
Signature · 1 line
2.40.1
PATCH 2/5 libsepol: validate old style range trans classes
For old style range transition rules the class defaults to process. However the policy might not declare the process class leading to setting a wrong bit later on via:
if (ebitmap_set_bit(&rtr->tclasses, rt->target_class - 1, 1))
UBSAN report:
policydb.c:3684:56: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'uint32_t' (aka 'unsigned int')
--- libsepol/src/policydb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libsepol/src/policydb.c +2 -2
@@ -3650,10 +3650,10 @@ static int range_read(policydb_t * p, struct policy_file *fp)if (rc <0 ) goto err; rt->target_class =le32_to_cpu (buf[0 ]); -if (!value_isvalid (rt->target_class, p->p_classes.nprim)) - goto err; }else rt->target_class = p->process_class; +if (!value_isvalid (rt->target_class, p->p_classes.nprim)) + goto err; r =calloc (1 ,sizeof (*r));if (!r) goto err;
Signature · 1 line
2.40.1
PATCH 3/5 libsepol: validate: check low category is not bigger than high
In reply to Christian Göttsche--- libsepol/src/policydb_validate.c | 2 ++ 1 file changed, 2 insertions(+)
libsepol/src/policydb_validate.c +2 -0
@@ -545,6 +545,8 @@ static int validate_mls_semantic_cat(const mls_semantic_cat_t *cat, const valida goto bad;if (validate_value (cat->high, cats)) goto bad; +if (cat->low > cat->high) + goto bad; }return 0 ;
Signature · 1 line
2.40.1
PATCH 4/5 libsepol: validate: reject XEN policy with xperm rules
In reply to Christian GöttscheXEN policies with extended permissions are not supported, e.g. writing them will fail (see write.c:avrule_write()).
--- libsepol/src/policydb_validate.c | 4 ++++ 1 file changed, 4 insertions(+)
libsepol/src/policydb_validate.c +4 -0
@@ -799,6 +799,8 @@ static int validate_avtab_key(const avtab_key_t *key, int conditional, const polcase AVTAB_XPERMS_ALLOWED :case AVTAB_XPERMS_AUDITALLOW :case AVTAB_XPERMS_DONTAUDIT : +if (p->target_platform !=SEPOL_TARGET_SELINUX ) + goto bad;if (conditional) goto bad;break ;
@@ -910,6 +912,8 @@ static int validate_avrules(sepol_handle_t *handle, const avrule_t *avrule, int }if (avrule->specified &AVRULE_XPERMS ) { +if (p->target_platform !=SEPOL_TARGET_SELINUX ) + goto bad;if (!avrule->xperms) goto bad;switch (avrule->xperms->specified) {
Signature · 1 line
2.40.1
PATCH 5/5 libsepol: expand: skip invalid cat
In reply to Christian GöttscheBail out on expanding levels with invalid low category.
UBSAN report:
expand.c:952:21: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'uint32_t' (aka 'unsigned int')
--- libsepol/src/expand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/expand.c +1 -1
@@ -943,7 +943,7 @@ int mls_semantic_level_expand(mls_semantic_level_t * sl, mls_level_t * l,return -1 ; }for (cat = sl->cat; cat; cat = cat->next) { -if (cat->low > cat->high) { +if (!cat->low || cat->low > cat->high) {ERR (h,"Category range is not valid %s.%s" , p->p_cat_val_to_name[cat->low -1 ], p->p_cat_val_to_name[cat->high -1 ]);
Signature · 1 line
2.40.1
Quoted 6 lines · Christian Göttsche
Ensure various object context entries have a name, since they are duplicated via strdup(3), and the order for ports and memory regions is valid.
Signed-off-by Christian Göttsche <[email protected]>
For these five patches:
Quoted 55 lines
--- libsepol/src/policydb_validate.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)libsepol/src/policydb_validate.c +30
-1@@ -1149,6 +1149,8 @@ static int validate_ocontexts(sepol_handle_t *handle, const policydb_t *p, validcase OCON_NETIF :if (validate_context (&octx->context[1 ], flavors, p->mls)) goto bad; +if (!octx->u.name) + goto bad;break ;case OCON_PORT :if (octx->u.port.low_port > octx->u.port.high_port)@@ -1163,6 +1165,34 @@ static int validate_ocontexts(sepol_handle_t *handle, const policydb_t *p, validdefault : goto bad; } +if (!octx->u.name) + goto bad; +break ; +case OCON_IBPKEY : +if (octx->u.ibpkey.low_pkey > octx->u.ibpkey.high_pkey) + goto bad; +break ; +case OCON_IBENDPORT : +if (!octx->u.ibendport.dev_name) + goto bad; +break ; + } + }else if (p->target_platform ==SEPOL_TARGET_XEN ) { +switch (i) { +case OCON_XEN_IOPORT : +if (octx->u.ioport.low_ioport > octx->u.ioport.high_ioport) + goto bad; +break ; +case OCON_XEN_IOMEM : +if (octx->u.iomem.low_iomem > octx->u.iomem.high_iomem) + goto bad; +if (p->policyvers <POLICYDB_VERSION_XEN_DEVICETREE && octx->u.iomem.high_iomem >0xFFFFFFFFULL ) + goto bad; +break ; +case OCON_XEN_DEVICETREE : +if (!octx->u.name) + goto bad; +break ; } } } --2.40.1
Quoted 4 lines · James Carter
Quoted 1 line · Christian Göttsche
Quoted 9 lines
Quoted 5 lines
Ensure various object context entries have a name, since they are duplicated via strdup(3), and the order for ports and memory regions is valid.
Signed-off-by Christian Göttsche <[email protected]>For these five patches:
Acked-by James Carter <[email protected]>
These five patches have been merged.
Thanks,
Jim
Quoted 55 lines
Quoted 55 lines
--- libsepol/src/policydb_validate.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)libsepol/src/policydb_validate.c +30
-1@@ -1149,6 +1149,8 @@ static int validate_ocontexts(sepol_handle_t *handle, const policydb_t *p, validcase OCON_NETIF :if (validate_context (&octx->context[1 ], flavors, p->mls)) goto bad; +if (!octx->u.name) + goto bad;break ;case OCON_PORT :if (octx->u.port.low_port > octx->u.port.high_port)@@ -1163,6 +1165,34 @@ static int validate_ocontexts(sepol_handle_t *handle, const policydb_t *p, validdefault : goto bad; } +if (!octx->u.name) + goto bad; +break ; +case OCON_IBPKEY : +if (octx->u.ibpkey.low_pkey > octx->u.ibpkey.high_pkey) + goto bad; +break ; +case OCON_IBENDPORT : +if (!octx->u.ibendport.dev_name) + goto bad; +break ; + } + }else if (p->target_platform ==SEPOL_TARGET_XEN ) { +switch (i) { +case OCON_XEN_IOPORT : +if (octx->u.ioport.low_ioport > octx->u.ioport.high_ioport) + goto bad; +break ; +case OCON_XEN_IOMEM : +if (octx->u.iomem.low_iomem > octx->u.iomem.high_iomem) + goto bad; +if (p->policyvers <POLICYDB_VERSION_XEN_DEVICETREE && octx->u.iomem.high_iomem >0xFFFFFFFFULL ) + goto bad; +break ; +case OCON_XEN_DEVICETREE : +if (!octx->u.name) + goto bad; +break ; } } } --2.40.1