Skip to contentSkip to conversation

apparmor: fix missing error check for rhashtable_insert_fast

PATCH In review Danila Chernetsov 2 participants 2 messages Apr 4, 2023 – Apr 9, 2023

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

PATCH 1/1 apparmor: fix missing error check for rhashtable_insert_fast

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")
---
 security/apparmor/policy_unpack.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
security/apparmor/policy_unpack.c +7 -2
index cf2ceec40b28..4d8adb21732c 100644
@@ -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)) {
Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Danila Chernetsov

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

thanks, I have pulled this into the apparmor tree

Quoted 24 lines
---
  security/apparmor/policy_unpack.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
security/apparmor/policy_unpack.c +7 -2
index cf2ceec40b28..4d8adb21732c 100644
@@ -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)) {