linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] apparmor: fix missing error check for rhashtable_insert_fast
@ 2023-04-04 19:05 Danila Chernetsov
  2023-04-09 23:29 ` John Johansen
  0 siblings, 1 reply; 2+ messages in thread
From: Danila Chernetsov @ 2023-04-04 19:05 UTC (permalink / raw)
  To: John Johansen
  Cc: Danila Chernetsov, Paul Moore, James Morris, Serge E. Hallyn,
	linux-security-module, linux-kernel, lvc-project

 rhashtable_insert_fast() could return err value when memory allocation is
 failed. but unpack_profile() do not check values and this always returns
 success value. This patch just adds error check code.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: e025be0f26d5 ("apparmor: support querying extended trusted helper extra data")

Signed-off-by: Danila Chernetsov <listdansp@mail.ru>
---
 security/apparmor/policy_unpack.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
index cf2ceec40b28..4d8adb21732c 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -1046,8 +1046,13 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
 				goto fail;
 			}
 
-			rhashtable_insert_fast(profile->data, &data->head,
-					       profile->data->p);
+			if(rhashtable_insert_fast(profile->data, &data->head,
+						profile->data->p)) {
+				kfree_sensitive(data->key);
+				kfree_sensitive(data);
+				info = "failed to insert data to table"; 
+				goto fail;
+			}
 		}
 
 		if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) {
-- 
2.25.1


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

* Re: [PATCH] apparmor: fix missing error check for rhashtable_insert_fast
  2023-04-04 19:05 [PATCH] apparmor: fix missing error check for rhashtable_insert_fast Danila Chernetsov
@ 2023-04-09 23:29 ` John Johansen
  0 siblings, 0 replies; 2+ messages in thread
From: John Johansen @ 2023-04-09 23:29 UTC (permalink / raw)
  To: Danila Chernetsov
  Cc: Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
	linux-kernel, lvc-project

On 4/4/23 12:05, Danila Chernetsov wrote:
>   rhashtable_insert_fast() could return err value when memory allocation is
>   failed. but unpack_profile() do not check values and this always returns
>   success value. This patch just adds error check code.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: e025be0f26d5 ("apparmor: support querying extended trusted helper extra data")
> 
> Signed-off-by: Danila Chernetsov <listdansp@mail.ru>

Acked-by: John Johansen <john.johansen@canonical.com>

thanks, I have pulled this into the apparmor tree


> ---
>   security/apparmor/policy_unpack.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
> index cf2ceec40b28..4d8adb21732c 100644
> --- a/security/apparmor/policy_unpack.c
> +++ b/security/apparmor/policy_unpack.c
> @@ -1046,8 +1046,13 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
>   				goto fail;
>   			}
>   
> -			rhashtable_insert_fast(profile->data, &data->head,
> -					       profile->data->p);
> +			if(rhashtable_insert_fast(profile->data, &data->head,
> +						profile->data->p)) {
> +				kfree_sensitive(data->key);
> +				kfree_sensitive(data);
> +				info = "failed to insert data to table";
> +				goto fail;
> +			}
>   		}
>   
>   		if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) {


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

end of thread, other threads:[~2023-04-09 23:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-04 19:05 [PATCH] apparmor: fix missing error check for rhashtable_insert_fast Danila Chernetsov
2023-04-09 23:29 ` John Johansen

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