Skip to contentSkip to conversation

Correctly label files under /lib/firmware

PATCH New Guido Trentalancia 2 participants 6 messages Aug 8, 2016 – Aug 13, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 Correctly label files under /lib/firmware

Create the proper label for files under the /lib/firmware directory (firmware data files usually shipped with the kernel).

---
 policy/modules/kernel/files.fc |    2 ++
 1 file changed, 2 insertions(+)
policy/modules/kernel/files.fc +2 -0
@@ -107,6 +107,8 @@ HOME_ROOT/lost\+found/.*	<<none>>
 # /lib(64)?
 #
 /lib/modules(/.*)?		gen_context(system_u:object_r:modules_object_t,s0)
+/lib/firmware		-d	gen_context(system_u:object_r:lib_t,s0)
+/lib/firmware/.*		gen_context(system_u:object_r:lib_t,s0)
 
 ifdef(`distro_debian',`
 # on Debian /lib/init/rw is a tmpfs used like /var/run but
#1 lore raw

PATCH v2 2/2 Correctly label files under /lib/firmware

Create a new "firmware_t" file type, an interface to read such type of files and properly label the files under /lib/firmware (firmware data files usually shipped with the kernel) using such new label.

---
 policy/modules/kernel/files.fc |    2 ++
 policy/modules/kernel/files.if |   20 ++++++++++++++++++++
 policy/modules/kernel/files.te |    6 ++++++
 3 files changed, 28 insertions(+)
policy/modules/kernel/files.fc +2 -0
@@ -107,6 +107,8 @@ HOME_ROOT/lost\+found/.*	<<none>>
 # /lib(64)?
 #
 /lib/modules(/.*)?		gen_context(system_u:object_r:modules_object_t,s0)
+/lib/firmware		-d	gen_context(system_u:object_r:firmware_t,s0)
+/lib/firmware/.*		gen_context(system_u:object_r:firmware_t,s0)
 
 ifdef(`distro_debian',`
 # on Debian /lib/init/rw is a tmpfs used like /var/run but
policy/modules/kernel/files.if +20 -0
@@ -4158,6 +4158,26 @@ interface(`files_kernel_modules_filetran
 
 ########################################
 ## <summary>
+##      Read firmware files.
+## </summary>
+## <param name="domain">
+##      <summary>
+##      Domain allowed access.
+##      </summary>
+## </param>
+#
+interface(`files_read_firmware_files',`
+	gen_require(`
+		type firmware_t;
+	')
+
+	allow $1 firmware_t:dir list_dir_perms;
+	read_files_pattern($1, firmware_t, firmware_t)
+	read_lnk_files_pattern($1, firmware_t, firmware_t)
+')
+
+########################################
+## <summary>
 ##	List world-readable directories.
 ## </summary>
 ## <param name="domain">
policy/modules/kernel/files.te +6 -0
@@ -98,6 +98,12 @@ files_mountpoint(mnt_t)
 type modules_object_t;
 files_type(modules_object_t)
 
+#
+# firmware_t is the type for firmware files
+#
+type firmware_t;
+files_type(firmware_t)
+
 type no_access_t;
 files_type(no_access_t)
 
#2 lore raw

PATCH v3 2/2 Correctly label files under /lib/firmware

Create a new "firmware_t" file type, an interface to read such type of files, an interface to search directories containing such type of files and finally make sure that files under /lib/firmware (firmware data files usually shipped with the kernel) are properly labeled using the new label.

---
 policy/modules/kernel/files.fc |    2 ++
 policy/modules/kernel/files.if |   38 ++++++++++++++++++++++++++++++++++++++
 policy/modules/kernel/files.te |    6 ++++++
 3 files changed, 46 insertions(+)
policy/modules/kernel/files.fc +2 -0
@@ -107,6 +107,8 @@ HOME_ROOT/lost\+found/.*	<<none>>
 # /lib(64)?
 #
 /lib/modules(/.*)?		gen_context(system_u:object_r:modules_object_t,s0)
+/lib/firmware		-d	gen_context(system_u:object_r:firmware_t,s0)
+/lib/firmware/.*		gen_context(system_u:object_r:firmware_t,s0)
 
 ifdef(`distro_debian',`
 # on Debian /lib/init/rw is a tmpfs used like /var/run but
policy/modules/kernel/files.if +38 -0
@@ -3992,6 +3992,24 @@ interface(`files_search_kernel_modules',
 
 ########################################
 ## <summary>
+##      Search the contents of /lib/firmware directories.
+## </summary>
+## <param name="domain">
+##      <summary>
+##      Domain allowed access.
+##      </summary>
+## </param>
+#
+interface(`files_search_firmware',`
+	gen_require(`
+		type firmware_t;
+	')
+
+	allow $1 firmware_t:dir search_dir_perms;
+')
+
+########################################
+## <summary>
 ##	List the contents of the kernel module directories.
 ## </summary>
 ## <param name="domain">
@@ -4157,6 +4175,26 @@ interface(`files_kernel_modules_filetran
 ')
 
 ########################################
+## <summary>
+##      Read firmware files.
+## </summary>
+## <param name="domain">
+##      <summary>
+##      Domain allowed access.
+##      </summary>
+## </param>
+#
+interface(`files_read_firmware_files',`
+	gen_require(`
+		type firmware_t;
+	')
+
+	allow $1 firmware_t:dir list_dir_perms;
+	read_files_pattern($1, firmware_t, firmware_t)
+	read_lnk_files_pattern($1, firmware_t, firmware_t)
+')
+
+########################################
 ## <summary>
 ##	List world-readable directories.
 ## </summary>
policy/modules/kernel/files.te +6 -0
@@ -98,6 +98,12 @@ files_mountpoint(mnt_t)
 type modules_object_t;
 files_type(modules_object_t)
 
+#
+# firmware_t is the type for firmware files
+#
+type firmware_t;
+files_type(firmware_t)
+
 type no_access_t;
 files_type(no_access_t)
 
#3 lore raw

PATCH v3 2/2 Correctly label files under /lib/firmware

Quoted 4 lines · Guido Trentalancia

Create a new "firmware_t" file type, an interface to read such type of files, an interface to search directories containing such type of files and finally make sure that files under /lib/firmware (firmware data files usually shipped with the kernel) are properly labeled using the new label.

I'm not clear why a new type is needed. The code should generally be read-only, not executable, and is otherwise non-sensitive. It seems like usr_t would be more appropriate to label the firmware files, than the current lib_t.

Quoted 92 lines
---
 policy/modules/kernel/files.fc |    2 ++
 policy/modules/kernel/files.if |   38 ++++++++++++++++++++++++++++++++++++++
 policy/modules/kernel/files.te |    6 ++++++
 3 files changed, 46 insertions(+)
policy/modules/kernel/files.fc +2 -0
@@ -107,6 +107,8 @@ HOME_ROOT/lost\+found/.*	<<none>>
 # /lib(64)?
 #
 /lib/modules(/.*)?		gen_context(system_u:object_r:modules_object_t,s0)
+/lib/firmware		-d	gen_context(system_u:object_r:firmware_t,s0)
+/lib/firmware/.*		gen_context(system_u:object_r:firmware_t,s0)
 
 ifdef(`distro_debian',`
 # on Debian /lib/init/rw is a tmpfs used like /var/run but
policy/modules/kernel/files.if +38 -0
@@ -3992,6 +3992,24 @@ interface(`files_search_kernel_modules',
 
 ########################################
 ## <summary>
+##      Search the contents of /lib/firmware directories.
+## </summary>
+## <param name="domain">
+##      <summary>
+##      Domain allowed access.
+##      </summary>
+## </param>
+#
+interface(`files_search_firmware',`
+	gen_require(`
+		type firmware_t;
+	')
+
+	allow $1 firmware_t:dir search_dir_perms;
+')
+
+########################################
+## <summary>
 ##	List the contents of the kernel module directories.
 ## </summary>
 ## <param name="domain">
@@ -4157,6 +4175,26 @@ interface(`files_kernel_modules_filetran
 ')
 
 ########################################
+## <summary>
+##      Read firmware files.
+## </summary>
+## <param name="domain">
+##      <summary>
+##      Domain allowed access.
+##      </summary>
+## </param>
+#
+interface(`files_read_firmware_files',`
+	gen_require(`
+		type firmware_t;
+	')
+
+	allow $1 firmware_t:dir list_dir_perms;
+	read_files_pattern($1, firmware_t, firmware_t)
+	read_lnk_files_pattern($1, firmware_t, firmware_t)
+')
+
+########################################
 ## <summary>
 ##	List world-readable directories.
 ## </summary>
policy/modules/kernel/files.te +6 -0
@@ -98,6 +98,12 @@ files_mountpoint(mnt_t)
 type modules_object_t;
 files_type(modules_object_t)
 
+#
+# firmware_t is the type for firmware files
+#
+type firmware_t;
+files_type(firmware_t)
+
 type no_access_t;
 files_type(no_access_t)
 

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

Signature · 1 line
Chris PeBenito
#4 lore raw

PATCH v3 2/2 Correctly label files under /lib/firmware

Hello Chris.

Quoted 9 lines · Chris PeBenito
Quoted 7 lines · Guido Trentalancia

Create a new "firmware_t" file type, an interface to read such type of files,
an interface to search directories containing such type of files and finally
make sure that files under /lib/firmware (firmware data files usually shipped
with the kernel) are properly labeled using the new label.

Quoted 6 lines

I'm not clear why a new type is needed.??The code should generally be?
read-only, not executable, and is otherwise non-sensitive.??It seems? like usr_t would be more appropriate to label the firmware files, than?
the current lib_t.

I have created a new version of the patch, where a specific firmware type is created so that permissions can be granted to read the corresponding file context only, instead of generic lib_t read permissions.

Quoted 88 lines
Quoted 88 lines

---
?policy/modules/kernel/files.fc |????2 ++
?policy/modules/kernel/files.if |???38
++++++++++++++++++++++++++++++++++++++
?policy/modules/kernel/files.te |????6 ++++++
?3 files changed, 46 insertions(+)

--- refpolicy-git-06082016-orig/policy/modules/kernel/files.fc

2016-08-06 21:26:43.283774146 +0200

+++ refpolicy-git-06082016/policy/modules/kernel/files.fc 20
16-08-08 18:04:04.403079629 +0200

(quoted diff) +0 -0
@@ -107,6 +107,8 @@ HOME_ROOT/lost\+found/.*	<<none>>

?# /lib(64)?
?#
?/lib/modules(/.*)? gen_context(system_u:object_r:mo
dules_object_t,s0)
+/lib/firmware -d gen_context(system_u:object
_r:firmware_t,s0)
+/lib/firmware/.* gen_context(system_u:object_r:firm
ware_t,s0)

?ifdef(distro_debian',
?# on Debian /lib/init/rw is a tmpfs used like /var/run but --- refpolicy-git-06082016-orig/policy/modules/kernel/files.if

2016-08-06 21:26:43.284774157 +0200

+++ refpolicy-git-06082016/policy/modules/kernel/files.if 20
16-08-08 18:42:32.255597221 +0200

(quoted diff) +0 -0
@@ -3992,6 +3992,24 @@ interface(`files_search_kernel_modules',
 

?########################################
?## <summary>

policy/modules/kernel/files.if +18 -0
+##??????Search the contents of /lib/firmware directories.
+## </summary>
+## <param name="domain">
+##??????<summary>
+##??????Domain allowed access.
+##??????</summary>
+## </param>
+#
+interface(`files_search_firmware',`
+	gen_require(`
+		type firmware_t;
+	')
+
+	allow $1 firmware_t:dir search_dir_perms;
+')
+
+########################################
+## <summary>

?## List the contents of the kernel module directories.
?## </summary>
?## <param name="domain">

(quoted diff) +0 -0
@@ -4157,6 +4175,26 @@ interface(`files_kernel_modules_filetran
 ?')
 

?########################################

policy/modules/kernel/files.if +20 -0
+## <summary>
+##??????Read firmware files.
+## </summary>
+## <param name="domain">
+##??????<summary>
+##??????Domain allowed access.
+##??????</summary>
+## </param>
+#
+interface(`files_read_firmware_files',`
+	gen_require(`
+		type firmware_t;
+	')
+
+	allow $1 firmware_t:dir list_dir_perms;
+	read_files_pattern($1, firmware_t, firmware_t)
+	read_lnk_files_pattern($1, firmware_t, firmware_t)
+')
+
+########################################

?## <summary>
?## List world-readable directories.
?## </summary>
--- refpolicy-git-06082016-orig/policy/modules/kernel/files.te

2016-08-06 21:26:43.284774157 +0200

+++ refpolicy-git-06082016/policy/modules/kernel/files.te 20
16-08-08 18:15:48.314379707 +0200

(quoted diff) +0 -0
@@ -98,6 +98,12 @@ files_mountpoint(mnt_t)
 ?type modules_object_t;
 ?files_type(modules_object_t)
 
Quoted 8 lines

policy/modules/kernel/files.te files_mountpoint(mnt_t)

Quoted 8 lines
policy/modules/kernel/files.te +6 -0
+#
+# firmware_t is the type for firmware files
+#
+type firmware_t;
+files_type(firmware_t)
+
 ?type no_access_t;
 ?files_type(no_access_t)

Regards,

Guido

#5 lore raw

PATCH v3 2/2 Correctly label files under /lib/firmware

Quoted 19 lines · Guido Trentalancia

Hello Chris.

Quoted 9 lines · Chris PeBenito
Quoted 7 lines · Guido Trentalancia

Create a new "firmware_t" file type, an interface to read such type of files,
an interface to search directories containing such type of files and finally
make sure that files under /lib/firmware (firmware data files usually shipped
with the kernel) are properly labeled using the new label.

Quoted 6 lines

I'm not clear why a new type is needed. The code should generally be
read-only, not executable, and is otherwise non-sensitive. It seems like usr_t would be more appropriate to label the firmware files, than
the current lib_t.

Quoted 4 lines

I have created a new version of the patch, where a specific firmware type is created so that permissions can be granted to read the corresponding file context only, instead of generic lib_t read permissions.

I don't understand why the reading would need to be restricted. The files aren't sensitive.

Signature · 1 line
Chris PeBenito