linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] security/loadpin: Replace "kernel_read_file_str[j]" with function                   "kernel_read_file_id_str(j)".
@ 2021-03-04  8:36 zhaojiele
  2021-03-04 23:50 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: zhaojiele @ 2021-03-04  8:36 UTC (permalink / raw)
  To: keescook, jmorris, serge; +Cc: linux-security-module, linux-kernel, 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)".

Signed-off-by: zhaojiele <unclexiaole@gmail.com>
---
 security/loadpin/loadpin.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c
index b12f7d986b1e..3e8bdcd06600 100644
--- a/security/loadpin/loadpin.c
+++ b/security/loadpin/loadpin.c
@@ -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
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] security/loadpin: Replace "kernel_read_file_str[j]" with function                   "kernel_read_file_id_str(j)".
  2021-03-04  8:36 [PATCH] security/loadpin: Replace "kernel_read_file_str[j]" with function "kernel_read_file_id_str(j)" zhaojiele
@ 2021-03-04 23:50 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2021-03-04 23:50 UTC (permalink / raw)
  To: zhaojiele; +Cc: jmorris, serge, linux-security-module, linux-kernel

On Thu, Mar 04, 2021 at 08:36:38AM +0000, zhaojiele wrote:
> 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)".
> 
> Signed-off-by: zhaojiele <unclexiaole@gmail.com>
> ---
>  security/loadpin/loadpin.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c
> index b12f7d986b1e..3e8bdcd06600 100644
> --- a/security/loadpin/loadpin.c
> +++ b/security/loadpin/loadpin.c
> @@ -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));

>  
>  	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

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

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-04 23:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-04  8:36 [PATCH] security/loadpin: Replace "kernel_read_file_str[j]" with function "kernel_read_file_id_str(j)" zhaojiele
2021-03-04 23:50 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).