lib: strip enclosing quotes from fsconfig option values

With the old mount(2) syscall, the kernel's SELinux code
(selinux_sb_eat_lsm_opts) internally strips double quotes from context
option values like context="system_u:object_r:root_t:s0". However, with
the new fsconfig() API the value is passed through verbatim, causing
SELinux to reject the mount with ENODEV.

Strip enclosing double quotes from key=value option values in
apply_opt_key_value() before passing them to fsconfig().

Signed-off-by: Jingbo Xu <jingbo.xu@linux.alibaba.com>
This commit is contained in:
Jingbo Xu
2026-06-16 10:05:42 +08:00
committed by Bernd Schubert
parent 1a3cc241e9
commit 24d40b2a7c
+14 -1
View File
@@ -207,7 +207,8 @@ static int apply_opt_key_value(int fsfd, char *opt)
{
char *eq;
const char *key;
const char *value;
char *value;
size_t len;
eq = strchr(opt, '=');
if (!eq)
@@ -217,6 +218,18 @@ static int apply_opt_key_value(int fsfd, char *opt)
key = opt;
value = eq + 1;
/*
* Strip enclosing double quotes from the value, e.g.
* context="system_u:object_r:root_t:s0". The old mount(2) path relied
* on the kernel (selinux_sb_eat_lsm_opts) to strip these, but
* fsconfig() passes the value through as-is.
*/
len = strlen(value);
if (len >= 2 && value[0] == '"' && value[len - 1] == '"') {
value[len - 1] = '\0';
value++;
}
if (strcmp(key, "fd") == 0)
return apply_fsconfig_opt_fd(fsfd, value);