Skip to contentSkip to conversation

Add support for UTF-8 in file context specifications

PATCH In review Petr Lautrbach 2 participants 3 messages Sep 4 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 Add support for UTF-8 in file context specifications

Implement support for UTF-8 symbols in file specifications. Strings representing paths are processed as bytes so if users need to use wildcards on non-ascii symbols, they need to put them in pcre groups, e.g. "/opt/žluťou(č)+"

This brings some overhead and so it's possible to disable UTF-8 support build time using DISABLE_UTF=y environment variable.

Fixes:

    # cat unicode.cil
    (filecon "/opt/žluťoučký(/.*)?" any (system_u object_r user_home_t ((s0) (s0))))
    # semodule -i unicode.cil
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts:  line 2145 error due to: Non-ASCII characters found
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts:  line 2145 error due to: Non-ASCII characters found
    /var/lib/selinux/final/targeted/contexts/files/file_contexts: Invalid argument
    libsemanage.semanage_validate_and_compile_fcontexts: setfiles returned error code 1.
    semodule:  Failed!
    # semanage fcontext --add -t user_home_t "/opt/žluťoučký(/.*)?"
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts.local:  line 4 error due to: Non-ASCII characters found
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts.local:  line 4 error due to: Non-ASCII characters found
    /var/lib/selinux/final/targeted/contexts/files/file_contexts: Invalid argument
    libsemanage.semanage_validate_and_compile_fcontexts: setfiles returned error code 1.
    OSError: Error

---
v4 changes

- droped all setlocate()
- droped PCRE2_UTF flag

Tested with semanage fcontext, cil module and with a filename with invalid utf8 symbol:

    # semanage fcontext -a -t user_home_t '/opt/invalid-utf8(/.*)?'
    # restorecon -R -v /opt/invalid-utf8/
    Relabeled /opt/invalid-utf8 from system_u:object_r:usr_t:s0 to system_u:object_r:user_home_t:s0
    Relabeled /opt/invalid-utf8/subdir from system_u:object_r:usr_t:s0 to system_u:object_r:user_home_t:s0
    Relabeled /opt/invalid-utf8/subdir/invalid_�_dir/a from system_u:object_r:usr_t:s0 to system_u:object_r:user_home_t:s0
    Relabeled /opt/invalid-utf8/subdir/�_dir from system_u:object_r:usr_t:s0 to system_u:object_r:user_home_t:s0
    Relabeled /opt/invalid-utf8/subdir/invalid_�_dir from system_u:object_r:usr_t:s0 to system_u:object_r:user_home_t:s0
 libselinux/Makefile                 |  4 ++
 libselinux/src/label_support.c      | 83 +++++++++++++++++++++++++++++
 python/semanage/semanage-fcontext.8 |  1 +
 3 files changed, 88 insertions(+)
libselinux/Makefile +4 -0
index 48c0206a0a4b..aa8d053e359f 100644
@@ -3,6 +3,7 @@ SUBDIRS = include src utils man
 PKG_CONFIG ?= pkg-config
 DISABLE_SETRANS ?= n
 DISABLE_RPM ?= n
+DISABLE_UTF ?= n
 ANDROID_HOST ?= n
 LABEL_BACKEND_ANDROID ?= n
 ifeq ($(ANDROID_HOST),y)
@@ -21,6 +22,9 @@ endif
 ifeq ($(DISABLE_X11),y)
 	DISABLE_FLAGS+= -DNO_X_BACKEND
 endif
+ifeq ($(DISABLE_UTF),y)
+	DISABLE_FLAGS+= -DNO_UTF
+endif
 export DISABLE_SETRANS DISABLE_RPM DISABLE_FLAGS ANDROID_HOST DISABLE_X11 LABEL_BACKEND_ANDROID
 
 USE_PCRE2 ?= y
libselinux/src/label_support.c +83 -0

101 lines not on this page · raw message

python/semanage/semanage-fcontext.8 +1 -0
index b037491e3394..66956440c5c5 100644
@@ -19,6 +19,7 @@ describing fully qualified path(s). The only PCRE flag in use is PCRE2_DOTALL,
 which causes a wildcard '.' to match anything, including a new line.
 Strings representing paths are processed as bytes (as opposed to Unicode),
 meaning that non-ASCII characters are not matched by a single wildcard.
+If you need to match a non-ASCII character with a wildcard, put it in a group, e.g. '(č)*'
 
 Note, that file context definitions specified using 'semanage fcontext'
 (i.e. local file context modifications stored in file_contexts.local)
Signature · 1 line
2.55.0
maintainer Acked-by on v4 1/1
#1 lore raw
Quoted 20 lines · Petr Lautrbach

Implement support for UTF-8 symbols in file specifications. Strings representing paths are processed as bytes so if users need to use wildcards on non-ascii symbols, they need to put them in pcre groups, e.g. "/opt/žluťou(č)+"

This brings some overhead and so it's possible to disable UTF-8 support build time using DISABLE_UTF=y environment variable.

Fixes:

    # cat unicode.cil
    (filecon "/opt/žluťoučký(/.*)?" any (system_u object_r user_home_t ((s0) (s0))))
    # semodule -i unicode.cil
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts:  line 2145 error due to: Non-ASCII characters found
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts:  line 2145 error due to: Non-ASCII characters found
    /var/lib/selinux/final/targeted/contexts/files/file_contexts: Invalid argument
    libsemanage.semanage_validate_and_compile_fcontexts: setfiles returned error code 1.
    semodule:  Failed!
Quoted 8 lines
    # semanage fcontext --add -t user_home_t "/opt/žluťoučký(/.*)?"
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts.local:  line 4 error due to: Non-ASCII characters found
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts.local:  line 4 error due to: Non-ASCII characters found
    /var/lib/selinux/final/targeted/contexts/files/file_contexts: Invalid argument
    libsemanage.semanage_validate_and_compile_fcontexts: setfiles returned error code 1.
    OSError: Error
maintainer
#2 lore raw
Quoted 29 lines · Stephen Smalley
Quoted 27 lines · Petr Lautrbach

Implement support for UTF-8 symbols in file specifications. Strings representing paths are processed as bytes so if users need to use wildcards on non-ascii symbols, they need to put them in pcre groups, e.g. "/opt/žluťou(č)+"

This brings some overhead and so it's possible to disable UTF-8 support build time using DISABLE_UTF=y environment variable.

Fixes:

    # cat unicode.cil
    (filecon "/opt/žluťoučký(/.*)?" any (system_u object_r user_home_t ((s0) (s0))))
    # semodule -i unicode.cil
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts:  line 2145 error due to: Non-ASCII characters found
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts:  line 2145 error due to: Non-ASCII characters found
    /var/lib/selinux/final/targeted/contexts/files/file_contexts: Invalid argument
    libsemanage.semanage_validate_and_compile_fcontexts: setfiles returned error code 1.
    semodule:  Failed!
    # semanage fcontext --add -t user_home_t "/opt/žluťoučký(/.*)?"
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts.local:  line 4 error due to: Non-ASCII characters found
    /sbin/setfiles: /var/lib/selinux/final/targeted/contexts/files/file_contexts.local:  line 4 error due to: Non-ASCII characters found
    /var/lib/selinux/final/targeted/contexts/files/file_contexts: Invalid argument
    libsemanage.semanage_validate_and_compile_fcontexts: setfiles returned error code 1.
    OSError: Error
Quoted 3 lines
Quoted 1 line

Merged.