Skip to contentSkip to conversation

selinux: security: Move selinux_state to a separate page

RFC PATCH In review Preeti Nagar 5 participants 11 messages Jan 8, 2021 – Jan 18, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/1 selinux: security: Move selinux_state to a separate page

The changes introduce a new security feature, RunTime Integrity Check (RTIC), designed to protect Linux Kernel at runtime. The motivation behind these changes is:
1. The system protection offered by SE for Android relies on the assumption of kernel integrity. If the kernel itself is compromised (by a perhaps as yet unknown future vulnerability), SE for Android security mechanisms could potentially be disabled and rendered ineffective.
2. Qualcomm Snapdragon devices use Secure Boot, which adds cryptographic checks to each stage of the boot-up process, to assert the authenticity of all secure software images that the device executes. However, due to various vulnerabilities in SW modules, the integrity of the system can be compromised at any time after device boot-up, leading to un-authorized SW executing.

The feature's idea is to move some sensitive kernel structures to a separate page and monitor further any unauthorized changes to these, from higher Exception Levels using stage 2 MMU. Moving these to a different page will help avoid getting page faults from un-related data. Using this mechanism, some sensitive variables of the kernel which are initialized after init or are updated rarely can also be protected from simple overwrites and attacks trying to modify these.

Currently, the change moves selinux_state structure to a separate page. In future we plan to move more security-related kernel assets to this page to enhance protection.

We want to seek your suggestions and comments on the idea and the changes in the patch.

---
 include/asm-generic/vmlinux.lds.h | 10 ++++++++++
 include/linux/init.h              |  4 ++++
 security/Kconfig                  | 10 ++++++++++
 security/selinux/hooks.c          |  4 ++++
 4 files changed, 28 insertions(+)
include/asm-generic/vmlinux.lds.h +10 -0
index b2b3d81..158dbc2 100644
@@ -770,6 +770,15 @@
 		*(.scommon)						\
 	}
 
+#ifdef CONFIG_SECURITY_RTIC
+#define RTIC_BSS							\
+	. = ALIGN(PAGE_SIZE);						\
+	KEEP(*(.bss.rtic))						\
+	. = ALIGN(PAGE_SIZE);
+#else
+#define RTIC_BSS
+#endif
+
 /*
  * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
  * sections to the front of bss.
@@ -782,6 +791,7 @@
 	. = ALIGN(bss_align);						\
 	.bss : AT(ADDR(.bss) - LOAD_OFFSET) {				\
 		BSS_FIRST_SECTIONS					\
+		RTIC_BSS						\
 		. = ALIGN(PAGE_SIZE);					\
 		*(.bss..page_aligned)					\
 		. = ALIGN(PAGE_SIZE);					\
include/linux/init.h +4 -0
index 7b53cb3..617adcf 100644
@@ -300,6 +300,10 @@ void __init parse_early_options(char *cmdline);
 /* Data marked not to be saved by software suspend */
 #define __nosavedata __section(".data..nosave")
 
+#ifdef CONFIG_SECURITY_RTIC
+#define __rticdata  __section(".bss.rtic")
+#endif
+
 #ifdef MODULE
 #define __exit_p(x) x
 #else
security/Kconfig +10 -0
index 7561f6f..66b61b9 100644
@@ -291,5 +291,15 @@ config LSM
 
 source "security/Kconfig.hardening"
 
+config SECURITY_RTIC
+        bool "RunTime Integrity Check feature"
+        help
+	  RTIC(RunTime Integrity Check) feature is to protect Linux kernel
+	  at runtime. This relocates some of the security sensitive kernel
+	  structures to a separate page aligned special section.
+
+	  This is to enable monitoring and protection of these kernel assets
+	  from a higher exception level(EL) against any unauthorized changes.
+
 endmenu
 
security/selinux/hooks.c +4 -0
index 6b1826f..7add17c 100644
@@ -104,7 +104,11 @@
 #include "audit.h"
 #include "avc_ss.h"
 
+#ifdef CONFIG_SECURITY_RTIC
+struct selinux_state selinux_state __rticdata;
+#else
 struct selinux_state selinux_state;
+#endif
 
 /* SECMARK reference count */
 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 3 lines · Preeti Nagar

We want to seek your suggestions and comments on the idea and the changes in the patch.

Not sure why I was Cc'd, but I have a quick comment nevertheless.

security/selinux/hooks.c line 111

Quoted 5 lines
security/selinux/hooks.c +4 -0
+#ifdef CONFIG_SECURITY_RTIC
+struct selinux_state selinux_state __rticdata;
+#else
 struct selinux_state selinux_state;
+#endif

If you define an empty __rticdata for the !CONFIG case, then we don't need #ifdefs for uses like this.

Cheers,
Miguel

#2 lore raw
Quoted 16 lines · Miguel Ojeda
Quoted 3 lines · Preeti Nagar

We want to seek your suggestions and comments on the idea and the changes in the patch.

Not sure why I was Cc'd, but I have a quick comment nevertheless.

security/selinux/hooks.c line 111

Quoted 5 lines
security/selinux/hooks.c +4 -0
+#ifdef CONFIG_SECURITY_RTIC
+struct selinux_state selinux_state __rticdata;
+#else
 struct selinux_state selinux_state;
+#endif

If you define an empty __rticdata for the !CONFIG case, then we don't need #ifdefs for uses like this.

Quoted 2 lines

Cheers,
Miguel

Thank you for the review! Will update this change in the next version of the patch soon.

Thanks,
Preeti

#3 lore raw
In reply to Preeti Nagar
Quoted 3 lines · Preeti Nagar

We want to seek your suggestions and comments on the idea and the changes in the patch.

Cc'ing Nick manually since his email domain was (again :-) incorrect.

Cheers,
Miguel

#4 lore raw
In reply to Preeti Nagar
Quoted 5 lines · Preeti Nagar

The changes introduce a new security feature, RunTime Integrity Check (RTIC), designed to protect Linux Kernel at runtime. The motivation behind these changes is:
1. The system protection offered by SE for Android relies on the assumption of kernel integrity. If the kernel itself is compromised (by

Quoted 8 lines

a perhaps as yet unknown future vulnerability), SE for Android security mechanisms could potentially be disabled and rendered ineffective.
2. Qualcomm Snapdragon devices use Secure Boot, which adds cryptographic checks to each stage of the boot-up process, to assert the authenticity of all secure software images that the device executes. However, due to various vulnerabilities in SW modules, the integrity of the system can be compromised at any time after device boot-up, leading to un-authorized SW executing.

It would be helpful if you characterized the "various vulnerabilities" rather than simply asserting their existence. This would allow the reviewer to determine if the proposed patch addresses the issue.

Quoted 5 lines

The feature's idea is to move some sensitive kernel structures to a separate page and monitor further any unauthorized changes to these, from higher Exception Levels using stage 2 MMU. Moving these to a different page will help avoid getting page faults from un-related data.

I've always been a little slow when it comes to understanding the details of advanced memory management facilities. That's part of why I work in access control. Could you expand this a bit, so that someone who doesn't already know how your stage 2 MMU works might be able to evaluate what you're doing here.

Quoted 3 lines

Using this mechanism, some sensitive variables of the kernel which are initialized after init or are updated rarely can also be protected from simple overwrites and attacks trying to modify these.

How would this interact with or complement __read_mostly?

Quoted 4 lines

Currently, the change moves selinux_state structure to a separate page. In future we plan to move more security-related kernel assets to this page to enhance protection.

What's special about selinux_state? What about the SELinux policy? How would I, as maintainer of the Smack security module, know if some Smack data should be treated the same way?

Quoted 60 lines

We want to seek your suggestions and comments on the idea and the changes in the patch.

---
 include/asm-generic/vmlinux.lds.h | 10 ++++++++++
 include/linux/init.h              |  4 ++++
 security/Kconfig                  | 10 ++++++++++
 security/selinux/hooks.c          |  4 ++++
 4 files changed, 28 insertions(+)
include/asm-generic/vmlinux.lds.h +10 -0
index b2b3d81..158dbc2 100644
@@ -770,6 +770,15 @@
 		*(.scommon)						\
 	}
 
+#ifdef CONFIG_SECURITY_RTIC
+#define RTIC_BSS							\
+	. = ALIGN(PAGE_SIZE);						\
+	KEEP(*(.bss.rtic))						\
+	. = ALIGN(PAGE_SIZE);
+#else
+#define RTIC_BSS
+#endif
+
 /*
  * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
  * sections to the front of bss.
@@ -782,6 +791,7 @@
 	. = ALIGN(bss_align);						\
 	.bss : AT(ADDR(.bss) - LOAD_OFFSET) {				\
 		BSS_FIRST_SECTIONS					\
+		RTIC_BSS						\
 		. = ALIGN(PAGE_SIZE);					\
 		*(.bss..page_aligned)					\
 		. = ALIGN(PAGE_SIZE);					\
include/linux/init.h +4 -0
index 7b53cb3..617adcf 100644
@@ -300,6 +300,10 @@ void __init parse_early_options(char *cmdline);
 /* Data marked not to be saved by software suspend */
 #define __nosavedata __section(".data..nosave")
 
+#ifdef CONFIG_SECURITY_RTIC
+#define __rticdata  __section(".bss.rtic")
+#endif
+
 #ifdef MODULE
 #define __exit_p(x) x
 #else
security/Kconfig +0 -0
index 7561f6f..66b61b9 100644

security/Kconfig config LSM · line 295

Quoted 5 lines
security/Kconfig +2 -0
@@ -291,5 +291,15 @@ config LSM
 
 source "security/Kconfig.hardening"
 
+config SECURITY_RTIC
+        bool "RunTime Integrity Check feature"

Shouldn't this depend on the architecture(s) supporting the feature?

security/Kconfig config LSM · line 302

Quoted 7 lines
security/Kconfig +7 -0
+        help
+	  RTIC(RunTime Integrity Check) feature is to protect Linux kernel
+	  at runtime. This relocates some of the security sensitive kernel
+	  structures to a separate page aligned special section.
+
+	  This is to enable monitoring and protection of these kernel assets
+	  from a higher exception level(EL) against any unauthorized changes.

"if you are unsure ..."

Quoted 8 lines
security/Kconfig +1 -0
+
 endmenu
 
security/selinux/hooks.c +0 -0
index 6b1826f..7add17c 100644

security/selinux/hooks.c line 111

Quoted 8 lines
security/selinux/hooks.c +4 -0
@@ -104,7 +104,11 @@
 #include "audit.h"
 #include "avc_ss.h"
 
+#ifdef CONFIG_SECURITY_RTIC
+struct selinux_state selinux_state __rticdata;
+#else
 struct selinux_state selinux_state;
+#endif

Shouldn't the __rticdata tag be applied always, and its definition take care of the cases where it doesn't do anything?

Quoted 3 lines
security/selinux/hooks.c +0 -0
 /* SECMARK reference count */
 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
#5 lore raw
Quoted 15 lines · Casey Schaufler
Quoted 5 lines · Preeti Nagar

The changes introduce a new security feature, RunTime Integrity Check (RTIC), designed to protect Linux Kernel at runtime. The motivation behind these changes is:
1. The system protection offered by SE for Android relies on the assumption of kernel integrity. If the kernel itself is compromised (by

Quoted 8 lines

a perhaps as yet unknown future vulnerability), SE for Android security mechanisms could potentially be disabled and rendered ineffective.
2. Qualcomm Snapdragon devices use Secure Boot, which adds cryptographic checks to each stage of the boot-up process, to assert the authenticity of all secure software images that the device executes. However, due to various vulnerabilities in SW modules, the integrity of the system can be compromised at any time after device boot-up, leading to un-authorized SW executing.

Quoted 4 lines

It would be helpful if you characterized the "various vulnerabilities" rather than simply asserting their existence. This would allow the reviewer to determine if the proposed patch addresses the issue.

There might not currently be vulnerabilities, but the system is meant more specifically to harden valuable assets against future compromises. The key value add is a third party independent entity keeping a watch on crucial kernel assets.

Quoted 6 lines
Quoted 5 lines

The feature's idea is to move some sensitive kernel structures to a separate page and monitor further any unauthorized changes to these, from higher Exception Levels using stage 2 MMU. Moving these to a different page will help avoid getting page faults from un-related data.

Quoted 6 lines

I've always been a little slow when it comes to understanding the details of advanced memory management facilities. That's part of why I work in access control. Could you expand this a bit, so that someone who doesn't already know how your stage 2 MMU works might be able to evaluate what you're doing here.

Sure, will include more details. The mechanism we have been working on removes the write permissions for HLOS in the stage 2 page tables for the regions to be monitored, such that any modification attempts to these will lead to faults being generated and handled by handlers. If the protected assets are moved to a separate page, faults will be generated corresponding to change attempts to these assets only. If not moved to a separate page, write attempts to un-related data which is present on the monitored pages will also be generated.

Quoted 6 lines
Quoted 3 lines

Using this mechanism, some sensitive variables of the kernel which are initialized after init or are updated rarely can also be protected from simple overwrites and attacks trying to modify these.

How would this interact with or complement __read_mostly?

Currently, the mechanism we are working on developing is independent of __read_mostly. This is something we can look more into while working further on the mechanism.

Quoted 9 lines
Quoted 4 lines

Currently, the change moves selinux_state structure to a separate page. In future we plan to move more security-related kernel assets to this page to enhance protection.

What's special about selinux_state? What about the SELinux policy? How would I, as maintainer of the Smack security module, know if some Smack data should be treated the same way?

We are investigating more of the SELinux related and other kernel assets which can be included in the protection. The basis of selinux_state is because disabling of SELinux is one of the common attack vectors in Android. We understand any kernel assets, unauthorized changes to which can give way to security or any other type of attack can be considered to be a potential asset to be added to the protection.

Quoted 69 lines
Quoted 60 lines

We want to seek your suggestions and comments on the idea and the changes in the patch.

---
 include/asm-generic/vmlinux.lds.h | 10 ++++++++++
 include/linux/init.h              |  4 ++++
 security/Kconfig                  | 10 ++++++++++
 security/selinux/hooks.c          |  4 ++++
 4 files changed, 28 insertions(+)
include/asm-generic/vmlinux.lds.h +10 -0
index b2b3d81..158dbc2 100644
@@ -770,6 +770,15 @@
 		*(.scommon)						\
 	}
 
+#ifdef CONFIG_SECURITY_RTIC
+#define RTIC_BSS							\
+	. = ALIGN(PAGE_SIZE);						\
+	KEEP(*(.bss.rtic))						\
+	. = ALIGN(PAGE_SIZE);
+#else
+#define RTIC_BSS
+#endif
+
 /*
  * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
  * sections to the front of bss.
@@ -782,6 +791,7 @@
 	. = ALIGN(bss_align);						\
 	.bss : AT(ADDR(.bss) - LOAD_OFFSET) {				\
 		BSS_FIRST_SECTIONS					\
+		RTIC_BSS						\
 		. = ALIGN(PAGE_SIZE);					\
 		*(.bss..page_aligned)					\
 		. = ALIGN(PAGE_SIZE);					\
include/linux/init.h +4 -0
index 7b53cb3..617adcf 100644
@@ -300,6 +300,10 @@ void __init parse_early_options(char *cmdline);
 /* Data marked not to be saved by software suspend */
 #define __nosavedata __section(".data..nosave")
 
+#ifdef CONFIG_SECURITY_RTIC
+#define __rticdata  __section(".bss.rtic")
+#endif
+
 #ifdef MODULE
 #define __exit_p(x) x
 #else
security/Kconfig +0 -0
index 7561f6f..66b61b9 100644

security/Kconfig config LSM · line 295

Quoted 5 lines
security/Kconfig +2 -0
@@ -291,5 +291,15 @@ config LSM
 
 source "security/Kconfig.hardening"
 
+config SECURITY_RTIC
+        bool "RunTime Integrity Check feature"

Shouldn't this depend on the architecture(s) supporting the feature?

Quoted 11 lines
Quoted 8 lines
security/Kconfig +7 -0
+        help
+	  RTIC(RunTime Integrity Check) feature is to protect Linux kernel
+	  at runtime. This relocates some of the security sensitive kernel
+	  structures to a separate page aligned special section.
+
+	  This is to enable monitoring and protection of these kernel assets
+	  from a higher exception level(EL) against any unauthorized 

changes.

"if you are unsure ..."

We just thought keeping it generic might be a better idea, thus, moved the changes to generic files from arch-specific files and thus, kept config also independent of the arch. Can surely make this config arch dependent if that is a better approach?

Quoted 11 lines
Quoted 11 lines
security/Kconfig +1 -0
+
 endmenu
security/selinux/hooks.c +0 -0
index 6b1826f..7add17c 100644
@@ -104,7 +104,11 @@
 #include "audit.h"
 #include "avc_ss.h"
 
Quoted 9 lines

security/selinux/hooks.c line 111

Quoted 5 lines
security/selinux/hooks.c +4 -0
+#ifdef CONFIG_SECURITY_RTIC
+struct selinux_state selinux_state __rticdata;
+#else
 struct selinux_state selinux_state;
+#endif

Shouldn't the __rticdata tag be applied always, and its definition take care of the cases where it doesn't do anything?

Will update this change in the next version of the patch. Thank you.

Quoted 3 lines
Quoted 3 lines
security/selinux/hooks.c +0 -0
 /* SECMARK reference count */
 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
#6 lore raw
Quoted 16 lines · On 1/12/2021 1:36 AM, [email protected] wrote:
Quoted 15 lines · Casey Schaufler
Quoted 13 lines · Preeti Nagar

The changes introduce a new security feature, RunTime Integrity Check (RTIC), designed to protect Linux Kernel at runtime. The motivation behind these changes is:
1. The system protection offered by SE for Android relies on the assumption of kernel integrity. If the kernel itself is compromised (by a perhaps as yet unknown future vulnerability), SE for Android security mechanisms could potentially be disabled and rendered ineffective.
2. Qualcomm Snapdragon devices use Secure Boot, which adds cryptographic checks to each stage of the boot-up process, to assert the authenticity of all secure software images that the device executes.  However, due to various vulnerabilities in SW modules, the integrity of the system can be compromised at any time after device boot-up, leading to un-authorized SW executing.

Quoted 8 lines
Quoted 4 lines

It would be helpful if you characterized the "various vulnerabilities" rather than simply asserting their existence. This would allow the reviewer to determine if the proposed patch addresses the issue.

There might not currently be vulnerabilities, but the system is meant more specifically to harden valuable assets against future compromises. The key value add is a third party independent entity keeping a watch on crucial kernel assets.

Could you characterize the potential vulnerabilities, then? Seriously, there's a gazillion ways data integrity can be compromised. Which of those are addressed?

Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

The feature's idea is to move some sensitive kernel structures to a separate page and monitor further any unauthorized changes to these, from higher Exception Levels using stage 2 MMU. Moving these to a different page will help avoid getting page faults from un-related data.

Quoted 6 lines

I've always been a little slow when it comes to understanding the details of advanced memory management facilities. That's part of why I work in access control. Could you expand this a bit, so that someone who doesn't already know how your stage 2 MMU works might be able to evaluate what you're doing here.

Quoted 8 lines

Sure, will include more details. The mechanism we have been working on removes the write permissions for HLOS in the stage 2 page tables for the regions to be monitored, such that any modification attempts to these will lead to faults being generated and handled by handlers. If the protected assets are moved to a separate page, faults will be generated corresponding to change attempts to these assets only. If not moved to a separate page, write attempts to un-related data which is present on the monitored pages will also be generated.

Thanks.

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

Using this mechanism, some sensitive variables of the kernel which are initialized after init or are updated rarely can also be protected from simple overwrites and attacks trying to modify these.

How would this interact with or complement __read_mostly?

Currently, the mechanism we are working on developing is independent of __read_mostly. This is something we can look more into while working further on the mechanism.

Please either integrate the two or explain how they differ. It appears that you haven't considered how you might exploit or expand the existing mechanism.

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

Currently, the change moves selinux_state structure to a separate page. In future we plan to move more security-related kernel assets to this page to enhance protection.

What's special about selinux_state? What about the SELinux policy? How would I, as maintainer of the Smack security module, know if some Smack data should be treated the same way?

Quoted 6 lines

We are investigating more of the SELinux related and other kernel assets which can be included in the protection. The basis of selinux_state is because disabling of SELinux is one of the common attack vectors in Android. We understand any kernel assets, unauthorized changes to which can give way to security or any other type of attack can be considered to be a potential asset to be added to the protection.

Yeah, I get that. It looks like this could be a useful mechanism beyond SELinux. No point in hoarding it.

Quoted 78 lines
Quoted 78 lines
Quoted 64 lines

We want to seek your suggestions and comments on the idea and the changes in the patch.

---
 include/asm-generic/vmlinux.lds.h | 10 ++++++++++ include/linux/init.h              |  4 ++++ security/Kconfig                  | 10 ++++++++++ security/selinux/hooks.c          |  4 ++++

 4 files changed, 28 insertions(+)
include/asm-generic/vmlinux.lds.h +10 -0
index b2b3d81..158dbc2 100644
@@ -770,6 +770,15 @@
          *(.scommon)                        \
      }
 
+#ifdef CONFIG_SECURITY_RTIC
+#define RTIC_BSS                            \
+    . = ALIGN(PAGE_SIZE);                        \
+    KEEP(*(.bss.rtic))                        \
+    . = ALIGN(PAGE_SIZE);
+#else
+#define RTIC_BSS
+#endif
+
  /*
   * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
   * sections to the front of bss.
@@ -782,6 +791,7 @@
      . = ALIGN(bss_align);                        \
      .bss : AT(ADDR(.bss) - LOAD_OFFSET) {                \
          BSS_FIRST_SECTIONS                    \
+        RTIC_BSS                        \
          . = ALIGN(PAGE_SIZE);                    \
          *(.bss..page_aligned)                    \
          . = ALIGN(PAGE_SIZE);                    \
include/linux/init.h +4 -0
index 7b53cb3..617adcf 100644
@@ -300,6 +300,10 @@ void __init parse_early_options(char *cmdline);
  /* Data marked not to be saved by software suspend */
  #define __nosavedata __section(".data..nosave")
 
+#ifdef CONFIG_SECURITY_RTIC
+#define __rticdata  __section(".bss.rtic")
+#endif
+
  #ifdef MODULE
  #define __exit_p(x) x
  #else
security/Kconfig +0 -0
index 7561f6f..66b61b9 100644
@@ -291,5 +291,15 @@ config LSM
 

 source "security/Kconfig.hardening"

Quoted 2 lines

+config SECURITY_RTIC
+        bool "RunTime Integrity Check feature"

Shouldn't this depend on the architecture(s) supporting the feature?

Quoted 7 lines

+        help
+      RTIC(RunTime Integrity Check) feature is to protect Linux kernel +      at runtime. This relocates some of the security sensitive kernel +      structures to a separate page aligned special section. +
+      This is to enable monitoring and protection of these kernel assets +      from a higher exception level(EL) against any unauthorized changes.

Quoted 6 lines
Quoted 2 lines

"if you are unsure ..."

We just thought keeping it generic might be a better idea, thus, moved the changes to generic files from arch-specific files and thus, kept config also independent of the arch. Can surely make this config arch dependent if that is a better approach?

It's kind of silly to enable this if the hardware doesn't support it, isn't it?

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines

+
 endmenu

security/selinux/hooks.c +0 -0
index 6b1826f..7add17c 100644
@@ -104,7 +104,11 @@
  #include "audit.h"
  #include "avc_ss.h"
 
Quoted 9 lines

security/selinux/hooks.c line 111

Quoted 5 lines
security/selinux/hooks.c +4 -0
+#ifdef CONFIG_SECURITY_RTIC
+struct selinux_state selinux_state __rticdata;
+#else
  struct selinux_state selinux_state;
+#endif

Shouldn't the __rticdata tag be applied always, and its definition take care of the cases where it doesn't do anything?

Quoted 1 line

Will update this change in the next version of the patch. Thank you.

I saw that several other people had the same comment.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
security/selinux/hooks.c +0 -0
  /* SECMARK reference count */
  static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
#7 lore raw
Quoted 9 lines · Casey Schaufler
Quoted 5 lines
Quoted 2 lines

How would this interact with or complement __read_mostly?

Currently, the mechanism we are working on developing is independent of __read_mostly. This is something we can look more into while working further on the mechanism.

Please either integrate the two or explain how they differ. It appears that you haven't considered how you might exploit or expand the existing mechanism.

I think __read_mostly is about grouping stuff together that's rarely going to be read to make the CPU's data cache more efficient. It doesn't stop people writing to such a variable.

David

#8 lore raw
Quoted 12 lines · David Howells
Quoted 9 lines · Casey Schaufler
Quoted 5 lines
Quoted 2 lines

How would this interact with or complement __read_mostly?

Currently, the mechanism we are working on developing is independent of __read_mostly. This is something we can look more into while working further on the mechanism.

Please either integrate the two or explain how they differ. It appears that you haven't considered how you might exploit or expand the existing mechanism.

Quoted 5 lines

I think __read_mostly is about grouping stuff together that's rarely going to be read to make the CPU's data cache more efficient. It doesn't stop people writing to such a variable.

David

Thank you for sharing!

#9 lore raw
In reply to Preeti Nagar

Via:
https://lore.kernel.org/lkml/[email protected]/

include/linux/init.h void __init parse_early_options(char *cmdline); · line 304

Quoted 10 lines
include/linux/init.h +2 -0
index 7b53cb3..617adcf 100644
@@ -300,6 +300,10 @@ void __init parse_early_options(char *cmdline);
 /* Data marked not to be saved by software suspend */
 #define __nosavedata __section(".data..nosave")
 
+#ifdef CONFIG_SECURITY_RTIC
+#define __rticdata  __section(".bss.rtic")

if you put:

#else
#define __rticdata

here, then you wouldn't need to label each datum you put in there.

Quoted 9 lines
include/linux/init.h +2 -0
+#endif
+
 #ifdef MODULE
 #define __exit_p(x) x
 #else

security/selinux/hooks.c line 111

Quoted 8 lines
security/selinux/hooks.c +4 -0
@@ -104,7 +104,11 @@
 #include "audit.h"
 #include "avc_ss.h"
 
+#ifdef CONFIG_SECURITY_RTIC
+struct selinux_state selinux_state __rticdata;
+#else
 struct selinux_state selinux_state;
+#endif

so you could then drop the if-def here.

Happy to see this resolved when building with LLD+LTO, which has been a problem in the past.

Disabling selinux is a common attack vector on Android devices, so happy to see some effort towards mitigation. You might want to communicate the feature more to existing OEMs that are using your chipsets that support this feature.

#10 lore raw
Quoted 33 lines · Nick Desaulniers

Via:
https://lore.kernel.org/lkml/[email protected]/

include/linux/init.h void __init parse_early_options(char *cmdline); · line 304

Quoted 10 lines
include/linux/init.h +2 -0
index 7b53cb3..617adcf 100644
@@ -300,6 +300,10 @@ void __init parse_early_options(char *cmdline);
 /* Data marked not to be saved by software suspend */
 #define __nosavedata __section(".data..nosave")
 
+#ifdef CONFIG_SECURITY_RTIC
+#define __rticdata  __section(".bss.rtic")

if you put:

#else
#define __rticdata

here, then you wouldn't need to label each datum you put in there.

Quoted 12 lines
include/linux/init.h +2 -0
+#endif
+
 #ifdef MODULE
 #define __exit_p(x) x
 #else
security/selinux/hooks.c +0 -0
@@ -104,7 +104,11 @@
 #include "audit.h"
 #include "avc_ss.h"
 
Quoted 7 lines

security/selinux/hooks.c line 111

Quoted 5 lines
security/selinux/hooks.c +4 -0
+#ifdef CONFIG_SECURITY_RTIC
+struct selinux_state selinux_state __rticdata;
+#else
 struct selinux_state selinux_state;
+#endif

so you could then drop the if-def here.

Will update this in next version, thank you for the suggestion.

Quoted 2 lines

Happy to see this resolved when building with LLD+LTO, which has been a problem in the past.

Yes, downstream we have this verified with LTO configs enabled. Let us know if you are suggesting to check anything additionally here.

Quoted 4 lines

Disabling selinux is a common attack vector on Android devices, so happy to see some effort towards mitigation. You might want to communicate the feature more to existing OEMs that are using your chipsets that support this feature.

Glad to know the idea looks good! Yes, we will work on that, will communicate internally as well, thank you.