Skip to contentSkip to conversation

libsepol: restore basic validation for path/component names

PATCH In review Stephen Smalley 1 participant 2 messages Sep 10 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 libsepol: restore basic validation for path/component names

Commit 2360a8a12b99 ("libsepol: do not reject control characters in pathnames") dropped the validate_string_field() calls for path/component names because validate_string_field() prohibits control characters which are legal in pathnames. Commit 069ccd7a497b ("libsepol: validate genfs_seclabel_wildcard paths") restored basic validation for genfscon paths by checking that they are not NULL or the empty string as well as further validating that they end in a wildcard ("*") if the genfs_seclabel_wildcard policy capability is enabled. Restore basic validation for the other two path/component names to ensure that they also are not NULL or the empty string. Further path and component name validation is of course possible but if we added it, we would want to make it consistently enforced by the compiler frontends as well.

---
 libsepol/src/policydb_validate.c | 4 ++++
 1 file changed, 4 insertions(+)
libsepol/src/policydb_validate.c +4 -0
index 8fe168f6..5b14b244 100644
@@ -1521,6 +1521,8 @@ static int validate_filename_trans(hashtab_key_t k, hashtab_datum_t d,
 		goto bad;
 	if (validate_value(ftk->tclass, &flavors[SYM_CLASSES]))
 		goto bad;
+	if (!ftk->name || !ftk->name[0])
+		goto bad;
 	if (!ftd)
 		goto bad;
 	for (; ftd; ftd = ftd->next) {
@@ -1880,6 +1882,8 @@ validate_filename_trans_rules(sepol_handle_t *handle,
 			goto bad;
 		if (validate_simpletype(filename_trans->otype, p, flavors))
 			goto bad;
+		if (!filename_trans->name || !filename_trans->name[0])
+			goto bad;
 
 		/* currently only the RULE_SELF flag can be set */
 		switch (filename_trans->flags) {
Signature · 1 line
2.55.0
author maintainer
#1 lore raw
Quoted 15 lines · Stephen Smalley

Commit 2360a8a12b99 ("libsepol: do not reject control characters in pathnames") dropped the validate_string_field() calls for path/component names because validate_string_field() prohibits control characters which are legal in pathnames. Commit 069ccd7a497b ("libsepol: validate genfs_seclabel_wildcard paths") restored basic validation for genfscon paths by checking that they are not NULL or the empty string as well as further validating that they end in a wildcard ("*") if the genfs_seclabel_wildcard policy capability is enabled. Restore basic validation for the other two path/component names to ensure that they also are not NULL or the empty string. Further path and component name validation is of course possible but if we added it, we would want to make it consistently enforced by the compiler frontends as well.

Quoted 1 line

This has been merged.