Skip to contentSkip to conversation

Add module_load permission to self when loading modules is allowed

PATCH New Nicolas Iooss 4 participants 5 messages Aug 8, 2017 – Aug 10, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add module_load permission to self when loading modules is allowed

When a program uses init_module() to load a module, the kernel checks for system:load_module permission in the process type [1]. For example when systemd loads ip_tables modules (since
https://github.com/systemd/systemd/commit/1d3087978a8ee23107cb64aa55ca97aefe9531e2),
the following AVC denial gets reported:

avc: denied { module_load } for pid=1 comm="systemd" scontext=system_u:system_r:init_t tcontext=system_u:system_r:init_t tclass=system permissive=1

[1] The relevant kernel code is selinux_kernel_module_from_file() in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/security/selinux/hooks.c?h=v4.11#n3836

    /* init_module */
    if (file == NULL)
        return avc_has_perm(sid, sid, SECCLASS_SYSTEM,
                    SYSTEM__MODULE_LOAD, NULL);

In this code, both source and target SIDs are current_sid().

---
 policy/modules/kernel/kernel.te | 1 +
 1 file changed, 1 insertion(+)
policy/modules/kernel/kernel.te +1 -0
index 424a4b511262..e2d3073b4260 100644
@@ -474,6 +474,7 @@ optional_policy(`
 
 if( ! secure_mode_insmod ) {
 	allow can_load_kernmodule self:capability sys_module;
+	allow can_load_kernmodule self:system module_load;
 
 	files_load_kernel_modules(can_load_kernmodule)
 
Signature · 1 line
2.13.4
#1 lore raw

PATCH v2 1/1 Add module_load permission to self when loading modules is allowed

Quoted 28 lines · Nicolas Iooss via refpolicy

When a program uses init_module() to load a module, the kernel checks for system:load_module permission in the process type [1]. For example when systemd loads ip_tables modules (since
https://github.com/systemd/systemd/commit/1d3087978a8ee23107cb64aa55ca97aefe9531e2),
the following AVC denial gets reported:

avc: denied { module_load } for pid=1 comm="systemd" scontext=system_u:system_r:init_t tcontext=system_u:system_r:init_t tclass=system permissive=1

[1] The relevant kernel code is selinux_kernel_module_from_file() in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/security/selinux/hooks.c?h=v4.11#n3836

    /* init_module */
    if (file == NULL)
        return avc_has_perm(sid, sid, SECCLASS_SYSTEM,
                    SYSTEM__MODULE_LOAD, NULL);

In this code, both source and target SIDs are current_sid().

---
 policy/modules/kernel/kernel.te | 1 +
 1 file changed, 1 insertion(+)
policy/modules/kernel/kernel.te +0 -0
index 424a4b511262..e2d3073b4260 100644

policy/modules/kernel/kernel.te optional_policy(` · line 479

Quoted 6 lines
policy/modules/kernel/kernel.te +1 -0
@@ -474,6 +474,7 @@ optional_policy(`
 
 if( ! secure_mode_insmod ) {
 	allow can_load_kernmodule self:capability sys_module;
+	allow can_load_kernmodule self:system module_load;
 
 	files_load_kernel_modules(can_load_kernmodule)

Merged.

Signature · 1 line
Chris PeBenito
#2 lore raw

PATCH v2 1/1 Add module_load permission to self when loading modules is allowed

Quoted 36 lines · Chris PeBenito via refpolicy
Quoted 35 lines · Nicolas Iooss via refpolicy

When a program uses init_module() to load a module, the kernel checks
for system:load_module permission in the process type [1]. For example when systemd loads ip_tables modules (since
https://github.com/systemd/systemd/commit/1d3087978a8ee23107cb64aa5
5ca97aefe9531e2),
the following AVC denial gets reported:

avc: denied { module_load } for pid=1 comm="systemd" scontext=system_u:system_r:init_t
tcontext=system_u:system_r:init_t
tclass=system permissive=1

[1] The relevant kernel code is selinux_kernel_module_from_file() in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
tree/security/selinux/hooks.c?h=v4.11#n3836

    /* init_module */
    if (file == NULL)
        return avc_has_perm(sid, sid, SECCLASS_SYSTEM,
                    SYSTEM__MODULE_LOAD, NULL);

In this code, both source and target SIDs are current_sid().

---
 policy/modules/kernel/kernel.te | 1 +
 1 file changed, 1 insertion(+)
policy/modules/kernel/kernel.te +0 -0
index 424a4b511262..e2d3073b4260 100644
@@ -474,6 +474,7 @@ optional_policy(`
 
Quoted 7 lines

policy/modules/kernel/kernel.te optional_policy(` · line 479

Quoted 5 lines
policy/modules/kernel/kernel.te +1 -0
 if( ! secure_mode_insmod ) {
 	allow can_load_kernmodule self:capability sys_module;
+	allow can_load_kernmodule self:system module_load;
 
 	files_load_kernel_modules(can_load_kernmodule)

Merged.

Hello.

Sorry for my late reply...

I believe this only applies to systemd.

So, is there any reason why it hasn't been enclosed in the appropriate ifdef(init_systemd) ?

Regards,

Guido

#3 lore raw

PATCH v2 1/1 Add module_load permission to self when loading modules is allowed

Quoted 46 lines · Guido Trentalancia via refpolicy
Quoted 36 lines · Chris PeBenito via refpolicy
Quoted 35 lines · Nicolas Iooss via refpolicy

When a program uses init_module() to load a module, the kernel checks
for system:load_module permission in the process type [1]. For example when systemd loads ip_tables modules (since
https://github.com/systemd/systemd/commit/1d3087978a8ee23107cb64aa5
5ca97aefe9531e2),
the following AVC denial gets reported:

avc: denied { module_load } for pid=1 comm="systemd" scontext=system_u:system_r:init_t
tcontext=system_u:system_r:init_t
tclass=system permissive=1

[1] The relevant kernel code is selinux_kernel_module_from_file() in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
tree/security/selinux/hooks.c?h=v4.11#n3836

    /* init_module */
    if (file == NULL)
        return avc_has_perm(sid, sid, SECCLASS_SYSTEM,
                    SYSTEM__MODULE_LOAD, NULL);

In this code, both source and target SIDs are current_sid().

---
 policy/modules/kernel/kernel.te | 1 +
 1 file changed, 1 insertion(+)
policy/modules/kernel/kernel.te +0 -0
index 424a4b511262..e2d3073b4260 100644
@@ -474,6 +474,7 @@ optional_policy(`
 
Quoted 7 lines

policy/modules/kernel/kernel.te optional_policy(` · line 479

Quoted 5 lines
policy/modules/kernel/kernel.te +1 -0
 if( ! secure_mode_insmod ) {
 	allow can_load_kernmodule self:capability sys_module;
+	allow can_load_kernmodule self:system module_load;
 
 	files_load_kernel_modules(can_load_kernmodule)

Merged.

Quoted 5 lines

Hello.

Sorry for my late reply...

I believe this only applies to systemd.

It doesnt. it applies to systems that have kernel modules compressed.

Quoted 11 lines

So, is there any reason why it hasn't been enclosed in the appropriate ifdef(init_systemd) ?

Regards,

Guido
_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com
http://oss.tresys.com/mailman/listinfo/refpolicy

Signature · 10 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8  02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20170810/4916011b/attachment.bin 
#4 lore raw

PATCH v2 1/1 Add module_load permission to self when loading modules is allowed

Hello and thanks for getting back.

Quoted 51 lines · Dominick Grift via refpolicy
Quoted 49 lines · Guido Trentalancia via refpolicy
Quoted 46 lines · Chris PeBenito via refpolicy
Quoted 37 lines · Nicolas Iooss via refpolicy

When a program uses init_module() to load a module, the kernel checks
for system:load_module permission in the process type [1]. For example when systemd loads ip_tables modules (since
https://github.com/systemd/systemd/commit/1d3087978a8ee23107cb6
4aa5
5ca97aefe9531e2),
the following AVC denial gets reported:

avc: denied { module_load } for pid=1 comm="systemd" scontext=system_u:system_r:init_t
tcontext=system_u:system_r:init_t
tclass=system permissive=1

[1] The relevant kernel code is
selinux_kernel_module_from_file()
in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.
git/
tree/security/selinux/hooks.c?h=v4.11#n3836

    /* init_module */
    if (file == NULL)
        return avc_has_perm(sid, sid, SECCLASS_SYSTEM,
                    SYSTEM__MODULE_LOAD, NULL);

In this code, both source and target SIDs are current_sid().

---
 policy/modules/kernel/kernel.te | 1 +
 1 file changed, 1 insertion(+)
policy/modules/kernel/kernel.te +0 -0
index 424a4b511262..e2d3073b4260 100644

policy/modules/kernel/kernel.te optional_policy(` · line 479

Quoted 6 lines
policy/modules/kernel/kernel.te +1 -0
@@ -474,6 +474,7 @@ optional_policy(`
 
 if( ! secure_mode_insmod ) {
 	allow can_load_kernmodule self:capability sys_module;
+	allow can_load_kernmodule self:system module_load;
 
 	files_load_kernel_modules(can_load_kernmodule)

Merged.

Quoted 7 lines
Quoted 5 lines

Hello.

Sorry for my late reply...

I believe this only applies to systemd.

It doesnt. it applies to systems that have kernel modules compressed.

Confirmed.

Quoted 3 lines
Quoted 3 lines

So, is there any reason why it hasn't been enclosed in the appropriate
ifdef(init_systemd) ?

Regards,

Guido