libsepol,checkpolicy: validate devicetree paths
Stephen Smalley
maintainerPATCH v2 1/1 libsepol,checkpolicy: validate devicetree paths
devicetreecon paths have their own validity rules specified by:
https://devicetree-specification.readthedocs.io/en/latest/index.html
libsepol was (correctly) preventing them from embedding control characters but checkpolicy was not. Provide helpers for validating devicetree paths according to the specification and use them in checkpolicy and libsepol to reject invalid devicetree paths.
Signed-off-by Stephen Smalley <[email protected]>
---
v2 fixes an error in the validation logic.
checkpolicy/policy_define.c | 20 +++-- libsepol/include/sepol/policydb/dtpath.h | 96 ++++++++++++++++++++++++ libsepol/src/policydb_validate.c | 3 +- 3 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 libsepol/include/sepol/policydb/dtpath.h
checkpolicy/policy_define.c +15 -5
@@ -54,6 +54,7 @@#include <sepol/policydb/conditional.h> #include <sepol/policydb/hierarchy.h> #include <sepol/policydb/polcaps.h> +#include <sepol/policydb/dtpath.h> #include "queue.h" #include "module_compiler.h" #include "policy_define.h"
@@ -5136,6 +5137,7 @@ bad:int define_devicetree_context (void ) {ocontext_t *newc, *c, *l, *head; +char *path;if (policydbp->target_platform !=SEPOL_TARGET_XEN ) {yyerror ("devicetreecon not supported for target" );
@@ -5148,17 +5150,25 @@ int define_devicetree_context(void)return 0 ; } + path = (char *)queue_remove (id_queue); +if (!path) { +yyerror ("Missing devicetreepath" ); +return -1 ; + } + +if (!is_valid_dt_path (path)) { +yyerror2 ("invalid devicetreecon path \"%s\"" , path); +free (path); +return -1 ; + } + newc =calloc (1 ,sizeof (ocontext_t));if (!newc) {yyerror ("out of memory" );return -1 ; } - newc->u.name = (char *)queue_remove (id_queue); -if (!newc->u.name) { -free (newc); -return -1 ; - } + newc->u.name = path;if (parse_security_context (&newc->context[0 ])) {free (newc->u.name);
libsepol/include/sepol/policydb/dtpath.h new file +96 -0
96 lines not on this page · raw message
libsepol/src/policydb_validate.c +2 -1
@@ -5,6 +5,7 @@#include <sepol/policydb/polcaps.h> #include <sepol/policydb/policydb.h> #include <sepol/policydb/services.h> +#include <sepol/policydb/dtpath.h> #include "debug.h" #include "private.h"
@@ -1613,7 +1614,7 @@ static int validate_ocontexts(sepol_handle_t *handle, const policydb_t *p, goto bad;break ;case OCON_XEN_DEVICETREE : -if (validate_string_field (octx->u.name)) +if (!is_valid_dt_path (octx->u.name)) goto bad;break ; }
Signature · 1 line
2.55.0