Skip to contentSkip to conversation

security/loadpin: Replace "kernel_read_file_str[j]" with function "kernel_read_file_id_str(j)".

PATCH Superseded zhaojiele 2 participants 2 messages Mar 4, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

zhaojiele

author
#0 lore raw

PATCH 1/1 security/loadpin: Replace "kernel_read_file_str[j]" with function "kernel_read_file_id_str(j)".

Actually Linux kernel already provide function "kernel_read_file_id_str()" for secure access in "kernel_read_file.h".And, in "parse_exclude()" function, there is no need for "BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) < ARRAY_SIZE(ignore_read_file_id))"
when access array by functon "kernel_read_file_id_str(j)".

---
 security/loadpin/loadpin.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
security/loadpin/loadpin.c +2 -4
index b12f7d986b1e..3e8bdcd06600 100644
@@ -210,8 +210,6 @@ static void __init parse_exclude(void)
 	 */
 	BUILD_BUG_ON(ARRAY_SIZE(exclude_read_files) !=
 		     ARRAY_SIZE(ignore_read_file_id));
-	BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) <
-		     ARRAY_SIZE(ignore_read_file_id));
 
 	for (i = 0; i < ARRAY_SIZE(exclude_read_files); i++) {
 		cur = exclude_read_files[i];
@@ -221,9 +219,9 @@ static void __init parse_exclude(void)
 			continue;
 
 		for (j = 0; j < ARRAY_SIZE(ignore_read_file_id); j++) {
-			if (strcmp(cur, kernel_read_file_str[j]) == 0) {
+			if (strcmp(cur, kernel_read_file_id_str(j)) == 0) {
 				pr_info("excluding: %s\n",
-					kernel_read_file_str[j]);
+					kernel_read_file_id_str(j));
 				ignore_read_file_id[j] = 1;
 				/*
 				 * Can not break, because one read_file_str
Signature · 1 line
2.25.1
#1 lore raw
Quoted 17 lines · zhaojiele

Actually Linux kernel already provide function "kernel_read_file_id_str()" for secure access in "kernel_read_file.h".And, in "parse_exclude()" function, there is no need for "BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) < ARRAY_SIZE(ignore_read_file_id))"
when access array by functon "kernel_read_file_id_str(j)".

---
 security/loadpin/loadpin.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
security/loadpin/loadpin.c +0 -0
index b12f7d986b1e..3e8bdcd06600 100644

security/loadpin/loadpin.c static void __init parse_exclude(void) · line 214

Quoted 5 lines
security/loadpin/loadpin.c +0 -2
@@ -210,8 +210,6 @@ static void __init parse_exclude(void)
 	 */
 	BUILD_BUG_ON(ARRAY_SIZE(exclude_read_files) !=
 		     ARRAY_SIZE(ignore_read_file_id));
-	BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) <
-		     ARRAY_SIZE(ignore_read_file_id));

This should stay to make sure kernel_read_file_str doesn't diverge from the other two. However, maybe it should be tightened to:

	BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) - 1 ==
		     ARRAY_SIZE(ignore_read_file_id));
Quoted 5 lines
security/loadpin/loadpin.c +0 -0
 	for (i = 0; i < ARRAY_SIZE(exclude_read_files); i++) {
 		cur = exclude_read_files[i];
@@ -221,9 +219,9 @@ static void __init parse_exclude(void)
 			continue;

security/loadpin/loadpin.c static void __init parse_exclude(void) · line 227

Quoted 10 lines
security/loadpin/loadpin.c +2 -2
 
 		for (j = 0; j < ARRAY_SIZE(ignore_read_file_id); j++) {
-			if (strcmp(cur, kernel_read_file_str[j]) == 0) {
+			if (strcmp(cur, kernel_read_file_id_str(j)) == 0) {
 				pr_info("excluding: %s\n",
-					kernel_read_file_str[j]);
+					kernel_read_file_id_str(j));
 				ignore_read_file_id[j] = 1;
 				/*
 				 * Can not break, because one read_file_str

I feel funny about making these into function calls when we've already validated the index, but yeah, that would be fine. Can you send a v2 with the earlier suggestion addressed?

Thanks!

-Kees

Signature · 1 line
Kees Cook