Skip to contentSkip to conversation

policy: use the kernel_request_load_module() interface

PATCH Superseded Ondrej Mosnacek 3 participants 8 messages Nov 26, 2019 SELinux security module

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 policy: use the kernel_request_load_module() interface

...instead of open-coding the rules. Also define a fallback to allow the policy to build even if the interface is not defined.

Fixes f5e5a0b8d005 ("selinux-testsuite: Add key_socket tests")
Cc Richard Haines <[email protected]>

---

Change in v3: use different approach as suggested by Stephen Change in v2: update also tests/Makefile for consistency

 policy/test_key_socket.te | 8 ++++----
 policy/test_policy.if     | 6 ++++++
 2 files changed, 10 insertions(+), 4 deletions(-)
policy/test_key_socket.te +4 -4
index cde426b..f1c1606 100644
@@ -13,7 +13,7 @@ typeattribute test_key_sock_t keysockdomain;
 allow test_key_sock_t self:capability { net_admin };
 allow test_key_sock_t self:key_socket { create write read setopt };
 # For CONFIG_NET_KEY=m
-allow test_key_sock_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
 ################## Deny capability { net_admin } ##########################
 #
@@ -29,7 +29,7 @@ typeattribute test_key_sock_no_net_admin_t testdomain;
 typeattribute test_key_sock_no_net_admin_t keysockdomain;
 
 allow test_key_sock_no_net_admin_t self:key_socket { create write read setopt };
-allow test_key_sock_no_net_admin_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
 ####################### Deny key_socket { create } ##########################
 type test_key_sock_no_create_t;
@@ -50,7 +50,7 @@ typeattribute test_key_sock_no_write_t keysockdomain;
 
 allow test_key_sock_no_write_t self:capability { net_admin };
 allow test_key_sock_no_write_t self:key_socket { create read setopt };
-allow test_key_sock_no_write_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
 ####################### Deny key_socket { read } ##########################
 type test_key_sock_no_read_t;
@@ -61,7 +61,7 @@ typeattribute test_key_sock_no_read_t keysockdomain;
 
 allow test_key_sock_no_read_t self:capability { net_admin };
 allow test_key_sock_no_read_t self:key_socket { create write setopt };
-allow test_key_sock_no_read_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
 #
 ########### Allow these domains to be entered from sysadm domain ############
policy/test_policy.if +6 -0
index e1175e8..3f163cb 100644
@@ -82,3 +82,9 @@ interface(`userdom_search_admin_dir', `
     userdom_search_user_home_content($1)
 ')
 ')
+
+# If the macro isn't defined, then most probably module_request permission
+# is just not supported (and relevant operations should be just allowed).
+ifdef(`kernel_request_load_module', `', ` dnl
+interface(`kernel_request_load_module', `')
+')
Signature · 1 line
2.23.0
Acked-by on v3 1/1
#1 lore raw
Quoted 7 lines · Ondrej Mosnacek

...instead of open-coding the rules. Also define a fallback to allow the policy to build even if the interface is not defined.

Fixes f5e5a0b8d005 ("selinux-testsuite: Add key_socket tests")
Cc Richard Haines <[email protected]>
Quoted 64 lines

---

Change in v3: use different approach as suggested by Stephen Change in v2: update also tests/Makefile for consistency

  policy/test_key_socket.te | 8 ++++----
  policy/test_policy.if     | 6 ++++++
  2 files changed, 10 insertions(+), 4 deletions(-)
policy/test_key_socket.te +4 -4
index cde426b..f1c1606 100644
@@ -13,7 +13,7 @@ typeattribute test_key_sock_t keysockdomain;
  allow test_key_sock_t self:capability { net_admin };
  allow test_key_sock_t self:key_socket { create write read setopt };
  # For CONFIG_NET_KEY=m
-allow test_key_sock_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
  ################## Deny capability { net_admin } ##########################
  #
@@ -29,7 +29,7 @@ typeattribute test_key_sock_no_net_admin_t testdomain;
  typeattribute test_key_sock_no_net_admin_t keysockdomain;
 
  allow test_key_sock_no_net_admin_t self:key_socket { create write read setopt };
-allow test_key_sock_no_net_admin_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
  ####################### Deny key_socket { create } ##########################
  type test_key_sock_no_create_t;
@@ -50,7 +50,7 @@ typeattribute test_key_sock_no_write_t keysockdomain;
 
  allow test_key_sock_no_write_t self:capability { net_admin };
  allow test_key_sock_no_write_t self:key_socket { create read setopt };
-allow test_key_sock_no_write_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
  ####################### Deny key_socket { read } ##########################
  type test_key_sock_no_read_t;
@@ -61,7 +61,7 @@ typeattribute test_key_sock_no_read_t keysockdomain;
 
  allow test_key_sock_no_read_t self:capability { net_admin };
  allow test_key_sock_no_read_t self:key_socket { create write setopt };
-allow test_key_sock_no_read_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
  #
  ########### Allow these domains to be entered from sysadm domain ############
policy/test_policy.if +6 -0
index e1175e8..3f163cb 100644
@@ -82,3 +82,9 @@ interface(`userdom_search_admin_dir', `
      userdom_search_user_home_content($1)
  ')
  ')
+
+# If the macro isn't defined, then most probably module_request permission
+# is just not supported (and relevant operations should be just allowed).
+ifdef(`kernel_request_load_module', `', ` dnl
+interface(`kernel_request_load_module', `')
+')
#2 lore raw
In reply to Ondrej Mosnacek
Quoted 32 lines · Ondrej Mosnacek

...instead of open-coding the rules. Also define a fallback to allow the
policy to build even if the interface is not defined.

Fixes f5e5a0b8d005 ("selinux-testsuite: Add key_socket tests")
Cc Richard Haines <[email protected]>

---

Change in v3: use different approach as suggested by Stephen Change in v2: update also tests/Makefile for consistency

 policy/test_key_socket.te | 8 ++++----
 policy/test_policy.if     | 6 ++++++
 2 files changed, 10 insertions(+), 4 deletions(-)
policy/test_key_socket.te +1 -1
index cde426b..f1c1606 100644
@@ -13,7 +13,7 @@ typeattribute test_key_sock_t keysockdomain;
 allow test_key_sock_t self:capability { net_admin };
 allow test_key_sock_t self:key_socket { create write read setopt };
 # For CONFIG_NET_KEY=m
-allow test_key_sock_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
 ################## Deny capability { net_admin }
 ##########################

#

policy/test_key_socket.te typeattribute test_key_sock_no_net_admin_t · line 35

Quoted 8 lines
policy/test_key_socket.te +1 -1
@@ -29,7 +29,7 @@ typeattribute test_key_sock_no_net_admin_t
 testdomain;
 typeattribute test_key_sock_no_net_admin_t keysockdomain;
 
 allow test_key_sock_no_net_admin_t self:key_socket { create write
 read setopt };
-allow test_key_sock_no_net_admin_t kernel_t:system { module_request
 };
+kernel_request_load_module(test_key_sock_t)

All the new entries have (test_key_sock_t) ??
Anyway if you run the tests in the order they appear in 'test' script, then it just so happens that the module will be loaded for test_key_sock_t as it's first. I added the others just to cover the cases where I sometimes run out of sequence, so you could remove these if required.

Quoted 44 lines

####################### Deny key_socket { create }
##########################
type test_key_sock_no_create_t;

policy/test_key_socket.te +1 -1
@@ -50,7 +50,7 @@ typeattribute test_key_sock_no_write_t
 keysockdomain;
 
 allow test_key_sock_no_write_t self:capability { net_admin };
 allow test_key_sock_no_write_t self:key_socket { create read setopt
 };
-allow test_key_sock_no_write_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 

####################### Deny key_socket { read }
##########################
type test_key_sock_no_read_t;

policy/test_key_socket.te +1 -1
@@ -61,7 +61,7 @@ typeattribute test_key_sock_no_read_t
 keysockdomain;
 
 allow test_key_sock_no_read_t self:capability { net_admin };
 allow test_key_sock_no_read_t self:key_socket { create write setopt
 };
-allow test_key_sock_no_read_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 

#
########### Allow these domains to be entered from sysadm domain
############

policy/test_policy.if +2 -0
index e1175e8..3f163cb 100644
@@ -82,3 +82,9 @@ interface(`userdom_search_admin_dir', `
     userdom_search_user_home_content($1)
 ')
 ')
+
+# If the macro isn't defined, then most probably module_request

permission
+# is just not supported (and relevant operations should be just allowed).

policy/test_policy.if +3 -0
+ifdef(`kernel_request_load_module', `', ` dnl
+interface(`kernel_request_load_module', `')
+')
#3 lore raw
Quoted 36 lines · Richard Haines
Quoted 35 lines · Ondrej Mosnacek

...instead of open-coding the rules. Also define a fallback to allow the
policy to build even if the interface is not defined.

Fixes f5e5a0b8d005 ("selinux-testsuite: Add key_socket tests")
Cc Richard Haines <[email protected]>

---

Change in v3: use different approach as suggested by Stephen Change in v2: update also tests/Makefile for consistency

  policy/test_key_socket.te | 8 ++++----
  policy/test_policy.if     | 6 ++++++
  2 files changed, 10 insertions(+), 4 deletions(-)
policy/test_key_socket.te +1 -1
index cde426b..f1c1606 100644
@@ -13,7 +13,7 @@ typeattribute test_key_sock_t keysockdomain;
  allow test_key_sock_t self:capability { net_admin };
  allow test_key_sock_t self:key_socket { create write read setopt };
  # For CONFIG_NET_KEY=m
-allow test_key_sock_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
  ################## Deny capability { net_admin }
 ##########################

#

policy/test_key_socket.te +0 -0
@@ -29,7 +29,7 @@ typeattribute test_key_sock_no_net_admin_t
 testdomain;
  typeattribute test_key_sock_no_net_admin_t keysockdomain;
 
Quoted 12 lines

policy/test_key_socket.te typeattribute test_key_sock_no_net_admin_t · line 35

Quoted 5 lines
policy/test_key_socket.te +1 -1
  allow test_key_sock_no_net_admin_t self:key_socket { create write
 read setopt };
-allow test_key_sock_no_net_admin_t kernel_t:system { module_request
 };
+kernel_request_load_module(test_key_sock_t)

All the new entries have (test_key_sock_t) ??
Anyway if you run the tests in the order they appear in 'test' script, then it just so happens that the module will be loaded for test_key_sock_t as it's first. I added the others just to cover the cases where I sometimes run out of sequence, so you could remove these if required.

Good catch! Somehow I missed that. Could probably just have a single kernel_request_load_module(keysockdomain) line?

Quoted 46 lines
Quoted 45 lines

####################### Deny key_socket { create }
##########################
type test_key_sock_no_create_t;

policy/test_key_socket.te +1 -1
@@ -50,7 +50,7 @@ typeattribute test_key_sock_no_write_t
 keysockdomain;
 
  allow test_key_sock_no_write_t self:capability { net_admin };
  allow test_key_sock_no_write_t self:key_socket { create read setopt
 };
-allow test_key_sock_no_write_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 

####################### Deny key_socket { read }
##########################
type test_key_sock_no_read_t;

policy/test_key_socket.te +1 -1
@@ -61,7 +61,7 @@ typeattribute test_key_sock_no_read_t
 keysockdomain;
 
  allow test_key_sock_no_read_t self:capability { net_admin };
  allow test_key_sock_no_read_t self:key_socket { create write setopt
 };
-allow test_key_sock_no_read_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 

#
########### Allow these domains to be entered from sysadm domain
############

policy/test_policy.if +2 -0
index e1175e8..3f163cb 100644
@@ -82,3 +82,9 @@ interface(`userdom_search_admin_dir', `
      userdom_search_user_home_content($1)
  ')
  ')
+
+# If the macro isn't defined, then most probably module_request

permission
+# is just not supported (and relevant operations should be just allowed).

policy/test_policy.if +3 -0
+ifdef(`kernel_request_load_module', `', ` dnl
+interface(`kernel_request_load_module', `')
+')
#4 lore raw
Quoted 57 lines · Stephen Smalley
Quoted 39 lines · Richard Haines
Quoted 38 lines · Ondrej Mosnacek

...instead of open-coding the rules. Also define a fallback to allow
the
policy to build even if the interface is not defined.

Fixes f5e5a0b8d005 ("selinux-testsuite: Add key_socket tests")
Cc Richard Haines <[email protected]>

---

Change in v3: use different approach as suggested by Stephen Change in v2: update also tests/Makefile for consistency

  policy/test_key_socket.te | 8 ++++----
  policy/test_policy.if     | 6 ++++++
  2 files changed, 10 insertions(+), 4 deletions(-)
policy/test_key_socket.te +1 -1
index cde426b..f1c1606 100644
@@ -13,7 +13,7 @@ typeattribute test_key_sock_t keysockdomain;
  allow test_key_sock_t self:capability { net_admin };
  allow test_key_sock_t self:key_socket { create write read
 setopt };
  # For CONFIG_NET_KEY=m
-allow test_key_sock_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
  ################## Deny capability { net_admin }

##########################
#

policy/test_key_socket.te +0 -0
@@ -29,7 +29,7 @@ typeattribute test_key_sock_no_net_admin_t
 testdomain;
  typeattribute test_key_sock_no_net_admin_t keysockdomain;
 
Quoted 16 lines
Quoted 7 lines
policy/test_key_socket.te +0 -0
  allow test_key_sock_no_net_admin_t self:key_socket { create

write
read setopt };
-allow test_key_sock_no_net_admin_t kernel_t:system { module_request
}; +kernel_request_load_module(test_key_sock_t)

All the new entries have (test_key_sock_t) ??
Anyway if you run the tests in the order they appear in 'test' script,
then it just so happens that the module will be loaded for test_key_sock_t as it's first. I added the others just to cover the cases where I sometimes run out of sequence, so you could remove these
if required.

Quoted 3 lines

Good catch! Somehow I missed that. Could probably just have a single
kernel_request_load_module(keysockdomain) line?

That's fine as it cover all cases.

Quoted 50 lines
Quoted 50 lines
Quoted 50 lines

####################### Deny key_socket { create }
##########################
type test_key_sock_no_create_t;

policy/test_key_socket.te +0 -0
@@ -50,7 +50,7 @@ typeattribute test_key_sock_no_write_t
 keysockdomain;
 
  allow test_key_sock_no_write_t self:capability { net_admin };
  allow test_key_sock_no_write_t self:key_socket { create read

setopt
};
-allow test_key_sock_no_write_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)

####################### Deny key_socket { read }
##########################
type test_key_sock_no_read_t;

policy/test_key_socket.te +0 -0
@@ -61,7 +61,7 @@ typeattribute test_key_sock_no_read_t
 keysockdomain;
 
  allow test_key_sock_no_read_t self:capability { net_admin };
  allow test_key_sock_no_read_t self:key_socket { create write

setopt
};
-allow test_key_sock_no_read_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)

#
########### Allow these domains to be entered from sysadm
domain
############

policy/test_policy.if +2 -0
index e1175e8..3f163cb 100644
@@ -82,3 +82,9 @@ interface(`userdom_search_admin_dir', `
      userdom_search_user_home_content($1)
  ')
  ')
+
+# If the macro isn't defined, then most probably module_request

permission
+# is just not supported (and relevant operations should be just allowed).

policy/test_policy.if +3 -0
+ifdef(`kernel_request_load_module', `', ` dnl
+interface(`kernel_request_load_module', `')
+')
#5 lore raw
In reply to Stephen Smalley
Quoted 37 lines · Stephen Smalley
Quoted 36 lines · Richard Haines
Quoted 35 lines · Ondrej Mosnacek

...instead of open-coding the rules. Also define a fallback to allow the
policy to build even if the interface is not defined.

Fixes f5e5a0b8d005 ("selinux-testsuite: Add key_socket tests")
Cc Richard Haines <[email protected]>

---

Change in v3: use different approach as suggested by Stephen Change in v2: update also tests/Makefile for consistency

  policy/test_key_socket.te | 8 ++++----
  policy/test_policy.if     | 6 ++++++
  2 files changed, 10 insertions(+), 4 deletions(-)
policy/test_key_socket.te +1 -1
index cde426b..f1c1606 100644
@@ -13,7 +13,7 @@ typeattribute test_key_sock_t keysockdomain;
  allow test_key_sock_t self:capability { net_admin };
  allow test_key_sock_t self:key_socket { create write read setopt };
  # For CONFIG_NET_KEY=m
-allow test_key_sock_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
  ################## Deny capability { net_admin }
 ##########################

#

policy/test_key_socket.te +0 -0
@@ -29,7 +29,7 @@ typeattribute test_key_sock_no_net_admin_t
 testdomain;
  typeattribute test_key_sock_no_net_admin_t keysockdomain;
 
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
policy/test_key_socket.te +0 -1
  allow test_key_sock_no_net_admin_t self:key_socket { create write
 read setopt };
-allow test_key_sock_no_net_admin_t kernel_t:system { module_request
 };
Quoted 8 lines

policy/test_key_socket.te typeattribute test_key_sock_no_net_admin_t · line 35

Quoted 1 line
policy/test_key_socket.te +1 -0
+kernel_request_load_module(test_key_sock_t)

All the new entries have (test_key_sock_t) ??
Anyway if you run the tests in the order they appear in 'test' script, then it just so happens that the module will be loaded for test_key_sock_t as it's first. I added the others just to cover the cases where I sometimes run out of sequence, so you could remove these if required.

*facepalm*

Yes, sorry, I messed up the copy-paste...

Quoted 3 lines

Good catch! Somehow I missed that. Could probably just have a single kernel_request_load_module(keysockdomain) line?

There is one domain (test_key_sock_no_create_t) that doesn't have the rule, so probably not.

Quoted 48 lines
Quoted 47 lines
Quoted 46 lines

####################### Deny key_socket { create }
##########################
type test_key_sock_no_create_t;

policy/test_key_socket.te +1 -1
@@ -50,7 +50,7 @@ typeattribute test_key_sock_no_write_t
 keysockdomain;
 
  allow test_key_sock_no_write_t self:capability { net_admin };
  allow test_key_sock_no_write_t self:key_socket { create read setopt
 };
-allow test_key_sock_no_write_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 

####################### Deny key_socket { read }
##########################
type test_key_sock_no_read_t;

policy/test_key_socket.te +1 -1
@@ -61,7 +61,7 @@ typeattribute test_key_sock_no_read_t
 keysockdomain;
 
  allow test_key_sock_no_read_t self:capability { net_admin };
  allow test_key_sock_no_read_t self:key_socket { create write setopt
 };
-allow test_key_sock_no_read_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 

#
########### Allow these domains to be entered from sysadm domain
############

policy/test_policy.if +2 -0
index e1175e8..3f163cb 100644
@@ -82,3 +82,9 @@ interface(`userdom_search_admin_dir', `
      userdom_search_user_home_content($1)
  ')
  ')
+
+# If the macro isn't defined, then most probably module_request

permission
+# is just not supported (and relevant operations should be just allowed).

policy/test_policy.if +3 -0
+ifdef(`kernel_request_load_module', `', ` dnl
+interface(`kernel_request_load_module', `')
+')
Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
#6 lore raw
Quoted 62 lines · Ondrej Mosnacek
Quoted 49 lines · Stephen Smalley
Quoted 48 lines · Richard Haines
Quoted 39 lines · Ondrej Mosnacek

...instead of open-coding the rules. Also define a fallback to allow
the
policy to build even if the interface is not defined.

Fixes f5e5a0b8d005 ("selinux-testsuite: Add key_socket tests")
Cc Richard Haines <[email protected]>

---

Change in v3: use different approach as suggested by Stephen Change in v2: update also tests/Makefile for consistency

  policy/test_key_socket.te | 8 ++++----
  policy/test_policy.if     | 6 ++++++
  2 files changed, 10 insertions(+), 4 deletions(-)
policy/test_key_socket.te +1 -1
index cde426b..f1c1606 100644
@@ -13,7 +13,7 @@ typeattribute test_key_sock_t keysockdomain;
  allow test_key_sock_t self:capability { net_admin };
  allow test_key_sock_t self:key_socket { create write read
 setopt };
  # For CONFIG_NET_KEY=m
-allow test_key_sock_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
  ################## Deny capability { net_admin }

##########################
#

policy/test_key_socket.te +0 -0
@@ -29,7 +29,7 @@ typeattribute test_key_sock_no_net_admin_t
 testdomain;
  typeattribute test_key_sock_no_net_admin_t keysockdomain;
 
  allow test_key_sock_no_net_admin_t self:key_socket { create
Quoted 6 lines

write
read setopt };
-allow test_key_sock_no_net_admin_t kernel_t:system { module_request
}; +kernel_request_load_module(test_key_sock_t)

All the new entries have (test_key_sock_t) ??

Quoted 8 lines
Quoted 8 lines

Anyway if you run the tests in the order they appear in 'test' script,
then it just so happens that the module will be loaded for test_key_sock_t as it's first. I added the others just to cover the
cases where I sometimes run out of sequence, so you could remove these
if required.

*facepalm*

Quoted 8 lines

Yes, sorry, I messed up the copy-paste...

Quoted 3 lines

Good catch! Somehow I missed that. Could probably just have a single
kernel_request_load_module(keysockdomain) line?

There is one domain (test_key_sock_no_create_t) that doesn't have the rule, so probably not.

That is probably one I didn't test out of sequence.

I'm currently writing the TUN/TAP tests and had the same problem as I've left the default Fedora CONFIG_TUN=m.
I've added 'kernel_request_load_module(tuntapdomain)' to the test module that allows tests in any order (as I usually run rmmod just as a check).

I'll leave it to you guys to decide what is finally best for you.

Quoted 53 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines

####################### Deny key_socket { create }
##########################
type test_key_sock_no_create_t;

policy/test_key_socket.te +0 -0
@@ -50,7 +50,7 @@ typeattribute test_key_sock_no_write_t
 keysockdomain;
 
  allow test_key_sock_no_write_t self:capability { net_admin };
  allow test_key_sock_no_write_t self:key_socket { create read

setopt
};
-allow test_key_sock_no_write_t kernel_t:system {
module_request };
+kernel_request_load_module(test_key_sock_t)

####################### Deny key_socket { read }
##########################
type test_key_sock_no_read_t;

policy/test_key_socket.te +0 -0
@@ -61,7 +61,7 @@ typeattribute test_key_sock_no_read_t
 keysockdomain;
 
  allow test_key_sock_no_read_t self:capability { net_admin };
  allow test_key_sock_no_read_t self:key_socket { create write

setopt
};
-allow test_key_sock_no_read_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)

#
########### Allow these domains to be entered from sysadm
domain
############

policy/test_policy.if +2 -0
index e1175e8..3f163cb 100644
@@ -82,3 +82,9 @@ interface(`userdom_search_admin_dir', `
      userdom_search_user_home_content($1)
  ')
  ')
+
+# If the macro isn't defined, then most probably

module_request
permission
+# is just not supported (and relevant operations should be just
allowed).

policy/test_policy.if +3 -0
+ifdef(`kernel_request_load_module', `', ` dnl
+interface(`kernel_request_load_module', `')
+')
#7 lore raw
Quoted 74 lines · Richard Haines
Quoted 62 lines · Ondrej Mosnacek
Quoted 49 lines · Stephen Smalley
Quoted 48 lines · Richard Haines
Quoted 39 lines · Ondrej Mosnacek

...instead of open-coding the rules. Also define a fallback to allow
the
policy to build even if the interface is not defined.

Fixes f5e5a0b8d005 ("selinux-testsuite: Add key_socket tests")
Cc Richard Haines <[email protected]>

---

Change in v3: use different approach as suggested by Stephen Change in v2: update also tests/Makefile for consistency

  policy/test_key_socket.te | 8 ++++----
  policy/test_policy.if     | 6 ++++++
  2 files changed, 10 insertions(+), 4 deletions(-)
policy/test_key_socket.te +1 -1
index cde426b..f1c1606 100644
@@ -13,7 +13,7 @@ typeattribute test_key_sock_t keysockdomain;
  allow test_key_sock_t self:capability { net_admin };
  allow test_key_sock_t self:key_socket { create write read
 setopt };
  # For CONFIG_NET_KEY=m
-allow test_key_sock_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)
 
  ################## Deny capability { net_admin }

##########################
#

policy/test_key_socket.te +0 -0
@@ -29,7 +29,7 @@ typeattribute test_key_sock_no_net_admin_t
 testdomain;
  typeattribute test_key_sock_no_net_admin_t keysockdomain;
 
  allow test_key_sock_no_net_admin_t self:key_socket { create
Quoted 6 lines

write
read setopt };
-allow test_key_sock_no_net_admin_t kernel_t:system { module_request
}; +kernel_request_load_module(test_key_sock_t)

All the new entries have (test_key_sock_t) ??

Quoted 8 lines
Quoted 8 lines

Anyway if you run the tests in the order they appear in 'test' script,
then it just so happens that the module will be loaded for test_key_sock_t as it's first. I added the others just to cover the
cases where I sometimes run out of sequence, so you could remove these
if required.

*facepalm*

Quoted 8 lines

Yes, sorry, I messed up the copy-paste...

Quoted 3 lines

Good catch! Somehow I missed that. Could probably just have a single
kernel_request_load_module(keysockdomain) line?

There is one domain (test_key_sock_no_create_t) that doesn't have the rule, so probably not.

That is probably one I didn't test out of sequence.

Quoted 7 lines

I'm currently writing the TUN/TAP tests and had the same problem as I've left the default Fedora CONFIG_TUN=m.
I've added 'kernel_request_load_module(tuntapdomain)' to the test module that allows tests in any order (as I usually run rmmod just as a check).

I'll leave it to you guys to decide what is finally best for you.

Aha, I see, so actually all the types might potentially need the rule (if someone rmmods the module during test, for example), so it would make more sense to allow it to the whole domain as Stephen suggested. I didn't stop to think about it and I assumed that the one domain didn't have the rule intentionally... I think I'll repost the patch once more, calling the macro on the whole keysockdomain.

Quoted 55 lines
Quoted 54 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines

####################### Deny key_socket { create }
##########################
type test_key_sock_no_create_t;

policy/test_key_socket.te +0 -0
@@ -50,7 +50,7 @@ typeattribute test_key_sock_no_write_t
 keysockdomain;
 
  allow test_key_sock_no_write_t self:capability { net_admin };
  allow test_key_sock_no_write_t self:key_socket { create read

setopt
};
-allow test_key_sock_no_write_t kernel_t:system {
module_request };
+kernel_request_load_module(test_key_sock_t)

####################### Deny key_socket { read }
##########################
type test_key_sock_no_read_t;

policy/test_key_socket.te +0 -0
@@ -61,7 +61,7 @@ typeattribute test_key_sock_no_read_t
 keysockdomain;
 
  allow test_key_sock_no_read_t self:capability { net_admin };
  allow test_key_sock_no_read_t self:key_socket { create write

setopt
};
-allow test_key_sock_no_read_t kernel_t:system { module_request };
+kernel_request_load_module(test_key_sock_t)

#
########### Allow these domains to be entered from sysadm
domain
############

policy/test_policy.if +2 -0
index e1175e8..3f163cb 100644
@@ -82,3 +82,9 @@ interface(`userdom_search_admin_dir', `
      userdom_search_user_home_content($1)
  ')
  ')
+
+# If the macro isn't defined, then most probably

module_request
permission
+# is just not supported (and relevant operations should be just
allowed).

policy/test_policy.if +3 -0
+ifdef(`kernel_request_load_module', `', ` dnl
+interface(`kernel_request_load_module', `')
+')
Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.